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: assertion left == right failed in rustc_const_eval/src/interpret/cast.rs #126666

Closed
cushionbadak opened this issue Jun 19, 2024 · 1 comment · Fixed by #127311
Closed

ICE: assertion left == right failed in rustc_const_eval/src/interpret/cast.rs #126666

cushionbadak opened this issue Jun 19, 2024 · 1 comment · Fixed by #127311
Labels
C-bug Category: This is a bug. F-const_mut_refs `#![feature(const_mut_refs)]` F-const_refs_to_static `#![feature(const_refs_to_static)]` F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_dispatch` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Code

(hand-reduced & simplified)

#![feature(const_mut_refs)]
#![feature(const_refs_to_static)]
#![feature(object_safe_for_dispatch)]

struct Meh {
    x: &'static dyn UnsafeCell,
}

const MUH: Meh = Meh {
    x: &mut *(&READONLY as *const _ as *mut _),
};

static READONLY: i32 = 0;

trait UnsafeCell<'a> {}

pub fn main() {}
  • crate attribute object_safe_for_dispatch added from original code.
(original)

#![feature(const_mut_refs)]
#![feature(const_refs_to_static)]

use std::cell::UnsafeCell;

struct Meh {
    x: &'static UnsafeCell<i32>,
}

const MUH: Meh = Meh {
    x: &mut *(&READONLY as *const _ as *mut _),
};

static READONLY: i32 = 0;

pub fn main() {}


#![feature(type_alias_impl_trait)]

struct call_me;

type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
type FnType = impl Fn(&u32) -> ReturnType;

impl std::ops::Deref for call_me {
    type Target = FnType;
    
    fn deref(&self) -> &Self::Target {
        fn inner(val: &u32) -> ReturnType {
            async move {
                *val * 2
            }
        }
    
        &inner
    }
}


trait UnsafeCell<'a, 'b, T> {
    async fn foo(&'a self) -> (Self::Target, &'BAR T);
}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (8fcd4dd08 2024-06-18)
binary: rustc
commit-hash: 8fcd4dd08e2ba3e922d917d819ba0be066bdb005
commit-date: 2024-06-18
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

Command: rustc

error[E0106]: missing lifetime specifier
 --> r_cast214_DE5E554.rs:6:21
  |
6 |     x: &'static dyn UnsafeCell,
  |                     ^^^^^^^^^^ expected named lifetime parameter
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
6 |     x: &'static dyn for<'a> UnsafeCell<'a>,
  |                     +++++++           ++++
help: consider introducing a named lifetime parameter
  |
5 ~ struct Meh<'a> {
6 ~     x: &'static dyn UnsafeCell<'a>,
  |
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/cast.rs:214:13:
assertion `left == right` failed
  left: Size(8 bytes)
 right: Size(16 bytes)
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<rustc_abi::Size, rustc_abi::Size>
   4: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::cast
   5: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::statement
   6: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 2 frames ...]
   7: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, rustc_middle::query::erase::Erased<[u8; 24]>>>
   8: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
      [... omitted 2 frames ...]
   9: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#3}>::{closure#0}
  10: rustc_hir_analysis::check_crate
  11: rustc_interface::passes::run_required_analyses
  12: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  13: <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}>
  14: 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.

error: the compiler unexpectedly panicked. this is a bug.

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/240615_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-19T06_25_41-29848.txt` to your bug report

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `MUH`
#1 [eval_to_const_value_raw] simplifying constant for the type system `MUH`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0106`.

Note

  • ICE location: compiler/rustc_const_eval/src/interpret/cast.rs L214
    if cast_to.size == src.layout.size {
    // Thin or fat pointer that just has the ptr kind of target type changed.
    return Ok(ImmTy::from_immediate(**src, cast_to));
    } else {
    // Casting the metadata away from a fat ptr.
    assert_eq!(src.layout.size, 2 * self.pointer_size());
    assert_eq!(cast_to.size, self.pointer_size());
    assert!(src.layout.ty.is_unsafe_ptr());
    return match **src {
    Immediate::ScalarPair(data, _) => Ok(ImmTy::from_scalar(data, cast_to)),

@rustbot label +F-const_mut_refs +F-const_refs_to_static +F-object_safe_for_dispatch

@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 Jun 19, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-const_mut_refs `#![feature(const_mut_refs)]` F-const_refs_to_static `#![feature(const_refs_to_static)]` F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_dispatch` labels Jun 19, 2024
@GrigorenkoPV
Copy link
Contributor

searched nightlies: from nightly-2022-02-19 to nightly-2024-06-19
regressed nightly: nightly-2024-03-22
searched commit range: 1388d7a...0ad927c
regressed commit: 6a6cd65 (#122803, which is a rollup)

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 23, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 4, 2024
Avoid follow-up errors and ICEs after missing lifetime errors on data structures

Tuple struct constructors are functions, so when we call them typeck will use the signature tuple struct constructor function to provide type hints. Since typeck mostly ignores and erases lifetimes, we end up never seeing the error lifetime in writeback, thus not tainting the typeck result.

Now, we eagerly taint typeck results by tainting from `resolve_vars_if_possible`, which is called all over the place.

I did not carry over all the `crashes` test suite tests, as they are really all the same cause (missing or unknown lifetime names in tuple struct definitions or generic arg lists).

fixes rust-lang#124262
fixes rust-lang#124083
fixes rust-lang#125155
fixes rust-lang#125888
fixes rust-lang#125992
fixes rust-lang#126666
fixes rust-lang#126648
fixes rust-lang#127268
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 9, 2024
…ler-errors

Avoid follow-up errors and ICEs after missing lifetime errors on data structures

Tuple struct constructors are functions, so when we call them typeck will use the signature tuple struct constructor function to provide type hints. Since typeck mostly ignores and erases lifetimes, we end up never seeing the error lifetime in writeback, thus not tainting the typeck result.

Now, we eagerly taint typeck results by tainting from `resolve_vars_if_possible`, which is called all over the place.

I did not carry over all the `crashes` test suite tests, as they are really all the same cause (missing or unknown lifetime names in tuple struct definitions or generic arg lists).

fixes rust-lang#124262
fixes rust-lang#124083
fixes rust-lang#125155
fixes rust-lang#125888
fixes rust-lang#125992
fixes rust-lang#126666
fixes rust-lang#126648
fixes rust-lang#127268
@bors bors closed this as completed in c92a8e4 Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-const_mut_refs `#![feature(const_mut_refs)]` F-const_refs_to_static `#![feature(const_refs_to_static)]` F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_dispatch` 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. 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