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 Box to contain Unique #98372

Closed
matthiaskrgr opened this issue Jun 22, 2022 · 12 comments
Closed

ICE: expected Box to contain Unique #98372

matthiaskrgr opened this issue Jun 22, 2022 · 12 comments
Labels
F-rustc_attrs Internal rustc attributes gated on the `#[rustc_attrs]` feature gate. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jun 22, 2022

Code

./compiler/rustc_codegen_gcc/example/mini_core.rs
Don't have time to reduce right now, sorry

reduced: #98372 (comment)

#![feature(
    no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
    untagged_unions, decl_macro, rustc_attrs, transparent_unions, auto_traits,
    thread_local
)]
#![no_core]
#![allow(dead_code)]

#[no_mangle]
unsafe extern "C" fn _Unwind_Resume() {
    intrinsics::unreachable();
}

#[lang = "sized"]
pub trait Sized {}

#[lang = "destruct"]
pub trait Destruct {}

#[lang = "unsize"]
pub trait Unsize<T: ?Sized> {}

#[lang = "coerce_unsized"]
pub trait CoerceUnsized<T> {}

impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}

#[lang = "dispatch_from_dyn"]
pub trait DispatchFromDyn<T> {}

// &T -> &U
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
// &mut T -> &mut U
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
// *const T -> *const U
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}

#[lang = "receiver"]
pub trait Receiver {}

impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> Receiver for &mut T {}
impl<T: ?Sized> Receiver for Box<T> {}

#[lang = "copy"]
pub unsafe trait Copy {}

unsafe impl Copy for bool {}
unsafe impl Copy for u8 {}
unsafe impl Copy for u16 {}
unsafe impl Copy for u32 {}
unsafe impl Copy for u64 {}
unsafe impl Copy for usize {}
unsafe impl Copy for i8 {}
unsafe impl Copy for i16 {}
unsafe impl Copy for i32 {}
unsafe impl Copy for isize {}
unsafe impl Copy for f32 {}
unsafe impl Copy for f64 {}
unsafe impl Copy for char {}
unsafe impl<'a, T: ?Sized> Copy for &'a T {}
unsafe impl<T: ?Sized> Copy for *const T {}
unsafe impl<T: ?Sized> Copy for *mut T {}

#[lang = "sync"]
pub unsafe trait Sync {}

unsafe impl Sync for bool {}
unsafe impl Sync for u8 {}
unsafe impl Sync for u16 {}
unsafe impl Sync for u32 {}
unsafe impl Sync for u64 {}
unsafe impl Sync for usize {}
unsafe impl Sync for i8 {}
unsafe impl Sync for i16 {}
unsafe impl Sync for i32 {}
unsafe impl Sync for isize {}
unsafe impl Sync for char {}
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
unsafe impl Sync for [u8; 16] {}

#[lang = "freeze"]
unsafe auto trait Freeze {}

unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
unsafe impl<T: ?Sized> Freeze for *const T {}
unsafe impl<T: ?Sized> Freeze for *mut T {}
unsafe impl<T: ?Sized> Freeze for &T {}
unsafe impl<T: ?Sized> Freeze for &mut T {}

#[lang = "structural_peq"]
pub trait StructuralPartialEq {}

#[lang = "structural_teq"]
pub trait StructuralEq {}

#[lang = "not"]
pub trait Not {
    type Output;

    fn not(self) -> Self::Output;
}

impl Not for bool {
    type Output = bool;

    fn not(self) -> bool {
        !self
    }
}

#[lang = "mul"]
pub trait Mul<RHS = Self> {
    type Output;

    #[must_use]
    fn mul(self, rhs: RHS) -> Self::Output;
}

impl Mul for u8 {
    type Output = Self;

    fn mul(self, rhs: Self) -> Self::Output {
        self * rhs
    }
}

impl Mul for usize {
    type Output = Self;

    fn mul(self, rhs: Self) -> Self::Output {
        self * rhs
    }
}

#[lang = "add"]
pub trait Add<RHS = Self> {
    type Output;

    fn add(self, rhs: RHS) -> Self::Output;
}

impl Add for u8 {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        self + rhs
    }
}

impl Add for i8 {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        self + rhs
    }
}

impl Add for usize {
    type Output = Self;

    fn add(self, rhs: Self) -> Self {
        self + rhs
    }
}

#[lang = "sub"]
pub trait Sub<RHS = Self> {
    type Output;

    fn sub(self, rhs: RHS) -> Self::Output;
}

impl Sub for usize {
    type Output = Self;

    fn sub(self, rhs: Self) -> Self {
        self - rhs
    }
}

impl Sub for u8 {
    type Output = Self;

    fn sub(self, rhs: Self) -> Self {
        self - rhs
    }
}

impl Sub for i8 {
    type Output = Self;

    fn sub(self, rhs: Self) -> Self {
        self - rhs
    }
}

impl Sub for i16 {
    type Output = Self;

    fn sub(self, rhs: Self) -> Self {
        self - rhs
    }
}

#[lang = "rem"]
pub trait Rem<RHS = Self> {
    type Output;

    fn rem(self, rhs: RHS) -> Self::Output;
}

impl Rem for usize {
    type Output = Self;

    fn rem(self, rhs: Self) -> Self {
        self % rhs
    }
}

#[lang = "bitor"]
pub trait BitOr<RHS = Self> {
    type Output;

    #[must_use]
    fn bitor(self, rhs: RHS) -> Self::Output;
}

impl BitOr for bool {
    type Output = bool;

    fn bitor(self, rhs: bool) -> bool {
        self | rhs
    }
}

impl<'a> BitOr<bool> for &'a bool {
    type Output = bool;

    fn bitor(self, rhs: bool) -> bool {
        *self | rhs
    }
}

#[lang = "eq"]
pub trait PartialEq<Rhs: ?Sized = Self> {
    fn eq(&self, other: &Rhs) -> bool;
    fn ne(&self, other: &Rhs) -> bool;
}

impl PartialEq for u8 {
    fn eq(&self, other: &u8) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &u8) -> bool {
        (*self) != (*other)
    }
}

impl PartialEq for u16 {
    fn eq(&self, other: &u16) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &u16) -> bool {
        (*self) != (*other)
    }
}

impl PartialEq for u32 {
    fn eq(&self, other: &u32) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &u32) -> bool {
        (*self) != (*other)
    }
}


impl PartialEq for u64 {
    fn eq(&self, other: &u64) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &u64) -> bool {
        (*self) != (*other)
    }
}

impl PartialEq for usize {
    fn eq(&self, other: &usize) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &usize) -> bool {
        (*self) != (*other)
    }
}

impl PartialEq for i8 {
    fn eq(&self, other: &i8) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &i8) -> bool {
        (*self) != (*other)
    }
}

impl PartialEq for i32 {
    fn eq(&self, other: &i32) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &i32) -> bool {
        (*self) != (*other)
    }
}

impl PartialEq for isize {
    fn eq(&self, other: &isize) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &isize) -> bool {
        (*self) != (*other)
    }
}

impl PartialEq for char {
    fn eq(&self, other: &char) -> bool {
        (*self) == (*other)
    }
    fn ne(&self, other: &char) -> bool {
        (*self) != (*other)
    }
}

impl<T: ?Sized> PartialEq for *const T {
    fn eq(&self, other: &*const T) -> bool {
        *self == *other
    }
    fn ne(&self, other: &*const T) -> bool {
        *self != *other
    }
}

#[lang = "neg"]
pub trait Neg {
    type Output;

    fn neg(self) -> Self::Output;
}

impl Neg for i8 {
    type Output = i8;

    fn neg(self) -> i8 {
        -self
    }
}

impl Neg for i16 {
    type Output = i16;

    fn neg(self) -> i16 {
        self
    }
}

impl Neg for isize {
    type Output = isize;

    fn neg(self) -> isize {
        -self
    }
}

impl Neg for f32 {
    type Output = f32;

    fn neg(self) -> f32 {
        -self
    }
}

pub enum Option<T> {
    Some(T),
    None,
}

pub use Option::*;

#[lang = "phantom_data"]
pub struct PhantomData<T: ?Sized>;

#[lang = "fn_once"]
#[rustc_paren_sugar]
pub trait FnOnce<Args> {
    #[lang = "fn_once_output"]
    type Output;

    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}

#[lang = "fn_mut"]
#[rustc_paren_sugar]
pub trait FnMut<Args>: FnOnce<Args> {
    extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
}

#[lang = "panic"]
#[track_caller]
pub fn panic(_msg: &str) -> ! {
    unsafe {
        libc::puts("Panicking\n\0" as *const str as *const u8);
        intrinsics::abort();
    }
}

#[lang = "panic_bounds_check"]
#[track_caller]
fn panic_bounds_check(index: usize, len: usize) -> ! {
    unsafe {
        libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
        intrinsics::abort();
    }
}

#[lang = "eh_personality"]
fn eh_personality() -> ! {
    loop {}
}

#[lang = "drop_in_place"]
#[allow(unconditional_recursion)]
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
    // Code here does not matter - this is replaced by the
    // real drop glue by the compiler.
    drop_in_place(to_drop);
}

#[lang = "deref"]
pub trait Deref {
    type Target: ?Sized;

    fn deref(&self) -> &Self::Target;
}

pub trait Allocator {
}

pub struct Global;

impl Allocator for Global {}

#[lang = "owned_box"]
pub struct Box<
    T: ?Sized,
    A: Allocator = Global,
>(*mut T, A);

impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}

impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
    fn drop(&mut self) {
        // drop is currently performed by compiler.
    }
}

impl<T> Deref for Box<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &**self
    }
}

#[lang = "exchange_malloc"]
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
    libc::malloc(size)
}

#[lang = "box_free"]
unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: *mut T, alloc: A) {
    libc::free(ptr as *mut u8);
}

#[lang = "drop"]
pub trait Drop {
    fn drop(&mut self);
}

#[lang = "manually_drop"]
#[repr(transparent)]
pub struct ManuallyDrop<T: ?Sized> {
    pub value: T,
}

#[lang = "maybe_uninit"]
#[repr(transparent)]
pub union MaybeUninit<T> {
    pub uninit: (),
    pub value: ManuallyDrop<T>,
}

pub mod intrinsics {
    extern "rust-intrinsic" {
        pub fn abort() -> !;
        pub fn size_of<T>() -> usize;
        pub fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
        pub fn min_align_of<T>() -> usize;
        pub fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize;
        pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
        pub fn transmute<T, U>(e: T) -> U;
        pub fn ctlz_nonzero<T>(x: T) -> T;
        pub fn needs_drop<T: ?::Sized>() -> bool;
        pub fn bitreverse<T>(x: T) -> T;
        pub fn bswap<T>(x: T) -> T;
        pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
        pub fn unreachable() -> !;
    }
}

pub mod libc {
    #[link(name = "c")]
    extern "C" {
        pub fn puts(s: *const u8) -> i32;
        pub fn printf(format: *const i8, ...) -> i32;
        pub fn malloc(size: usize) -> *mut u8;
        pub fn free(ptr: *mut u8);
        pub fn memcpy(dst: *mut u8, src: *const u8, size: usize);
        pub fn memmove(dst: *mut u8, src: *const u8, size: usize);
        pub fn strncpy(dst: *mut u8, src: *const u8, size: usize);
    }
}

#[lang = "index"]
pub trait Index<Idx: ?Sized> {
    type Output: ?Sized;
    fn index(&self, index: Idx) -> &Self::Output;
}

impl<T> Index<usize> for [T; 3] {
    type Output = T;

    fn index(&self, index: usize) -> &Self::Output {
        &self[index]
    }
}

impl<T> Index<usize> for [T] {
    type Output = T;

    fn index(&self, index: usize) -> &Self::Output {
        &self[index]
    }
}

extern {
    type VaListImpl;
}

#[lang = "va_list"]
#[repr(transparent)]
pub struct VaList<'a>(&'a mut VaListImpl);

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro stringify($($t:tt)*) { /* compiler built-in */ }

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro file() { /* compiler built-in */ }

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro line() { /* compiler built-in */ }

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro cfg() { /* compiler built-in */ }

pub static A_STATIC: u8 = 42;

#[lang = "panic_location"]
struct PanicLocation {
    file: &'static str,
    line: u32,
    column: u32,
}

#[no_mangle]
pub fn get_tls() -> u8 {
    #[thread_local]
    static A: u8 = 42;

    A
}

Meta

rustc --version --verbose:

rustc 1.63.0-nightly (dc80ca78b 2022-06-21)
binary: rustc
commit-hash: dc80ca78b6ec2b6bba02560470347433bcd0bb3c
commit-date: 2022-06-21
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

Error output

warning: unused variable: `alloc`
   --> ./compiler/rustc_codegen_gcc/example/mini_core.rs:485:58
    |
485 | unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: *mut T, alloc: A) {
    |                                                          ^^^^^ help: if this is intentional, prefix it with an underscore: `_alloc`
    |
    = note: `#[warn(unused_variables)]` on by default

error: internal compiler error: compiler/rustc_mir_transform/src/elaborate_box_derefs.rs:106:17: expected Box to contain Unique
   --> ./compiler/rustc_codegen_gcc/example/mini_core.rs:461:3
    |
461 | >(*mut T, A);
    |   ^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/compiler/rustc_errors/src/lib.rs:1331:9
stack backtrace:
Backtrace

error: internal compiler error: compiler/rustc_mir_transform/src/elaborate_box_derefs.rs:106:17: expected Box to contain Unique
   --> ./compiler/rustc_codegen_gcc/example/mini_core.rs:461:3
    |
461 | >(*mut T, A);
    |   ^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/compiler/rustc_errors/src/lib.rs:1331:9
stack backtrace:
   0:     0x7fa37629e02d - std::backtrace_rs::backtrace::libunwind::trace::h66824bd979b46652
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fa37629e02d - std::backtrace_rs::backtrace::trace_unsynchronized::h0caf895dc6521160
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa37629e02d - std::sys_common::backtrace::_print_fmt::h8ee19c74892f96ef
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fa37629e02d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4f38873b172b3ee3
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fa3762f9dec - core::fmt::write::h95bc5c1a2dab38ae
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/core/src/fmt/mod.rs:1197:17
   5:     0x7fa37628f741 - std::io::Write::write_fmt::hcbe645da27d05687
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/io/mod.rs:1672:15
   6:     0x7fa3762a0cf5 - std::sys_common::backtrace::_print::h491b32351e64ba40
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fa3762a0cf5 - std::sys_common::backtrace::print::h95813b9263ac2531
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fa3762a0cf5 - std::panicking::default_hook::{{closure}}::h97b51a053e0a66a6
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:295:22
   9:     0x7fa3762a0a16 - std::panicking::default_hook::h4e7a054eecf2a40c
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:314:9
  10:     0x7fa376afd3c4 - rustc_driver[90499e6357860faf]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fa3762a13ca - std::panicking::rust_panic_with_hook::hc34128de9b2f1619
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/panicking.rs:702:17
  12:     0x7fa376c99f81 - std[b701561e8274a90e]::panicking::begin_panic::<rustc_errors[66b38508c80fa53]::ExplicitBug>::{closure#0}
  13:     0x7fa376c98756 - std[b701561e8274a90e]::sys_common::backtrace::__rust_end_short_backtrace::<std[b701561e8274a90e]::panicking::begin_panic<rustc_errors[66b38508c80fa53]::ExplicitBug>::{closure#0}, !>
  14:     0x7fa376cc4c96 - std[b701561e8274a90e]::panicking::begin_panic::<rustc_errors[66b38508c80fa53]::ExplicitBug>
  15:     0x7fa376ca4906 - std[b701561e8274a90e]::panic::panic_any::<rustc_errors[66b38508c80fa53]::ExplicitBug>
  16:     0x7fa376ca2791 - <rustc_errors[66b38508c80fa53]::HandlerInner>::span_bug::<rustc_span[a21f0b15de3a4c22]::span_encoding::Span, &alloc[2bc16101ff7e918e]::string::String>
  17:     0x7fa376ca2560 - <rustc_errors[66b38508c80fa53]::Handler>::span_bug::<rustc_span[a21f0b15de3a4c22]::span_encoding::Span, &alloc[2bc16101ff7e918e]::string::String>
  18:     0x7fa376c65498 - rustc_middle[72ed1f8610012006]::ty::context::tls::with_opt::<rustc_middle[72ed1f8610012006]::util::bug::opt_span_bug_fmt<rustc_span[a21f0b15de3a4c22]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7fa376c65336 - rustc_middle[72ed1f8610012006]::util::bug::opt_span_bug_fmt::<rustc_span[a21f0b15de3a4c22]::span_encoding::Span>
  20:     0x7fa376c652f4 - rustc_middle[72ed1f8610012006]::util::bug::span_bug_fmt::<rustc_span[a21f0b15de3a4c22]::span_encoding::Span>
  21:     0x7fa377fb351c - <rustc_mir_transform[9ad3929c9a854eea]::elaborate_box_derefs::ElaborateBoxDerefs as rustc_middle[72ed1f8610012006]::mir::MirPass>::run_pass
  22:     0x7fa377f40150 - rustc_mir_transform[9ad3929c9a854eea]::pass_manager::run_passes
  23:     0x7fa377f31ee9 - rustc_mir_transform[9ad3929c9a854eea]::mir_drops_elaborated_and_const_checked
  24:     0x7fa3786af83b - rustc_query_system[a3029e6dae607812]::query::plumbing::try_execute_query::<rustc_query_impl[7ac02512ff88ed66]::plumbing::QueryCtxt, rustc_query_system[a3029e6dae607812]::query::caches::DefaultCache<rustc_middle[72ed1f8610012006]::ty::WithOptConstParam<rustc_span[a21f0b15de3a4c22]::def_id::LocalDefId>, &rustc_data_structures[c41427e6dab4dba2]::steal::Steal<rustc_middle[72ed1f8610012006]::mir::Body>>>
  25:     0x7fa37869690a - <rustc_query_impl[7ac02512ff88ed66]::Queries as rustc_middle[72ed1f8610012006]::ty::query::QueryEngine>::mir_drops_elaborated_and_const_checked
  26:     0x7fa377e222fc - <rustc_session[4ced65ff44b6b5e6]::session::Session>::time::<(), rustc_interface[fff95432a826ec6b]::passes::analysis::{closure#3}>
  27:     0x7fa378cfb23c - rustc_interface[fff95432a826ec6b]::passes::analysis
  28:     0x7fa37925bc0f - rustc_query_system[a3029e6dae607812]::query::plumbing::try_execute_query::<rustc_query_impl[7ac02512ff88ed66]::plumbing::QueryCtxt, rustc_query_system[a3029e6dae607812]::query::caches::DefaultCache<(), core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>>
  29:     0x7fa3792a56ee - rustc_query_system[a3029e6dae607812]::query::plumbing::get_query::<rustc_query_impl[7ac02512ff88ed66]::queries::analysis, rustc_query_impl[7ac02512ff88ed66]::plumbing::QueryCtxt>
  30:     0x7fa378cde5a7 - <rustc_interface[fff95432a826ec6b]::passes::QueryContext>::enter::<rustc_driver[90499e6357860faf]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  31:     0x7fa378cc884f - <rustc_interface[fff95432a826ec6b]::interface::Compiler>::enter::<rustc_driver[90499e6357860faf]::run_compiler::{closure#1}::{closure#2}, core[61a96b067728b167]::result::Result<core[61a96b067728b167]::option::Option<rustc_interface[fff95432a826ec6b]::queries::Linker>, rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  32:     0x7fa378cecd2f - rustc_span[a21f0b15de3a4c22]::with_source_map::<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_interface[fff95432a826ec6b]::interface::create_compiler_and_run<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#1}>
  33:     0x7fa378cc96e2 - <scoped_tls[fd6fb1272a57f899]::ScopedKey<rustc_span[a21f0b15de3a4c22]::SessionGlobals>>::set::<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  34:     0x7fa378cdecdf - std[b701561e8274a90e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fff95432a826ec6b]::util::run_in_thread_pool_with_globals<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>
  35:     0x7fa378cdee19 - <<std[b701561e8274a90e]::thread::Builder>::spawn_unchecked_<rustc_interface[fff95432a826ec6b]::util::run_in_thread_pool_with_globals<rustc_interface[fff95432a826ec6b]::interface::run_compiler<core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>, rustc_driver[90499e6357860faf]::run_compiler::{closure#1}>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#0}, core[61a96b067728b167]::result::Result<(), rustc_errors[66b38508c80fa53]::ErrorGuaranteed>>::{closure#1} as core[61a96b067728b167]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7fa3762ab303 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hed39a37500816679
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/alloc/src/boxed.rs:1951:9
  37:     0x7fa3762ab303 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf70a23328098c6ee
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/alloc/src/boxed.rs:1951:9
  38:     0x7fa3762ab303 - std::sys::unix::thread::Thread::new::thread_start::h4e2fce376f42517a
                               at /rustc/dc80ca78b6ec2b6bba02560470347433bcd0bb3c/library/std/src/sys/unix/thread.rs:108:17
  39:     0x7fa37607f54d - <unknown>
  40:     0x7fa376104b14 - clone
  41:                0x0 - <unknown>

note: 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: rustc 1.63.0-nightly (dc80ca78b 2022-06-21) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `<impl at ./compiler/rustc_codegen_gcc/example/mini_core.rs:86:1: 86:33>::{constant#0}`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 1 warning emitted

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Jun 22, 2022
@Urgau
Copy link
Member

Urgau commented Jun 22, 2022

Isn't this expected ? The definition of Box wants a Unique and is defined with a Unique in alloc:

pub struct Box<
T: ?Sized,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
>(Unique<T>, A);

The fix here would be to add a definition of for Unique and to use it in Box definition.

@matthiaskrgr
Copy link
Member Author

This ICEs since #95576

@matthiaskrgr
Copy link
Member Author

reduced.

#![feature(
    no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types,
    untagged_unions, decl_macro, rustc_attrs, transparent_unions, auto_traits,
    thread_local
)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

#[lang = "unsize"]
pub trait Unsize<T: ?Sized> {}

#[lang = "coerce_unsized"]
pub trait CoerceUnsized<T> {}

#[lang = "copy"]
pub trait Copy {}

#[lang = "sync"]
pub unsafe trait Sync {}

unsafe impl Sync for [u8; 16] {}

pub trait Allocator {
}

pub struct Global;

impl Allocator for Global {}

#[lang = "owned_box"]
pub struct Box<
    T: ?Sized,
    A: Allocator = Global,
>(*mut T, A);

matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 22, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 22, 2022
@CAD97
Copy link
Contributor

CAD97 commented Jun 22, 2022

I agree that this is an expected ICE (misuse of lang items), and minicore needs to define a Unique... but Unique should imo be referenced by a lang item here, so you'd at least get a "missing lang item" error with this code as-is.

For a worse ICE that doesn't give context, try ending with

#[lang = "phantom_data"]
pub struct PhantomData<T: ?Sized>;

#[lang = "owned_box"]
pub struct Box<T: ?Sized, A: Allocator = Global>(PhantomData<T>, A);
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', compiler\rustc_mir_transform\src\elaborate_box_derefs.rs:109:31

@matthiaskrgr
Copy link
Member Author

Hm, so is it wrong that the code compiler before? 🤔

@bjorn3
Copy link
Member

bjorn3 commented Jun 22, 2022

cg_clif's mini_core already uses Unique: https://github.com/bjorn3/rustc_codegen_cranelift/blob/c431540544a03dc09577df4b97afd868deb167e5/example/mini_core.rs#L514 Should be easy to copy given that cg_gcc's mini_core started as copy of cg_clif's one.

@bjorn3
Copy link
Member

bjorn3 commented Jun 22, 2022

@matthiaskrgr It just so happened that previously it compiled. Lang items are very easy to misuse as they the compiler expects specific definitions, but doesn't do much checks that the actual definitions match the expectations.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 23, 2022

Not sure how much we should be doing here beyond improving the ICEs. We can replicate the entire lang item structure inside the compiler, but that's just complex code duplication. The standard library is already the code that defines it. What we could try is to pull out the relevant definitions so that all the minicore crates are just a bunch of include! calls that get updated automatically

@bjorn3
Copy link
Member

bjorn3 commented Jun 23, 2022

How would that work with subtrees? Both rustc_codegen_cranelift and rustc_codegen_gcc can be compiled outside of the main rust repo. This means that they can't include!() files outside of their directory. At best it could get included from the sysroot, but I don't think it is possible to do that using include!().

@oli-obk
Copy link
Contributor

oli-obk commented Jun 23, 2022

Hm... yea. that won't work :(

@CAD97
Copy link
Contributor

CAD97 commented Jun 23, 2022

If we wanted, we could publish a minicore to crates-io. (In fact, the minicore name is available.) However, the benefit of minicores for testing is mostly in having it inline and highly domain specific, so that might cancel out nearly all of the benefits.

(For this specific case, the eventual “correct” solution is “just” to stop directly codegening box deref and rely on its Deref::deref impl.)

Rambling about future possibilities

In the future, it might be nice to incrementally extract the "I know X about the shape of lang item Z" earlier into the compiler, rather than having it scattered about the compiler. Doing so would have a twofold benefit:

  • catch_unwind any panics to decorate the ICE with a "malformed lang item" note
  • avoid rederiving facts and potential inconsistencies

For this case, you'd have a derived lang item for the projection Box<T> -> *mut T. For something like the Pointee trait, the Metadata projection could be a derived lang item rather than separately annotated.

However, this is probably overengineering for a failure case which is inherently an unsafe violation of preconditions, and just marking and using the one lang item system is simpler.

@workingjubilee workingjubilee added the F-rustc_attrs Internal rustc attributes gated on the `#[rustc_attrs]` feature gate. label Mar 14, 2023
@Noratrieb Noratrieb added the requires-internal-features This issue requires the use of internal features. label Apr 5, 2023
@Noratrieb
Copy link
Member

closing as wontfix

@Noratrieb Noratrieb closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2023
@workingjubilee workingjubilee removed the C-bug Category: This is a bug. label Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-rustc_attrs Internal rustc attributes gated on the `#[rustc_attrs]` feature gate. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-internal-features This issue requires the use of internal features. 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

8 participants