Skip to content

Commit 4ed008a

Browse files
committed
Auto merge of #62682 - alessandrod:issue-58375, r=eddyb
Normalize type parameters in create_mono_items_for_default_impls. Fix for #58375. I've added a test in `src/tests/run-pass` to reproduce the bug, not sure that's the best place for it. See #58375 (comment) for more context.
2 parents 21d5b8b + 745c76d commit 4ed008a

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/librustc_mir/monomorphize/collector.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,11 @@ fn create_mono_items_for_default_impls<'tcx>(
11431143
def_id_to_string(tcx, impl_def_id));
11441144

11451145
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) {
1146+
let param_env = ty::ParamEnv::reveal_all();
1147+
let trait_ref = tcx.normalize_erasing_regions(
1148+
param_env,
1149+
trait_ref,
1150+
);
11461151
let overridden_methods: FxHashSet<_> =
11471152
impl_item_refs.iter()
11481153
.map(|iiref| iiref.ident.modern())
@@ -1165,9 +1170,8 @@ fn create_mono_items_for_default_impls<'tcx>(
11651170
}
11661171
}
11671172
});
1168-
11691173
let instance = ty::Instance::resolve(tcx,
1170-
ty::ParamEnv::reveal_all(),
1174+
param_env,
11711175
method.def_id,
11721176
substs).unwrap();
11731177

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Make sure that the mono-item collector does not crash when trying to
2+
// instantiate a default impl for DecodeUtf16<<u8 as A>::Item>
3+
// See https://github.com/rust-lang/rust/issues/58375
4+
// compile-flags:-C link-dead-code
5+
6+
#![crate_type = "rlib"]
7+
8+
pub struct DecodeUtf16<I>(I);
9+
10+
pub trait Arbitrary {
11+
fn arbitrary() {}
12+
}
13+
14+
pub trait A {
15+
type Item;
16+
}
17+
18+
impl A for u8 {
19+
type Item = char;
20+
}
21+
22+
impl Arbitrary for DecodeUtf16<<u8 as A>::Item> {
23+
}

0 commit comments

Comments
 (0)