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 unsize_into #126982

Open
cushionbadak opened this issue Jun 26, 2024 · 3 comments
Labels
C-bug Category: This is a bug. F-coerce_unsized The `CoerceUnsized` trait 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

#![feature(coerce_unsized)]
use std::ops::CoerceUnsized;

struct Foo<T: ?Sized> {
    a: T,
}

impl<T, U> CoerceUnsized<U> for Foo<T> {}

union U {
    a: usize,
}

const C: U = Foo { a: 10 };

fn main() {}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (fda509e81 2024-06-25)
binary: rustc
commit-hash: fda509e817abeeecb5b76bc1de844f355675c81e
commit-date: 2024-06-25
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error[E0376]: the trait `CoerceUnsized` may only be implemented for a coercion between structures
 --> cast442.rs:8:1
  |
8 | impl<T, U> CoerceUnsized<U> for Foo<T> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/cast.rs:442:17:
assertion `left == right` failed
  left: Foo
 right: U
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<&rustc_middle::ty::adt::AdtDef, &rustc_middle::ty::adt::AdtDef>
   4: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::unsize_into
   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#5}>
  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/placeholder_rustexec/0625/rustc-ice-2024-06-26T06_34_30-28249.txt` to your bug report

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `C`
#1 [eval_to_const_value_raw] simplifying constant for the type system `C`
#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 E0376`.

Note

  • ICE location: compiler/rustc_const_eval/src/interpret/cast.rs#L442
    pub fn unsize_into(
    &mut self,
    src: &OpTy<'tcx, M::Provenance>,
    cast_ty: TyAndLayout<'tcx>,
    dest: &PlaceTy<'tcx, M::Provenance>,
    ) -> InterpResult<'tcx> {
    trace!("Unsizing {:?} of type {} into {}", *src, src.layout.ty, cast_ty.ty);
    match (&src.layout.ty.kind(), &cast_ty.ty.kind()) {
    (&ty::Ref(_, s, _), &ty::Ref(_, c, _) | &ty::RawPtr(c, _))
    | (&ty::RawPtr(s, _), &ty::RawPtr(c, _)) => self.unsize_into_ptr(src, dest, *s, *c),
    (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
    assert_eq!(def_a, def_b); // implies same number of fields
  • ICE: unsize_into: invalid conversion in rustc_const_eval/src/interpret/cast.rs #126269 might be related

@rustbot label +F-coerce_unsized

@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 26, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-coerce_unsized The `CoerceUnsized` trait labels Jun 26, 2024
@lqd
Copy link
Member

lqd commented Jun 26, 2024

This bisects to #121087 so I'll cc @oli-obk, but that PR surfaced a bunch of pre-existing stable ICEs. It seems possible to be the case here as well, though the usual simple transforms to surface the stable ICEs didn't seem to be applicable here, so maybe not.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 26, 2024

Yea, this needed that PR on top of my "don't hide errors from later phases" PRs. But even without #121087 it would then have been reproducible with

use std::ops::CoerceUnsized;

struct Foo<T: ?Sized> {
    a: T,
}

impl<T, U> CoerceUnsized<U> for Foo<T> {}

union U {
    a: usize,
}

const C: U = Foo { a: 10 };

const _: [(); {
    C;
    0
}] = [];

fn main() {}

@lqd
Copy link
Member

lqd commented Jun 26, 2024

That's what I expected but it didn't happen, the rewritten example doesn't ICE on 1.77 for example, but maybe it would only with the other PR that makes compilation go further (if I understood you correctly).

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 5, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jul 5, 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-coerce_unsized The `CoerceUnsized` trait 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

No branches or pull requests

6 participants