Skip to content

Commit

Permalink
Auto merge of #62682 - alessandrod:issue-58375, r=eddyb
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jul 18, 2019
2 parents 21d5b8b + 745c76d commit 4ed008a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();

Expand Down
23 changes: 23 additions & 0 deletions src/test/run-pass/issue-58375-monomorphize-default-impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Make sure that the mono-item collector does not crash when trying to
// instantiate a default impl for DecodeUtf16<<u8 as A>::Item>
// See https://github.com/rust-lang/rust/issues/58375
// compile-flags:-C link-dead-code

#![crate_type = "rlib"]

pub struct DecodeUtf16<I>(I);

pub trait Arbitrary {
fn arbitrary() {}
}

pub trait A {
type Item;
}

impl A for u8 {
type Item = char;
}

impl Arbitrary for DecodeUtf16<<u8 as A>::Item> {
}

0 comments on commit 4ed008a

Please sign in to comment.