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 isize, got Ty(3_isize,) #125799

Closed
cushionbadak opened this issue May 31, 2024 · 1 comment · Fixed by #126620
Closed

ICE: expected bits of isize, got Ty(3_isize,) #125799

cushionbadak opened this issue May 31, 2024 · 1 comment · Fixed by #126620
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Code

(hand-reduced)

trait Trait<T> {
    type Assoc;
}

impl<T> Trait<T> for Vec<T> {
    type Assoc = ();
}

impl Trait<u8> for Vec<u8> {}

const BAR: <Vec<u8> as Trait<u8>>::Assoc = 3;

pub fn main() {
    let x: isize = 3;
    let _ = match x {
        BAR => 2,
        _ => 3,
    };
}
(original)

use inner_private_module::*;

mod inner_private_module {
    pub struct Unnameable1;
    pub struct Unnameable2;
    #[derive(Clone, Copy)]
    pub struct Unnameable3;
    pub struct Unnameable4;
    pub struct Unnameable5;
    pub struct Unnameable6;
    pub struct Unnameable7;
    #[derive(Default)]
    pub struct Unnameable8;
    pub enum UnnameableEnum {
        NameableVariant
    }
    pub trait UnnameableTrait {
        type Alias: Default;
    }

    impl Unnameable1 {
        pub fn method_of_unnameable_type1(&self) -> &'static str {
            "Hello1"
        }
    }
    impl Unnameable2 {
        pub fn method_of_unnameable_type2(&self) -> &'static str {
            "Hello2"
        }
    }
    impl Unnameable3 {
        pub fn method_of_unnameable_type3(&self) -> &'static str {
            "Hello3"
        }
    }
    impl Unnameable4 {
        pub fn method_of_unnameable_type4(&self) -> &'static str {
            "Hello4"
        }
    }
    impl Unnameable5 {
        pub fn method_of_unnameable_type5(&self) -> &'static str {
            "Hello5"
        }
    }
    impl Unnameable6 {
        pub fn method_of_unnameable_type6(&self) -> &'static str {
            "Hello6"
        }
    }
    impl Unnameable7 {
        pub fn method_of_unnameable_type7(&self) -> &'static str {
            "Hello7"
        }
    }
    impl Unnameable8 {
        pub fn method_of_unnameable_type8(&self) -> &'static str {
            "Hello8"
        }
    }
    impl UnnameableEnum {
        pub fn method_of_unnameable_enum(&self) -> &'static str {
            "HelloEnum"
        }
    }
}

pub fn function_returning_unnameable_type() -> Unnameable1 {
    Unnameable1
}

pub const CONSTANT_OF_UNNAMEABLE_TYPE: Unnameable2 =
                                            Unnameable2;

pub fn function_accepting_unnameable_type(_: Option<Unnameable3>) {}

pub type AliasOfUnnameableType = Unnameable4;

impl Unnameable1 {
    pub fn inherent_method_returning_unnameable_type(&self) -> Unnameable5 {
        Unnameable5
    }
}

pub trait Tr {
    fn trait_method_returning_unnameable_type(&self) -> Unnameable6 {
        Unnameable6
    }
}
impl Tr for Unnameable1 {}

pub use inner_private_module::UnnameableEnum::NameableVariant;

pub struct Struct {
    pub field_of_unnameable_type: Unnameable7
}

pub static STATIC: Struct = Struct { field_of_unnameable_type: Unnameable7 } ;

impl UnnameableTrait for AliasOfUnnameableType {
    type Alias = Unnameable8;
}

pub fn generic_function<T: UnnameableTrait>() -> T::Alias {
    Default::default()
}


// Formerly this ICEd with the following message:
// Tried to project an inherited associated type during coherence checking,
// which is currently not supported.
//
// No we expect to run into a more user-friendly cycle error instead.
#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

trait Trait<T> { type Assoc; }
//~^ ERROR E0391

impl<T> Trait<T> for Vec<T> {
    type Assoc = ();
}

impl Trait<u8> for Vec<u8> {}

impl<T> Trait<T> for String {
    type Assoc = ();
}

impl Trait<<Vec<u8> as T::Alias<u8>>::Assoc> for String {}

fn main() {}


//@ run-pass

const FOO: isize = 10;
const BAR: <Vec<u8> as Trait<u8>>::Assoc = 3;
const ZST: &() = unsafe { std::mem::transmute(1usize) };
const ZST_ARR: &[u8; 0] = unsafe { std::mem::transmute(1usize) };

const fn foo() -> isize { 4 }
const BOO: isize = foo();

pub fn main() {
    let x: isize = 3;
    let y = match x {
        FOO => 1,
        BAR => 2,
        BOO => 4,
        _ => 3
    };
    assert_eq!(y, 2);
    let z = match &() {
        ZST => 9,
    };
    assert_eq!(z, 9);
    let z = match b"" {
        ZST_ARR => 10,
    };
    assert_eq!(z, 10);
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (6f3df08aa 2024-05-30)
binary: rustc
commit-hash: 6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4
commit-date: 2024-05-30
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Command: rustc

error[E0119]: conflicting implementations of trait `Trait<u8>` for type `Vec<u8>`
 --> r_consts_17666C.rs:9:1
  |
5 | impl<T> Trait<T> for Vec<T> {
  | --------------------------- first implementation here
...
9 | impl Trait<u8> for Vec<u8> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Vec<u8>`
Backtrace

error: internal compiler error: /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/compiler/rustc_middle/src/mir/consts.rs:374:32: expected bits of isize, got Ty(
                                    3_isize,
                                )

thread 'rustc' panicked at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/compiler/rustc_middle/src/mir/consts.rs:374: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_middle::mir::consts::Const>::eval_bits::{closure#0}
   7: <rustc_mir_build::build::Builder>::test_candidates_with_or
   8: <rustc_mir_build::build::Builder>::match_candidates::{closure#0}
   9: <rustc_mir_build::build::Builder>::match_candidates
  10: <rustc_mir_build::build::Builder>::lower_match_tree
  11: <rustc_mir_build::build::Builder>::expr_into_dest
  12: <rustc_mir_build::build::Builder>::as_temp_inner
  13: <rustc_mir_build::build::Builder>::expr_as_place
  14: <rustc_mir_build::build::Builder>::expr_as_place
  15: <rustc_mir_build::build::Builder>::lower_scrutinee
  16: <rustc_mir_build::build::Builder>::ast_block_stmts
  17: <rustc_mir_build::build::Builder>::expr_into_dest
  18: <rustc_mir_build::build::Builder>::expr_into_dest::{closure#0}
  19: <rustc_mir_build::build::Builder>::expr_into_dest
  20: rustc_mir_build::build::construct_fn
  21: rustc_mir_build::build::mir_build
  22: rustc_mir_transform::mir_built
      [... omitted 1 frame ...]
  23: rustc_mir_build::check_unsafety::check_unsafety
      [... omitted 1 frame ...]
  24: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  25: rustc_interface::passes::run_required_analyses
  26: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  27: <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}>
  28: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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 make sure that you have updated to the latest nightly

note: please attach the file at `/Volumes/T7/workspace/240530_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-05-31T07_39_02-97364.txt` to your bug report

query stack during panic:
#0 [mir_built] building MIR for `main`
#1 [check_unsafety] unsafety-checking `main`
#2 [analysis] running analysis passes on this crate
end of query stack
error[E0282]: type annotations needed
  --> r_consts_17666C.rs:11:12
   |
11 | const BAR: <Vec<u8> as Trait<u8>>::Assoc = 3;
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0119, E0282.
For more information about an error, try `rustc --explain E0119`.

Note

  • ICE location: rustc_middle/src/mir/consts.rs L374
    /// Panics if the value cannot be evaluated or doesn't contain a valid integer of the given type.
    #[inline]
    pub fn eval_bits(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> u128 {
    self.try_eval_bits(tcx, param_env)
    .unwrap_or_else(|| bug!("expected bits of {:#?}, got {:#?}", self.ty(), self))
    }
  • A solved ICE issue ICE: expected bits of u8, got Ty(10_u32,) #123092 has identical ICE location.
@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 May 31, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 31, 2024
@jieyouxu jieyouxu added A-const-eval Area: Constant evaluation (MIR interpretation) S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 9, 2024
@cushionbadak
Copy link
Author

searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30
regressed nightly: nightly-2024-02-15
searched commit range: a84bb95...ee9c7c9
regressed commit: ee9c7c9

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2023-01-01 --end=2024-05-30 --regress=ice --script=rustc --preserve -- 125799.rs

jieyouxu added a commit to jieyouxu/rust that referenced this issue Jun 19, 2024
Actually taint InferCtxt when a fulfillment error is emitted

And avoid checking the global error counter

fixes rust-lang#122044
fixes rust-lang#123255
fixes rust-lang#123276
fixes rust-lang#125799
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jun 19, 2024
Actually taint InferCtxt when a fulfillment error is emitted

And avoid checking the global error counter

fixes rust-lang#122044
fixes rust-lang#123255
fixes rust-lang#123276
fixes rust-lang#125799
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jun 19, 2024
Actually taint InferCtxt when a fulfillment error is emitted

And avoid checking the global error counter

fixes rust-lang#122044
fixes rust-lang#123255
fixes rust-lang#123276
fixes rust-lang#125799
@bors bors closed this as completed in e7be356 Jun 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 20, 2024
Rollup merge of rust-lang#126620 - oli-obk:taint_errors, r=fee1-dead

Actually taint InferCtxt when a fulfillment error is emitted

And avoid checking the global error counter

fixes rust-lang#122044
fixes rust-lang#123255
fixes rust-lang#123276
fixes rust-lang#125799
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants