Skip to content

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

Closed
@cushionbadak

Description

@cushionbadak

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: 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-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions