Closed
Description
auto-reduced (treereduce-rust):
pub trait TraitA {
type AssocB = T;
}
pub trait TraitB {
type AssocB;
}
pub trait MethodTrait {
fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a>;
}
impl<T: TraitB> MethodTrait for T
where
<T::AssocB as TraitA>::AssocB: TraitA,
{
// }
fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> {}
}
original code
original:
pub struct Wrapper<T>(T);
struct Struct;
pub trait TraitA {
type AssocB = T;
}
pub trait TraitB {
type AssocB;
}
pub fn helper(v: impl MethodTrait) {
// monomorphization instantiates something it then normalizes to:
//
// Closure(
// DefId(0:27 ~ unnamed_1[00e7]::{impl#0}::method::{closure#0}),
// [
// must be a method (through Self), the example below doesn't work (as a standalone function)
// i16,
// Binder {
// value: extern "RustCall" fn((&'^0 (),)) -> Alias(Projection, AliasTy { args: [StructX, '^0], def_id: DefId(0:10 ~ unnamed_1[00e7]::TraitA::AssocA), .. }),
// bound_vars: [Region(BrAnon)]
// },
// ()
// ]
// ),
//
// This should be completely normalized but isn't.
// so, normalizing again gives (StructX is inserted) for
// Alias(Projection, AliasTy { args: [StructX, '^0], def_id: DefId(0:10 ~ unnamed_1[00e7]::TraitA::AssocA), .. })
//
// Closure(
// DefId(0:27 ~ unnamed_1[00e7]::{impl#0}::method::{closure#0}),
pub struct Wrapper<T>(T);
// Wrapper1<StructX>,
// i16,
// Binder {
// value: extern "RustCall" fn((&'^0 (),)) -> StructX, bound_vars: [Region(BrAnon)]
// },
// ()
// ]
// ).
let _local_that_causes_ice = v.method();
}
pub fn main() {
helper(WrapperT::AssocB as TraitA);
}
pub trait MethodTrait {
type Assoc<'a>;
fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a>;
}
impl<T: TraitB> MethodTrait for T
where
<T::AssocB as TraitA>::AssocB: TraitA,
{
type Assoc<'a> = <T::AssocB as TraitA>::AssocA<'t>;
// must be a method (through Self), the example below doesn't work (as a standalone function)
// fn helper2<M: MethodTrait>(_v: M) -> impl for<'a> FnMut(&'a ()) -> M::Assoc<'a> {
// move |_| loop {}
// }
fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> {
move |_| loop {}
}
}
impl<T, B> TraitB for Wrapper<B>
where
B: TraitB<AssocB = T>,
{
type AssocB = T;
}
impl TraitB for Struct {
type AssocB = Struct;
}
impl TraitA for Struct {
type AssocA<'t> = Self;
}
Version information
rustc 1.85.0-nightly (96e51d948 2024-12-04)
binary: rustc
commit-hash: 96e51d9482405e400dec53750f3b263d45784ada
commit-date: 2024-12-04
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5
Possibly related line of code:
rust/compiler/rustc_trait_selection/src/traits/normalize.rs
Lines 63 to 75 in 96e51d9
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc
Program output
error[E0412]: cannot find type `T` in this scope
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:2:19
|
2 | type AssocB = T;
| ^ not found in this scope
error[E0658]: associated type defaults are unstable
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:2:5
|
2 | type AssocB = T;
| ^^^^^^^^^^^^^^^^
|
= note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
= note: this compiler was built on 2024-12-04; consider upgrading it if it is out of date
error[E0601]: `main` function not found in crate `mvce`
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:18:2
|
18 | }
| ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs`
error[E0277]: the trait bound `<T as TraitB>::AssocB: TraitA` is not satisfied
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:17:5
|
17 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TraitA` is not implemented for `<T as TraitB>::AssocB`
|
help: consider further restricting the associated type
|
17 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> where <T as TraitB>::AssocB: TraitA {}
| +++++++++++++++++++++++++++++++++++
error[E0220]: associated type `Assoc` not found for `Self`
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:9:60
|
9 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a>;
| ^^^^^ associated type `Assoc` not found
error[E0220]: associated type `Assoc` not found for `Self`
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:17:60
|
17 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> {}
| ^^^^^ associated type `Assoc` not found
error[E0277]: the trait bound `<T as TraitB>::AssocB: TraitA` is not satisfied
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:17:24
|
17 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TraitA` is not implemented for `<T as TraitB>::AssocB`
|
help: consider further restricting the associated type
|
17 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> where <T as TraitB>::AssocB: TraitA {}
| +++++++++++++++++++++++++++++++++++
error[E0277]: the trait bound `<T as TraitB>::AssocB: TraitA` is not satisfied
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:12:1
|
12 | / impl<T: TraitB> MethodTrait for T
13 | | where
14 | | <T::AssocB as TraitA>::AssocB: TraitA,
| |__________________________________________^ the trait `TraitA` is not implemented for `<T as TraitB>::AssocB`
|
help: consider further restricting the associated type
|
14 | <T::AssocB as TraitA>::AssocB: TraitA, <T as TraitB>::AssocB: TraitA
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0277]: the trait bound `<T as TraitB>::AssocB: TraitA` is not satisfied
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:12:1
|
12 | / impl<T: TraitB> MethodTrait for T
13 | | where
14 | | <T::AssocB as TraitA>::AssocB: TraitA,
15 | | {
16 | | // }
17 | | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> {}
18 | | }
| |_^ the trait `TraitA` is not implemented for `<T as TraitB>::AssocB`
|
help: consider further restricting the associated type
|
14 | <T::AssocB as TraitA>::AssocB: TraitA, <T as TraitB>::AssocB: TraitA
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0277]: the trait bound `<T as TraitB>::AssocB: TraitA` is not satisfied
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:17:24
|
17 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TraitA` is not implemented for `<T as TraitB>::AssocB`
|
help: consider further restricting the associated type
|
14 | <T::AssocB as TraitA>::AssocB: TraitA, <T as TraitB>::AssocB: TraitA
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: internal compiler error: compiler/rustc_trait_selection/src/traits/normalize.rs:69:17: deeply_normalize should not be called with pending obligations: [
Obligation(predicate=Binder { value: TraitPredicate(<_ as TraitA>, polarity:Positive), bound_vars: [] }, depth=1),
]
--> /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:9:24
|
9 | fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/normalize.rs:69:17:
Box<dyn Any>
stack backtrace:
0: 0x7f404913b59a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h7d5d2ef8548ea862
1: 0x7f4049813e26 - core::fmt::write::hc7f1fcf2cd4d0b24
2: 0x7f404a7f4751 - std::io::Write::write_fmt::h5dae3cf637b1b14c
3: 0x7f404913b3f2 - std::sys::backtrace::BacktraceLock::print::h603d5439a4d48e27
4: 0x7f404913d91a - std::panicking::default_hook::{{closure}}::h317c28a5ebbd850f
5: 0x7f404913d763 - std::panicking::default_hook::h0f4f8ead395a2965
6: 0x7f40482bbb88 - std[b886acd6fb60b0a8]::panicking::update_hook::<alloc[e4e71b9a99f0d22f]::boxed::Box<rustc_driver_impl[c07627fafa57377e]::install_ice_hook::{closure#0}>>::{closure#0}
7: 0x7f404913e0d8 - std::panicking::rust_panic_with_hook::he1329bac1e03080f
8: 0x7f40482f10a1 - std[b886acd6fb60b0a8]::panicking::begin_panic::<rustc_errors[c4cb0ec99f59abcb]::ExplicitBug>::{closure#0}
9: 0x7f40482e6246 - std[b886acd6fb60b0a8]::sys::backtrace::__rust_end_short_backtrace::<std[b886acd6fb60b0a8]::panicking::begin_panic<rustc_errors[c4cb0ec99f59abcb]::ExplicitBug>::{closure#0}, !>
10: 0x7f40482e2d29 - std[b886acd6fb60b0a8]::panicking::begin_panic::<rustc_errors[c4cb0ec99f59abcb]::ExplicitBug>
11: 0x7f40482fb041 - <rustc_errors[c4cb0ec99f59abcb]::diagnostic::BugAbort as rustc_errors[c4cb0ec99f59abcb]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
12: 0x7f404884f8bc - <rustc_errors[c4cb0ec99f59abcb]::DiagCtxtHandle>::span_bug::<rustc_span[5535563d387a33e2]::span_encoding::Span, alloc[e4e71b9a99f0d22f]::string::String>
13: 0x7f40488e2227 - rustc_middle[67be29f945e3ecf0]::util::bug::opt_span_bug_fmt::<rustc_span[5535563d387a33e2]::span_encoding::Span>::{closure#0}
14: 0x7f40488ca74a - rustc_middle[67be29f945e3ecf0]::ty::context::tls::with_opt::<rustc_middle[67be29f945e3ecf0]::util::bug::opt_span_bug_fmt<rustc_span[5535563d387a33e2]::span_encoding::Span>::{closure#0}, !>::{closure#0}
15: 0x7f40488ca5db - rustc_middle[67be29f945e3ecf0]::ty::context::tls::with_context_opt::<rustc_middle[67be29f945e3ecf0]::ty::context::tls::with_opt<rustc_middle[67be29f945e3ecf0]::util::bug::opt_span_bug_fmt<rustc_span[5535563d387a33e2]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
16: 0x7f404738acf7 - rustc_middle[67be29f945e3ecf0]::util::bug::span_bug_fmt::<rustc_span[5535563d387a33e2]::span_encoding::Span>
17: 0x7f4049b83090 - <rustc_trait_selection[8b7799daf48e843f]::traits::engine::ObligationCtxt<rustc_trait_selection[8b7799daf48e843f]::traits::FulfillmentError>>::assumed_wf_types_and_report_errors
18: 0x7f404a004b26 - rustc_hir_analysis[e6847c1464713c9a]::check::compare_impl_item::check_type_bounds
19: 0x7f404a22849d - rustc_hir_analysis[e6847c1464713c9a]::check::compare_impl_item::compare_impl_item
20: 0x7f404a225dd1 - rustc_query_impl[d2f5d943c2280edc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2f5d943c2280edc]::query_impl::compare_impl_item::dynamic_query::{closure#2}::{closure#0}, rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>>
21: 0x7f404a1cf730 - rustc_query_system[254f9b8bf6b2b5ec]::query::plumbing::try_execute_query::<rustc_query_impl[d2f5d943c2280edc]::DynamicConfig<rustc_data_structures[d98f95e3c765a7d0]::vec_cache::VecCache<rustc_span[5535563d387a33e2]::def_id::LocalDefId, rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[254f9b8bf6b2b5ec]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d2f5d943c2280edc]::plumbing::QueryCtxt, false>
22: 0x7f404a1cf201 - rustc_query_impl[d2f5d943c2280edc]::query_impl::compare_impl_item::get_query_non_incr::__rust_end_short_backtrace
23: 0x7f4045dbbf66 - rustc_hir_analysis[e6847c1464713c9a]::check::check::check_item_type
24: 0x7f40471754b4 - rustc_hir_analysis[e6847c1464713c9a]::check::wfcheck::check_well_formed
25: 0x7f404a1cf487 - rustc_query_impl[d2f5d943c2280edc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2f5d943c2280edc]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>>
26: 0x7f404a1cf748 - rustc_query_system[254f9b8bf6b2b5ec]::query::plumbing::try_execute_query::<rustc_query_impl[d2f5d943c2280edc]::DynamicConfig<rustc_data_structures[d98f95e3c765a7d0]::vec_cache::VecCache<rustc_span[5535563d387a33e2]::def_id::LocalDefId, rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[254f9b8bf6b2b5ec]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d2f5d943c2280edc]::plumbing::QueryCtxt, false>
27: 0x7f404a1cf462 - rustc_query_impl[d2f5d943c2280edc]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
28: 0x7f404a1d01ec - rustc_hir_analysis[e6847c1464713c9a]::check::wfcheck::check_mod_type_wf
29: 0x7f404a1d000b - rustc_query_impl[d2f5d943c2280edc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2f5d943c2280edc]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>>
30: 0x7f404a62b784 - rustc_query_system[254f9b8bf6b2b5ec]::query::plumbing::try_execute_query::<rustc_query_impl[d2f5d943c2280edc]::DynamicConfig<rustc_query_system[254f9b8bf6b2b5ec]::query::caches::DefaultCache<rustc_span[5535563d387a33e2]::def_id::LocalModDefId, rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d2f5d943c2280edc]::plumbing::QueryCtxt, false>
31: 0x7f404a62b518 - rustc_query_impl[d2f5d943c2280edc]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
32: 0x7f4049ac9adc - rustc_hir_analysis[e6847c1464713c9a]::check_crate
33: 0x7f404a13a57c - rustc_interface[14bb8bd49e3c2011]::passes::run_required_analyses
34: 0x7f404a3cfd5e - rustc_interface[14bb8bd49e3c2011]::passes::analysis
35: 0x7f404a3cfd2f - rustc_query_impl[d2f5d943c2280edc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2f5d943c2280edc]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>>
36: 0x7f404a7bc37a - rustc_query_system[254f9b8bf6b2b5ec]::query::plumbing::try_execute_query::<rustc_query_impl[d2f5d943c2280edc]::DynamicConfig<rustc_query_system[254f9b8bf6b2b5ec]::query::caches::SingleCache<rustc_middle[67be29f945e3ecf0]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d2f5d943c2280edc]::plumbing::QueryCtxt, false>
37: 0x7f404a7bc04e - rustc_query_impl[d2f5d943c2280edc]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
38: 0x7f404a88c239 - rustc_interface[14bb8bd49e3c2011]::interface::run_compiler::<core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>, rustc_driver_impl[c07627fafa57377e]::run_compiler::{closure#0}>::{closure#1}
39: 0x7f404a71a3c7 - std[b886acd6fb60b0a8]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[14bb8bd49e3c2011]::util::run_in_thread_with_globals<rustc_interface[14bb8bd49e3c2011]::util::run_in_thread_pool_with_globals<rustc_interface[14bb8bd49e3c2011]::interface::run_compiler<core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>, rustc_driver_impl[c07627fafa57377e]::run_compiler::{closure#0}>::{closure#1}, core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>>::{closure#0}, core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>>
40: 0x7f404a71a062 - <<std[b886acd6fb60b0a8]::thread::Builder>::spawn_unchecked_<rustc_interface[14bb8bd49e3c2011]::util::run_in_thread_with_globals<rustc_interface[14bb8bd49e3c2011]::util::run_in_thread_pool_with_globals<rustc_interface[14bb8bd49e3c2011]::interface::run_compiler<core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>, rustc_driver_impl[c07627fafa57377e]::run_compiler::{closure#0}>::{closure#1}, core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>>::{closure#0}, core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dd48f16c736a3ea3]::result::Result<(), rustc_span[5535563d387a33e2]::ErrorGuaranteed>>::{closure#1} as core[dd48f16c736a3ea3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
41: 0x7f404a7197ab - std::sys::pal::unix::thread::Thread::new::thread_start::h7cc6adb00f817196
42: 0x7f4044a6a39d - <unknown>
43: 0x7f4044aef49c - <unknown>
44: 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: rustc 1.85.0-nightly (96e51d948 2024-12-04) running on x86_64-unknown-linux-gnu
query stack during panic:
#0 [compare_impl_item] checking assoc item `<impl at /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:12:1: 14:43>::{synthetic#0}` is compatible with trait definition
#1 [check_well_formed] checking that `<impl at /tmp/icemaker_global_tempdir.oqycY4Xka193/rustc_testrunner_tmpdir_reporting.FxaXXxPy3JEq/mvce.rs:12:1: 14:43>` is well-formed
end of query stack
error: aborting due to 11 previous errors
Some errors have detailed explanations: E0220, E0277, E0412, E0601, E0658.
For more information about an error, try `rustc --explain E0220`.
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.