Skip to content

Commit 8fd515c

Browse files
committed
use non-intercrate SelectionContext for normalization in coherence::with_fresh_ty_vars
1 parent 2336406 commit 8fd515c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
129129
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates,
130130
};
131131

132+
// We need a new SelectionContext for the normalization, since `selcx`
133+
// has its intercrate flag set, which causes all foreign types that occur
134+
// in the normalization of header to fail the orphan check.
135+
let mut new_selcx = SelectionContext::new(selcx.infcx());
136+
132137
let Normalized { value: mut header, obligations } =
133-
traits::normalize(selcx, param_env, ObligationCause::dummy(), header);
138+
traits::normalize(&mut new_selcx, param_env, ObligationCause::dummy(), header);
134139

135140
header.predicates.extend(obligations.into_iter().map(|o| o.predicate));
136141
header

src/test/ui/coherence/issue-85898.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
3+
use std::ops::Range;
4+
5+
struct Foo;
6+
7+
impl From<<Range<usize> as Iterator>::Item> for Foo {
8+
fn from(_: <Range<usize> as Iterator>::Item) -> Foo {
9+
Foo
10+
}
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)