-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Open
Labels
A-coinductionArea: Concerning coinduction, most often for auto traitsArea: Concerning coinduction, most often for auto traitsA-miriArea: The miri toolArea: The miri toolA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)
Description
trait Apply {
type Output<T: Trait>: Trait;
}
struct Identity;
impl Apply for Identity {
type Output<T: Trait> = T;
}
struct Thing<A: Apply>(A);
trait Trait {
fn method() {}
}
impl<A: Apply> Trait for Thing<A> where <A as Apply>::Output<Self>: Trait {}
/*
effectively:
impl Trait for Thing<Identity> where Thing<Identity>: Trait {}
*/
fn weird<A: Apply>() {
<Thing<A> as Trait>::method();
}
fn main() {
weird::<Identity>();
}In the above code, each indivuidual trait bound holds pre-monomorphization. However, after monomorphization, the required trait bound is Thing<Identity>: Trait. Trying to prove this bound runs into a coinductive cycle.
In normal compilation, we get the following post-mono error (ran on the playground with version 1.94.0-nightly (2025-12-29 56f24e00c62ec2db9a8b)):
error[E0275]: overflow evaluating the requirement `Thing<Identity>: Trait`
|
note: required by a bound in `Apply::Output`
--> src/main.rs:2:20
|
2 | type Output<T: Trait>: Trait;
| ^^^^^ required by this bound in `Apply::Output`
For more information about this error, try `rustc --explain E0275`.
error: could not compile `playground` (bin "playground") due to 1 previous error
However, running the code with Miri gives the following ICE (ran on the playground with Miri version 0.1.0 (2025-12-29 56f24e00c6)):
Output with Miri
error[E0275]: overflow evaluating the requirement `Thing<Identity>: Trait`
|
note: required by a bound in `Apply::Output`
--> src/main.rs:2:20
|
2 | type Output<T: Trait>: Trait;
| ^^^^^ required by this bound in `Apply::Output`
Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
note: the place in the program where the ICE was triggered
--> src/main.rs:23:4
|
23 | <Thing<A> as Trait>::method();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: BACKTRACE:
= note: inside `weird::<Identity>` at src/main.rs:23:4: 23:33
note: inside `main`
--> src/main.rs:27:5
|
27 | weird::<Identity>();
| ^^^^^^^^^^^^^^^^^^^
= note: inside `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: 250:71
= note: inside `std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166:18: 166:21
= note: inside closure at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:206:18: 206:75
= note: inside `std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:287:13: 287:31
= note: inside `std::panicking::catch_unwind::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:581:40: 581:43
= note: inside `std::panicking::catch_unwind::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19: 544:88
= note: inside `std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14: 359:40
= note: inside closure at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:175:24: 175:49
= note: inside `std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:581:40: 581:43
= note: inside `std::panicking::catch_unwind::<isize, {closure@std::rt::lang_start_internal::{closure#0}}>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19: 544:88
= note: inside `std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14: 359:40
= note: inside `std::rt::lang_start_internal` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:171:5: 193:7
= note: inside `std::rt::lang_start::<()>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205:5: 210:6
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0275`.
Additionally, running the code with -Znext-solver gives the following ICE (ran on godbolt with version 1.94.0-nightly (7b5cde737 2025-12-27) and changing fn main to pub fn main):
Output with next-solver
error: internal compiler error: /rustc-dev/7b5cde7370b82fecf700071dda98c3fbc7d41fae/compiler/rustc_middle/src/ty/instance.rs:579:21: failed to resolve instance for <Thing<Identity> as Trait>::method
--> <source>:23:4
|
23 | <Thing<A> as Trait>::method();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
thread 'rustc' (3) panicked at /rustc-dev/7b5cde7370b82fecf700071dda98c3fbc7d41fae/compiler/rustc_middle/src/ty/instance.rs:579:21:
Box<dyn Any>
stack backtrace:
0: 0x7228bb653393 - <<std[d04b43a2428f6e7c]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[5301abcae13ad7a]::fmt::Display>::fmt
1: 0x7228bbc10b88 - core[5301abcae13ad7a]::fmt::write
2: 0x7228bb669aa6 - <std[d04b43a2428f6e7c]::sys::stdio::unix::Stderr as std[d04b43a2428f6e7c]::io::Write>::write_fmt
3: 0x7228bb629c48 - std[d04b43a2428f6e7c]::panicking::default_hook::{closure#0}
4: 0x7228bb6472d3 - std[d04b43a2428f6e7c]::panicking::default_hook
5: 0x7228ba621aca - std[d04b43a2428f6e7c]::panicking::update_hook::<alloc[966711e2d4248474]::boxed::Box<rustc_driver_impl[d4ed2211832a1e45]::install_ice_hook::{closure#1}>>::{closure#0}
6: 0x7228bb6475b2 - std[d04b43a2428f6e7c]::panicking::panic_with_hook
7: 0x7228ba65e371 - std[d04b43a2428f6e7c]::panicking::begin_panic::<rustc_errors[cb139601f36bb398]::ExplicitBug>::{closure#0}
8: 0x7228ba64e866 - std[d04b43a2428f6e7c]::sys::backtrace::__rust_end_short_backtrace::<std[d04b43a2428f6e7c]::panicking::begin_panic<rustc_errors[cb139601f36bb398]::ExplicitBug>::{closure#0}, !>
9: 0x7228ba64be3c - std[d04b43a2428f6e7c]::panicking::begin_panic::<rustc_errors[cb139601f36bb398]::ExplicitBug>
10: 0x7228ba67c2b1 - <rustc_errors[cb139601f36bb398]::diagnostic::BugAbort as rustc_errors[cb139601f36bb398]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
11: 0x7228bac0693c - <rustc_errors[cb139601f36bb398]::DiagCtxtHandle>::span_bug::<rustc_span[41c12b187d0c00e0]::span_encoding::Span, alloc[966711e2d4248474]::string::String>
12: 0x7228bac2b636 - rustc_middle[b12d616c0d1b1d17]::util::bug::opt_span_bug_fmt::<rustc_span[41c12b187d0c00e0]::span_encoding::Span>::{closure#0}
13: 0x7228bac2b7e2 - rustc_middle[b12d616c0d1b1d17]::ty::context::tls::with_opt::<rustc_middle[b12d616c0d1b1d17]::util::bug::opt_span_bug_fmt<rustc_span[41c12b187d0c00e0]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x7228bac1c6db - rustc_middle[b12d616c0d1b1d17]::ty::context::tls::with_context_opt::<rustc_middle[b12d616c0d1b1d17]::ty::context::tls::with_opt<rustc_middle[b12d616c0d1b1d17]::util::bug::opt_span_bug_fmt<rustc_span[41c12b187d0c00e0]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x7228b904f0a8 - rustc_middle[b12d616c0d1b1d17]::util::bug::span_bug_fmt::<rustc_span[41c12b187d0c00e0]::span_encoding::Span>
16: 0x7228bc027975 - <rustc_middle[b12d616c0d1b1d17]::ty::instance::Instance>::expect_resolve
17: 0x7228bc3da1d5 - <rustc_monomorphize[93af97dab7a3fd6a]::collector::MirUsedCollector as rustc_middle[b12d616c0d1b1d17]::mir::visit::Visitor>::visit_terminator
18: 0x7228bc3d3a4a - rustc_monomorphize[93af97dab7a3fd6a]::collector::items_of_instance
19: 0x7228bc3d343a - rustc_query_impl[7dbdc15bcc8f2d5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b12d616c0d1b1d17]::query::erase::Erased<[u8; 32usize]>>
20: 0x7228bc830195 - rustc_query_system[ff548912004eb624]::query::plumbing::try_execute_query::<rustc_query_impl[7dbdc15bcc8f2d5]::DynamicConfig<rustc_query_system[ff548912004eb624]::query::caches::DefaultCache<(rustc_middle[b12d616c0d1b1d17]::ty::instance::Instance, rustc_middle[b12d616c0d1b1d17]::mir::mono::CollectionMode), rustc_middle[b12d616c0d1b1d17]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[7dbdc15bcc8f2d5]::plumbing::QueryCtxt, false>
21: 0x7228bc82fdbf - rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::items_of_instance::get_query_non_incr::__rust_end_short_backtrace
22: 0x7228bd073e6e - rustc_monomorphize[93af97dab7a3fd6a]::collector::collect_items_rec
23: 0x7228bd078042 - rustc_monomorphize[93af97dab7a3fd6a]::collector::collect_items_rec
24: 0x7228bbf0dba1 - rustc_monomorphize[93af97dab7a3fd6a]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
25: 0x7228bc38e658 - rustc_monomorphize[93af97dab7a3fd6a]::partitioning::collect_and_partition_mono_items
26: 0x7228bd028624 - rustc_query_impl[7dbdc15bcc8f2d5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b12d616c0d1b1d17]::query::erase::Erased<[u8; 24usize]>>
27: 0x7228bd028609 - <rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[5301abcae13ad7a]::ops::function::FnOnce<(rustc_middle[b12d616c0d1b1d17]::ty::context::TyCtxt, ())>>::call_once
28: 0x7228bd02815e - rustc_query_system[ff548912004eb624]::query::plumbing::try_execute_query::<rustc_query_impl[7dbdc15bcc8f2d5]::DynamicConfig<rustc_query_system[ff548912004eb624]::query::caches::SingleCache<rustc_middle[b12d616c0d1b1d17]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[7dbdc15bcc8f2d5]::plumbing::QueryCtxt, false>
29: 0x7228bd027f03 - rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
30: 0x7228bc7fde9f - rustc_codegen_ssa[6bd2bc7e2f8a2c6d]::back::symbol_export::exported_generic_symbols_provider_local
31: 0x7228bcb6f275 - rustc_query_impl[7dbdc15bcc8f2d5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::exported_generic_symbols::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b12d616c0d1b1d17]::query::erase::Erased<[u8; 16usize]>>
32: 0x7228bcb6f24b - <rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::exported_generic_symbols::dynamic_query::{closure#2} as core[5301abcae13ad7a]::ops::function::FnOnce<(rustc_middle[b12d616c0d1b1d17]::ty::context::TyCtxt, rustc_span[41c12b187d0c00e0]::def_id::CrateNum)>>::call_once
33: 0x7228bcb6d0a6 - rustc_query_system[ff548912004eb624]::query::plumbing::try_execute_query::<rustc_query_impl[7dbdc15bcc8f2d5]::DynamicConfig<rustc_data_structures[6f877b1072984333]::vec_cache::VecCache<rustc_span[41c12b187d0c00e0]::def_id::CrateNum, rustc_middle[b12d616c0d1b1d17]::query::erase::Erased<[u8; 16usize]>, rustc_query_system[ff548912004eb624]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[7dbdc15bcc8f2d5]::plumbing::QueryCtxt, false>
34: 0x7228bcb6cbcc - rustc_query_impl[7dbdc15bcc8f2d5]::query_impl::exported_generic_symbols::get_query_non_incr::__rust_end_short_backtrace
35: 0x7228bc460a0d - <rustc_metadata[15381d64219637fd]::rmeta::encoder::EncodeContext>::encode_crate_root
36: 0x7228bcfe0612 - <rustc_metadata[15381d64219637fd]::rmeta::encoder::encode_metadata::{closure#3} as core[5301abcae13ad7a]::ops::function::FnOnce<(rustc_middle[b12d616c0d1b1d17]::ty::context::TyCtxt, &std[d04b43a2428f6e7c]::path::Path)>>::call_once
37: 0x7228bcfdd853 - rustc_metadata[15381d64219637fd]::rmeta::encoder::encode_metadata
38: 0x7228bcbe9b7f - rustc_metadata[15381d64219637fd]::fs::encode_and_write_metadata
39: 0x7228bcfd1ee8 - <rustc_interface[84bae928b5c4a14c]::queries::Linker>::codegen_and_build_linker
40: 0x7228bcfcf6dc - <rustc_interface[84bae928b5c4a14c]::passes::create_and_enter_global_ctxt<core[5301abcae13ad7a]::option::Option<rustc_interface[84bae928b5c4a14c]::queries::Linker>, rustc_driver_impl[d4ed2211832a1e45]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[5301abcae13ad7a]::ops::function::FnOnce<(&rustc_session[34b11767d146bd]::session::Session, rustc_middle[b12d616c0d1b1d17]::ty::context::CurrentGcx, alloc[966711e2d4248474]::sync::Arc<rustc_data_structures[6f877b1072984333]::jobserver::Proxy>, &std[d04b43a2428f6e7c]::sync::once_lock::OnceLock<rustc_middle[b12d616c0d1b1d17]::ty::context::GlobalCtxt>, &rustc_data_structures[6f877b1072984333]::sync::worker_local::WorkerLocal<rustc_middle[b12d616c0d1b1d17]::arena::Arena>, &rustc_data_structures[6f877b1072984333]::sync::worker_local::WorkerLocal<rustc_hir[bd2e92b33866e02d]::Arena>, rustc_driver_impl[d4ed2211832a1e45]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
41: 0x7228bcdf2358 - rustc_interface[84bae928b5c4a14c]::interface::run_compiler::<(), rustc_driver_impl[d4ed2211832a1e45]::run_compiler::{closure#0}>::{closure#1}
42: 0x7228bcd926ce - std[d04b43a2428f6e7c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[84bae928b5c4a14c]::util::run_in_thread_with_globals<rustc_interface[84bae928b5c4a14c]::util::run_in_thread_pool_with_globals<rustc_interface[84bae928b5c4a14c]::interface::run_compiler<(), rustc_driver_impl[d4ed2211832a1e45]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
43: 0x7228bcd924a0 - <std[d04b43a2428f6e7c]::thread::lifecycle::spawn_unchecked<rustc_interface[84bae928b5c4a14c]::util::run_in_thread_with_globals<rustc_interface[84bae928b5c4a14c]::util::run_in_thread_pool_with_globals<rustc_interface[84bae928b5c4a14c]::interface::run_compiler<(), rustc_driver_impl[d4ed2211832a1e45]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5301abcae13ad7a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
44: 0x7228bcd97df8 - <std[d04b43a2428f6e7c]::sys::thread::unix::Thread>::new::thread_start
45: 0x7228b6694ac3 - <unknown>
46: 0x7228b67268c0 - <unknown>
47: 0x0 - <unknown>
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 `/app/rustc-ice-2025-12-30T02_26_48-1.txt` to your bug report
note: rustc 1.94.0-nightly (7b5cde737 2025-12-27) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 -C llvm-args=--x86-asm-syntax=intel --crate-type rlib -Z next-solver
query stack during panic:
#0 [items_of_instance] collecting items used by `weird::<Identity>`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
error: aborting due to 1 previous error
See also #149898
Metadata
Metadata
Assignees
Labels
A-coinductionArea: Concerning coinduction, most often for auto traitsArea: Concerning coinduction, most often for auto traitsA-miriArea: The miri toolArea: The miri toolA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)The Rustc Trait System Refactor Initiative (-Znext-solver)