marker traits can result in ambiguity during monomorphization
Open
Nobody has claimed this yet.
A-borrow-checker
A-trait-system
F-marker_trait_attr
I-ICE
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#![feature(marker_trait_attr)]
#[marker]
trait Trait {}
impl<'a, T: 'static> Trait for (T, &'a u32) {}
impl<'a, T: 'static> Trait for (&'a u32, T) {}
trait Other {
fn method() {}
}
impl<T: Trait> Other for T {}
fn foo<T: 'static>() {
<(T, &u32)>::method();
}
fn main() {
foo::<&u32>();
}
while (T, &u32): Trait has an unambiguous choice, (&u32, &u32): Trait has two choices, each of which results in different lifetime constraints. This results in ambiguity when monomorphizing foo, resulting in
error: internal compiler error: compiler/rustc_middle/src/ty/instance.rs:579:21: failed to resolve instance for <(&u32, &u32) as Other>::method
--> src/main.rs:16:5
|
16 | <(T, &u32)>::method();
| ^^^^^^^^^^^^^^^^^^^^^
thread 'rustc' (2044881) panicked at compiler/rustc_middle/src/ty/instance.rs:579:21:
Box<dyn Any>
stack backtrace:
0: 0x7f311f870583 - <<std[f73caa43acb03b8c]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[1f5c4c040b19307]::fmt::Display>::fmt
1: 0x7f311fe11bc8 - core[1f5c4c040b19307]::fmt::write
2: 0x7f311f886ef6 - <std[f73caa43acb03b8c]::sys::stdio::unix::Stderr as std[f73caa43acb03b8c]::io::Write>::write_fmt
3: 0x7f311f846fa3 - std[f73caa43acb03b8c]::panicking::default_hook::{closure#0}
4: 0x7f311f8666b0 - std[f73caa43acb03b8c]::panicking::default_hook
5: 0x7f311e8cd527 - std[f73caa43acb03b8c]::panicking::update_hook::<alloc[31570ea252afb3e]::boxed::Box<rustc_driver_impl[a62c041d93dad5ac]::install_ice_hook::{closure#1}>>::{closure#0}
6: 0x7f311f866992 - std[f73caa43acb03b8c]::panicking::panic_with_hook
7: 0x7f311e9094e1 - std[f73caa43acb03b8c]::panicking::begin_panic::<rustc_errors[e47345eadeff1cc0]::ExplicitBug>::{closure#0}
8: 0x7f311e8f9e06 - std[f73caa43acb03b8c]::sys::backtrace::__rust_end_short_backtrace::<std[f73caa43acb03b8c]::panicking::begin_panic<rustc_errors[e47345eadeff1cc0]::ExplicitBug>::{closure#0}, !>
9: 0x7f311e8f9a4a - std[f73caa43acb03b8c]::panicking::begin_panic::<rustc_errors[e47345eadeff1cc0]::ExplicitBug>
10: 0x7f311e926df1 - <rustc_errors[e47345eadeff1cc0]::diagnostic::BugAbort as rustc_errors[e47345eadeff1cc0]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
11: 0x7f311ee670bc - <rustc_errors[e47345eadeff1cc0]::DiagCtxtHandle>::span_bug::<rustc_span[4312f27e8c783d4a]::span_encoding::Span, alloc[31570ea252afb3e]::string::String>
12: 0x7f311ee88486 - rustc_middle[55db46a3a9e6fd01]::util::bug::opt_span_bug_fmt::<rustc_span[4312f27e8c783d4a]::span_encoding::Span>::{closure#0}
13: 0x7f311ee88632 - rustc_middle[55db46a3a9e6fd01]::ty::context::tls::with_opt::<rustc_middle[55db46a3a9e6fd01]::util::bug::opt_span_bug_fmt<rustc_span[4312f27e8c783d4a]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x7f311ee7979b - rustc_middle[55db46a3a9e6fd01]::ty::context::tls::with_context_opt::<rustc_middle[55db46a3a9e6fd01]::ty::context::tls::with_opt<rustc_middle[55db46a3a9e6fd01]::util::bug::opt_span_bug_fmt<rustc_span[4312f27e8c783d4a]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x7f311cf14878 - rustc_middle[55db46a3a9e6fd01]::util::bug::span_bug_fmt::<rustc_span[4312f27e8c783d4a]::span_encoding::Span>
16: 0x7f312004476d - <rustc_middle[55db46a3a9e6fd01]::ty::instance::Instance>::expect_resolve
17: 0x7f311d058c56 - rustc_monomorphize[6bc2048e015f6b8e]::collector::items_of_instance
18: 0x7f311ffdb946 - rustc_query_impl[dd57941d79eef654]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dd57941d79eef654]::query_impl::items_of_instance::dynamic_query::{closure#2}::{closure#0}, rustc_middle[55db46a3a9e6fd01]::query::erase::Erased<[u8; 32usize]>>
19: 0x7f311ffda417 - rustc_query_system[fbdf9c15bf535051]::query::plumbing::try_execute_query::<rustc_query_impl[dd57941d79eef654]::DynamicConfig<rustc_query_system[fbdf9c15bf535051]::query::caches::DefaultCache<(rustc_middle[55db46a3a9e6fd01]::ty::instance::Instance, rustc_middle[55db46a3a9e6fd01]::mir::mono::CollectionMode), rustc_middle[55db46a3a9e6fd01]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[dd57941d79eef654]::plumbing::QueryCtxt, true>
20: 0x7f311ffd8ce7 - rustc_query_impl[dd57941d79eef654]::query_impl::items_of_instance::get_query_incr::__rust_end_short_backtrace
21: 0x7f312085ff99 - rustc_monomorphize[6bc2048e015f6b8e]::collector::collect_items_rec::{closure#0}
22: 0x7f31211d2417 - rustc_monomorphize[6bc2048e015f6b8e]::collector::collect_items_rec
23: 0x7f31211d55d4 - rustc_monomorphize[6bc2048e015f6b8e]::collector::collect_items_rec
24: 0x7f31201851e3 - rustc_monomorphize[6bc2048e015f6b8e]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
25: 0x7f312082c4ba - rustc_monomorphize[6bc2048e015f6b8e]::partitioning::collect_and_partition_mono_items
26: 0x7f31211ef616 - rustc_query_impl[dd57941d79eef654]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dd57941d79eef654]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[55db46a3a9e6fd01]::query::erase::Erased<[u8; 24usize]>>
27: 0x7f31211ef5dd - <rustc_query_impl[dd57941d79eef654]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[1f5c4c040b19307]::ops::function::FnOnce<(rustc_middle[55db46a3a9e6fd01]::ty::context::TyCtxt, ())>>::call_once
28: 0x7f31211ee45c - rustc_query_system[fbdf9c15bf535051]::query::plumbing::try_execute_query::<rustc_query_impl[dd57941d79eef654]::DynamicConfig<rustc_query_system[fbdf9c15bf535051]::query::caches::SingleCache<rustc_middle[55db46a3a9e6fd01]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[dd57941d79eef654]::plumbing::QueryCtxt, true>
29: 0x7f31211edf88 - rustc_query_impl[dd57941d79eef654]::query_impl::collect_and_partition_mono_items::get_query_incr::__rust_end_short_backtrace
30: 0x7f312106ce29 - rustc_codegen_ssa[8f1f60f4942dc47f]::base::codegen_crate::<rustc_codegen_llvm[b9ffd0f94873fbe0]::LlvmCodegenBackend>
31: 0x7f312106a8b3 - <rustc_codegen_llvm[b9ffd0f94873fbe0]::LlvmCodegenBackend as rustc_codegen_ssa[8f1f60f4942dc47f]::traits::backend::CodegenBackend>::codegen_crate
32: 0x7f3120e6aa0c - <rustc_interface[414c0bf7369858c6]::queries::Linker>::codegen_and_build_linker
33: 0x7f31210d9b1b - <rustc_interface[414c0bf7369858c6]::passes::create_and_enter_global_ctxt<core[1f5c4c040b19307]::option::Option<rustc_interface[414c0bf7369858c6]::queries::Linker>, rustc_driver_impl[a62c041d93dad5ac]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[1f5c4c040b19307]::ops::function::FnOnce<(&rustc_session[349a198c03ceb088]::session::Session, rustc_middle[55db46a3a9e6fd01]::ty::context::CurrentGcx, alloc[31570ea252afb3e]::sync::Arc<rustc_data_structures[734b602c71f49520]::jobserver::Proxy>, &std[f73caa43acb03b8c]::sync::once_lock::OnceLock<rustc_middle[55db46a3a9e6fd01]::ty::context::GlobalCtxt>, &rustc_data_structures[734b602c71f49520]::sync::worker_local::WorkerLocal<rustc_middle[55db46a3a9e6fd01]::arena::Arena>, &rustc_data_structures[734b602c71f49520]::sync::worker_local::WorkerLocal<rustc_hir[81959f50af77ce73]::Arena>, rustc_driver_impl[a62c041d93dad5ac]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
34: 0x7f3120f22e05 - rustc_interface[414c0bf7369858c6]::interface::run_compiler::<(), rustc_driver_impl[a62c041d93dad5ac]::run_compiler::{closure#0}>::{closure#1}
35: 0x7f3120edc914 - std[f73caa43acb03b8c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[414c0bf7369858c6]::util::run_in_thread_with_globals<rustc_interface[414c0bf7369858c6]::util::run_in_thread_pool_with_globals<rustc_interface[414c0bf7369858c6]::interface::run_compiler<(), rustc_driver_impl[a62c041d93dad5ac]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
36: 0x7f3120edc61e - <<std[f73caa43acb03b8c]::thread::Builder>::spawn_unchecked_<rustc_interface[414c0bf7369858c6]::util::run_in_thread_with_globals<rustc_interface[414c0bf7369858c6]::util::run_in_thread_pool_with_globals<rustc_interface[414c0bf7369858c6]::interface::run_compiler<(), rustc_driver_impl[a62c041d93dad5ac]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[1f5c4c040b19307]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
37: 0x7f3120ee242f - <std[f73caa43acb03b8c]::sys::thread::unix::Thread>::new::thread_start
38: 0x7f311aa9caa4 - start_thread
at ./nptl/pthread_create.c:447:8
39: 0x7f311ab29c6c - clone3
at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
40: 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 `/home/lcnr/test1/rustc-ice-2025-12-01T12_13_29-2044879.txt` to your bug report
note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [items_of_instance] collecting items used by `foo::<&u32>`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the provided reproducer and inspect compiler/rustc_middle/src/ty/instance.rs around line 579, then follow the items_of_instance query into rustc_monomorphize. Confirm the ambiguity during monomorphization and the resulting ICE. Done means the example no longer panics and receives an appropriate compiler result or diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100