diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 9bb4af16a8f53..c0660e30072b2 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -129,8 +129,13 @@ fn with_fresh_ty_vars<'cx, 'tcx>( predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates, }; + // We need a new SelectionContext for the normalization, since `selcx` + // has its intercrate flag set, which causes all foreign types that occur + // in the normalization of header to fail the orphan check. + let mut new_selcx = SelectionContext::new(selcx.infcx()); + let Normalized { value: mut header, obligations } = - traits::normalize(selcx, param_env, ObligationCause::dummy(), header); + traits::normalize(&mut new_selcx, param_env, ObligationCause::dummy(), header); header.predicates.extend(obligations.into_iter().map(|o| o.predicate)); header diff --git a/src/test/ui/coherence/issue-85898.rs b/src/test/ui/coherence/issue-85898.rs new file mode 100644 index 0000000000000..fb3c8d705fe9e --- /dev/null +++ b/src/test/ui/coherence/issue-85898.rs @@ -0,0 +1,13 @@ +// check-pass + +use std::ops::Range; + +struct Foo; + +impl From< as Iterator>::Item> for Foo { + fn from(_: as Iterator>::Item) -> Foo { + Foo + } +} + +fn main() {}