Skip to content

Commit

Permalink
Don't check self type twice
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Feb 12, 2021
1 parent bc5f4c4 commit 0cc35f5
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ where
// Before doing expensive operations like entering an inference context, do
// a quick check via fast_reject to tell if the impl headers could possibly
// unify.
let impl1_self = tcx.type_of(impl1_def_id);
let impl2_self = tcx.type_of(impl2_def_id);
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);

Expand All @@ -80,14 +78,13 @@ where
.iter()
.flat_map(|tref| tref.substs.types())
.zip(impl2_ref.iter().flat_map(|tref| tref.substs.types()))
.chain(iter::once((impl1_self, impl2_self)))
.any(|(ty1, ty2)| {
let t1 = fast_reject::simplify_type(tcx, ty1, false);
let t2 = fast_reject::simplify_type(tcx, ty2, false);
if let (Some(t1), Some(t2)) = (t1, t2) {
// Simplified successfully
// Types cannot unify if they differ in their reference mutability or simplify to different types
t1 != t2 || ty1.ref_mutability() != ty2.ref_mutability()
t1 != t2 || ty1.ref_mutability() != ty2.ref_mutability()
} else {
// Types might unify
false
Expand Down

0 comments on commit 0cc35f5

Please sign in to comment.