Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use non-intercrate SelectionContext for normalization in coherence::with_fresh_ty_vars #86360

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/coherence/issue-85898.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// check-pass

use std::ops::Range;

struct Foo;

impl From<<Range<usize> as Iterator>::Item> for Foo {
fn from(_: <Range<usize> as Iterator>::Item) -> Foo {
Foo
}
}

fn main() {}