diff options
| author | bors <bors@rust-lang.org> | 2019-07-18 13:09:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-18 13:09:01 +0000 |
| commit | 4ed008a420d725d9543d14acd0f7078a77b8bd16 (patch) | |
| tree | 49491d2d792fce60e1b96e192ac80893d894c2f6 /src | |
| parent | 21d5b8bf0c26e3ee4c270ce5527df66b1af56513 (diff) | |
| parent | 745c76d657ebbe29265100e5381f8bf326c54567 (diff) | |
| download | rust-4ed008a420d725d9543d14acd0f7078a77b8bd16.tar.gz rust-4ed008a420d725d9543d14acd0f7078a77b8bd16.zip | |
Auto merge of #62682 - alessandrod:issue-58375, r=eddyb
Normalize type parameters in create_mono_items_for_default_impls. Fix for https://github.com/rust-lang/rust/issues/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 https://github.com/rust-lang/rust/issues/58375#issuecomment-509156977 for more context.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/monomorphize/collector.rs | 8 | ||||
| -rw-r--r-- | src/test/run-pass/issue-58375-monomorphize-default-impls.rs | 23 |
2 files changed, 29 insertions, 2 deletions
diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 6e9390f7750..ee0f9119544 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 00000000000..6730217626f --- /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<<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> { +} |
