Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: expected bits of u8, got Ty(10_u32,) #123092

Closed
cushionbadak opened this issue Mar 26, 2024 · 3 comments · Fixed by #123130
Closed

ICE: expected bits of u8, got Ty(10_u32,) #123092

cushionbadak opened this issue Mar 26, 2024 · 3 comments · Fixed by #123130
Assignees
Labels
A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Code

(reduced)

trait Range {
    const FIRST: u8;
    const LAST: u8;
}

struct TwoDigits;
impl Range for TwoDigits {
    const FIRST:  = 10;
    const LAST: u8 = 99;
}

fn digits(x: u8) -> u32 {
    match x {
        TwoDigits::FIRST..=TwoDigits::LAST => 2,
    }
}

fn main() {}

Note: type notation at const FIRST: in TwoDigits is omitted. I guess that causes ICE

Original Code

//@ run-pass

#![allow(dead_code)]

trait Range {
    const FIRST: u8;
    const LAST: u8;
}

struct OneDigit;
impl Range for OneDigit {
    const FIRST: u8 = 0;
    const LAST: u8 = 9;
}

struct TwoDigits;
impl Range for TwoDigits {
    const FIRST:  = 10;
    const LAST: u8 = 99;
}

struct ThreeDigits;
impl Range for ThreeDigits {
    const FIRST: u8 = 100;
    const LAST: u8 = 255;
}

fn digits(x: u8) -> u32 {
    match x {
        OneDigit::FIRST..=OneDigit::LAST => 1,
        TwoDigits::FIRST..=TwoDigits::LAST => 2,
        ThreeDigits::FIRST..=ThreeDigits::LAST => 3,
    }
}

fn main() {
    assert_eq!(digits(100), 3);
}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (5f2c7d2bf 2024-03-25)
binary: rustc
commit-hash: 5f2c7d2bfd46cad00352ab7cd66242077e2e518c
commit-date: 2024-03-25
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2

Command

rustc, no other options

Error output

error: missing type for `const` item
 --> reduced_23439712.rs:8:17
  |
8 |     const FIRST:  = 10;
  |                 ^ help: provide a type for the associated constant: `i32`
Backtrace

error: internal compiler error: /rustc/5f2c7d2bfd46cad00352ab7cd66242077e2e518c/compiler/rustc_middle/src/mir/consts.rs:344:32: expected bits of u8, got Ty(
                                    10_u32,
                                )

thread 'rustc' panicked at /rustc/5f2c7d2bfd46cad00352ab7cd66242077e2e518c/compiler/rustc_middle/src/mir/consts.rs:344:32:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_pattern_analysis::rustc::RustcPatCtxt>::lower_pat_range_bdy
   7: <rustc_pattern_analysis::rustc::RustcPatCtxt>::lower_pat
   8: <rustc_mir_build::thir::pattern::check_match::MatchVisitor>::lower_pattern
   9: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  10: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  11: rustc_middle::thir::visit::walk_block::<rustc_mir_build::thir::pattern::check_match::MatchVisitor>
  12: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  13: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  14: rustc_mir_build::thir::pattern::check_match::check_match
      [... omitted 1 frame ...]
  15: rustc_mir_build::build::mir_build
  16: rustc_mir_transform::mir_built
      [... omitted 1 frame ...]
  17: rustc_mir_build::check_unsafety::check_unsafety
      [... omitted 1 frame ...]
  18: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::analysis::{closure#1}::{closure#0}>::{closure#0}
  19: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  20: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  21: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: it seems that this compiler `1.79.0-nightly (5f2c7d2bf 2024-03-25)` is outdated, a newer nightly should have been released in the mean time
  |
  = note: please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
  = note: if the problem still persists, we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please attach the file at `/Volumes/T7/workspace/placeholder_rustexec/rustc-ice-2024-03-26T12_13_20-28368.txt` to your bug report

query stack during panic:
#0 [check_match] match-checking `digits`
#1 [mir_built] building MIR for `digits`
#2 [check_unsafety] unsafety-checking `digits`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Related Issues

@cushionbadak cushionbadak added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 26, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 26, 2024
@oli-obk oli-obk self-assigned this Mar 26, 2024
@jieyouxu jieyouxu added A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 26, 2024
@GrigorenkoPV
Copy link
Contributor

Regression in #120550, but I guess it is already known.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 27, 2024

#120550 only exposed it more easily, the ICE can also be triggered on stable by invoking the function in an array length:

trait Range {
    const FIRST: u8;
    const LAST: u8;
}

struct TwoDigits;
impl Range for TwoDigits {
    const FIRST:  = 10;
    const LAST: u8 = 99;
}

const fn digits(x: u8) -> usize {
    match x {
        TwoDigits::FIRST..=TwoDigits::LAST => 0,
    }
}

const FOOMP: [(); {
    digits(42)
}] = [];

@oli-obk
Copy link
Contributor

oli-obk commented Mar 27, 2024

trait Range {
    const FIRST: u8;
    const LAST: u8;
}

struct TwoDigits;
impl Range for TwoDigits {
    const FIRST:  = 10;
    const LAST: u8 = 99;
}

const FOOMP: [(); {
    TwoDigits::FIRST as usize
}] = [];

has been ICEing with different messages since 1.23 (edit: but isn't ICEing anymore, edit: scalar size mismatch should be an ICE, not an error, huh?)

Further bisection can be done, but is probably not useful. I'll just fix the bug 😆

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 27, 2024
…iler-errors

Load missing type of impl associated constant from trait definition

fixes rust-lang#123092

Also does some cleanups I discovered while analyzing this issue
@bors bors closed this as completed in 15fb2f2 Mar 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 28, 2024
Rollup merge of rust-lang#123130 - oli-obk:missing_type_taint, r=compiler-errors

Load missing type of impl associated constant from trait definition

fixes rust-lang#123092

Also does some cleanups I discovered while analyzing this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants