diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 6e9390f77508b..ee0f9119544bf 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -1143,6 +1143,11 @@ fn create_mono_items_for_default_impls<'tcx>( def_id_to_string(tcx, impl_def_id)); if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) { + let param_env = ty::ParamEnv::reveal_all(); + let trait_ref = tcx.normalize_erasing_regions( + param_env, + trait_ref, + ); let overridden_methods: FxHashSet<_> = impl_item_refs.iter() .map(|iiref| iiref.ident.modern()) @@ -1165,9 +1170,8 @@ fn create_mono_items_for_default_impls<'tcx>( } } }); - let instance = ty::Instance::resolve(tcx, - ty::ParamEnv::reveal_all(), + param_env, method.def_id, substs).unwrap(); diff --git a/src/test/run-pass/issue-58375-monomorphize-default-impls.rs b/src/test/run-pass/issue-58375-monomorphize-default-impls.rs new file mode 100644 index 0000000000000..6730217626f3e --- /dev/null +++ b/src/test/run-pass/issue-58375-monomorphize-default-impls.rs @@ -0,0 +1,23 @@ +// Make sure that the mono-item collector does not crash when trying to +// instantiate a default impl for DecodeUtf16<::Item> +// See https://github.com/rust-lang/rust/issues/58375 +// compile-flags:-C link-dead-code + +#![crate_type = "rlib"] + +pub struct DecodeUtf16(I); + +pub trait Arbitrary { + fn arbitrary() {} +} + +pub trait A { + type Item; +} + +impl A for u8 { + type Item = char; +} + +impl Arbitrary for DecodeUtf16<::Item> { +}