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: 'cannot copy unsized immediates' creating Box of trait object with generics #102553

Closed
qwertz19281 opened this issue Oct 1, 2022 · 1 comment · Fixed by #102559
Closed
Assignees
Labels
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.

Comments

@qwertz19281
Copy link

While cargo check succeeds without warnings, cargo build fails on nightly on this code.

On stable 1.64.0, both checking and building succeed without warnings.

Code (playground)

pub trait Widget<E> {
    fn boxed<'w>(self) -> Box<dyn WidgetDyn<E>+'w> where Self: Sized + 'w;
}

pub trait WidgetDyn<E> {}

impl<T,E> WidgetDyn<E> for T where T: Widget<E> {}

impl<E> Widget<E> for dyn WidgetDyn<E> + '_ {
    fn boxed<'w>(self) -> Box<dyn WidgetDyn<E>+'w> where Self: Sized + 'w {
        Box::new(self) //ICE: cannot copy unsized immediates
    }
}

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (8ce3204af 2022-09-30)
binary: rustc
commit-hash: 8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6
commit-date: 2022-09-30
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2

Error output

thread 'rustc' panicked at 'cannot copy unsized immediates', /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/compiler/rustc_const_eval/src/interpret/place.rs:643:17
Backtrace

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'cannot copy unsized immediates', /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/compiler/rustc_const_eval/src/interpret/place.rs:643:17
stack backtrace:
   0:     0x7f20d3308470 - std::backtrace_rs::backtrace::libunwind::trace::h48a6b877947e3b61
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f20d3308470 - std::backtrace_rs::backtrace::trace_unsynchronized::hfe09011594941abe
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f20d3308470 - std::sys_common::backtrace::_print_fmt::h9ce2ad36264dcd3e
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f20d3308470 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4f730349406daa4f
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f20d336330e - core::fmt::write::h4545826f01b877ac
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/core/src/fmt/mod.rs:1209:17
   5:     0x7f20d32f90f5 - std::io::Write::write_fmt::hac4d3a613c78c8e4
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/io/mod.rs:1679:15
   6:     0x7f20d330b213 - std::sys_common::backtrace::_print::ha560f7b733dc8a6e
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f20d330b213 - std::sys_common::backtrace::print::hcca78599db59c8b4
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f20d330b213 - std::panicking::default_hook::{{closure}}::h0d6a74e6cb8499ce
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/panicking.rs:267:22
   9:     0x7f20d330aeea - std::panicking::default_hook::hcb5d3609ae810fb1
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/panicking.rs:286:9
  10:     0x7f20d5b6a7d1 - rustc_driver[6635a35d3e701dd7]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f20d330ba4b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hba26835306149e75
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/alloc/src/boxed.rs:1952:9
  12:     0x7f20d330ba4b - std::panicking::rust_panic_with_hook::h4f2461a1c1c1a86e
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/panicking.rs:673:13
  13:     0x7f20d330b861 - std::panicking::begin_panic_handler::{{closure}}::hcad64e5dfff8b9ed
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/panicking.rs:558:13
  14:     0x7f20d330891c - std::sys_common::backtrace::__rust_end_short_backtrace::h2a66b4ccd8d28c5b
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/sys_common/backtrace.rs:138:18
  15:     0x7f20d330b5c2 - rust_begin_unwind
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/panicking.rs:556:5
  16:     0x7f20d335fee3 - core::panicking::panic_fmt::h443d402932f5c508
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/core/src/panicking.rs:142:14
  17:     0x7f20d52394a9 - <rustc_const_eval[596954f8d26f1fb9]::interpret::eval_context::InterpCx<rustc_mir_transform[aa15e105a635a786]::const_prop::ConstPropMachine>>::eval_rvalue_into_place
  18:     0x7f20d4f6a2e9 - <rustc_mir_transform[aa15e105a635a786]::const_prop_lint::ConstPropagator as rustc_middle[cea04118b266f04d]::mir::visit::Visitor>::visit_body
  19:     0x7f20d4f61ccc - <rustc_mir_transform[aa15e105a635a786]::const_prop_lint::ConstProp as rustc_mir_transform[aa15e105a635a786]::pass_manager::MirLint>::run_lint
  20:     0x7f20d460b2f5 - rustc_mir_transform[aa15e105a635a786]::pass_manager::run_passes_no_validate
  21:     0x7f20d4608524 - rustc_mir_transform[aa15e105a635a786]::run_analysis_to_runtime_passes
  22:     0x7f20d4607542 - rustc_mir_transform[aa15e105a635a786]::mir_drops_elaborated_and_const_checked
  23:     0x7f20d510eed3 - rustc_query_system[effbf359c8fbf60]::query::plumbing::try_execute_query::<rustc_query_impl[7290f92e0d30aec0]::plumbing::QueryCtxt, rustc_query_system[effbf359c8fbf60]::query::caches::DefaultCache<rustc_middle[cea04118b266f04d]::ty::WithOptConstParam<rustc_span[ea709073fc09e903]::def_id::LocalDefId>, &rustc_data_structures[83030b31f5a5da14]::steal::Steal<rustc_middle[cea04118b266f04d]::mir::Body>>>
  24:     0x7f20d5aabcce - <rustc_query_impl[7290f92e0d30aec0]::Queries as rustc_middle[cea04118b266f04d]::ty::query::QueryEngine>::mir_drops_elaborated_and_const_checked
  25:     0x7f20d4688fdb - rustc_mir_transform[aa15e105a635a786]::optimized_mir
  26:     0x7f20d45a2562 - rustc_query_system[effbf359c8fbf60]::query::plumbing::try_execute_query::<rustc_query_impl[7290f92e0d30aec0]::plumbing::QueryCtxt, rustc_query_system[effbf359c8fbf60]::query::caches::DefaultCache<rustc_span[ea709073fc09e903]::def_id::DefId, &rustc_middle[cea04118b266f04d]::mir::Body>>
  27:     0x7f20d5aac0bf - <rustc_query_impl[7290f92e0d30aec0]::Queries as rustc_middle[cea04118b266f04d]::ty::query::QueryEngine>::optimized_mir
  28:     0x7f20d4e1974f - <rustc_metadata[c2fa7c38f8bdc238]::rmeta::encoder::EncodeContext>::encode_crate_root
  29:     0x7f20d487f872 - rustc_metadata[c2fa7c38f8bdc238]::rmeta::encoder::encode_metadata_impl
  30:     0x7f20d4865cbe - rustc_data_structures[83030b31f5a5da14]::sync::join::<rustc_metadata[c2fa7c38f8bdc238]::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata[c2fa7c38f8bdc238]::rmeta::encoder::encode_metadata::{closure#1}, (), ()>
  31:     0x7f20d4865b99 - rustc_metadata[c2fa7c38f8bdc238]::rmeta::encoder::encode_metadata
  32:     0x7f20d4864de3 - rustc_metadata[c2fa7c38f8bdc238]::fs::encode_and_write_metadata
  33:     0x7f20d4858d72 - <rustc_interface[c5619889e11552cd]::passes::QueryContext>::enter::<<rustc_interface[c5619889e11552cd]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[7ac8aee7065c0cc9]::result::Result<alloc[31d53a49c811d0c6]::boxed::Box<dyn core[7ac8aee7065c0cc9]::any::Any>, rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>>
  34:     0x7f20d481b343 - <rustc_interface[c5619889e11552cd]::queries::Queries>::ongoing_codegen
  35:     0x7f20d48195ca - rustc_interface[c5619889e11552cd]::interface::create_compiler_and_run::<core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>, rustc_driver[6635a35d3e701dd7]::run_compiler::{closure#1}>
  36:     0x7f20d4817ed1 - <scoped_tls[d196d212a4d59b56]::ScopedKey<rustc_span[ea709073fc09e903]::SessionGlobals>>::set::<rustc_interface[c5619889e11552cd]::interface::run_compiler<core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>, rustc_driver[6635a35d3e701dd7]::run_compiler::{closure#1}>::{closure#0}, core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>>
  37:     0x7f20d4817bbf - std[25baae9c6c77129a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c5619889e11552cd]::util::run_in_thread_pool_with_globals<rustc_interface[c5619889e11552cd]::interface::run_compiler<core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>, rustc_driver[6635a35d3e701dd7]::run_compiler::{closure#1}>::{closure#0}, core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>>::{closure#0}, core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>>
  38:     0x7f20d59cfbd0 - <<std[25baae9c6c77129a]::thread::Builder>::spawn_unchecked_<rustc_interface[c5619889e11552cd]::util::run_in_thread_pool_with_globals<rustc_interface[c5619889e11552cd]::interface::run_compiler<core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>, rustc_driver[6635a35d3e701dd7]::run_compiler::{closure#1}>::{closure#0}, core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>>::{closure#0}, core[7ac8aee7065c0cc9]::result::Result<(), rustc_errors[fbe8c5f47b14aa4]::ErrorGuaranteed>>::{closure#1} as core[7ac8aee7065c0cc9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7f20d3315663 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h15b2b49f1be836c1
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/alloc/src/boxed.rs:1938:9
  40:     0x7f20d3315663 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h2e516647663708b1
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/alloc/src/boxed.rs:1938:9
  41:     0x7f20d3315663 - std::sys::unix::thread::Thread::new::thread_start::hf5914966a92465bd
                               at /rustc/8ce3204af9463db3192ea1eb31c45c2f6d4b5ae6/library/std/src/sys/unix/thread.rs:108:17
  42:     0x7f20d31e8609 - start_thread
  43:     0x7f20d310b133 - clone
  44:                0x0 - <unknown>

error: internal compiler error: unexpected panic

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.66.0-nightly (8ce3204af 2022-09-30) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `<impl at src/lib.rs:9:1: 9:44>::boxed`
#1 [optimized_mir] optimizing MIR for `<impl at src/lib.rs:9:1: 9:44>::boxed`
end of query stack
error: could not compile `playground`

@qwertz19281 qwertz19281 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 Oct 1, 2022
@compiler-errors
Copy link
Member

this has to do with the trivially false Self: Sized predicate. Perhaps we should skip const prop if the where clauses of the function have any where clause predicates known to be false...

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. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants