File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
rustc_trait_selection/src/traits Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -1837,6 +1837,15 @@ impl<'tcx> TyS<'tcx> {
18371837 )
18381838 }
18391839
1840+ /// Get the mutability of the reference or `None` when not a reference
1841+ #[ inline]
1842+ pub fn ref_mutability ( & self ) -> Option < hir:: Mutability > {
1843+ match self . kind ( ) {
1844+ Ref ( _, _, mutability) => Some ( * mutability) ,
1845+ _ => None ,
1846+ }
1847+ }
1848+
18401849 #[ inline]
18411850 pub fn is_unsafe_ptr ( & self ) -> bool {
18421851 matches ! ( self . kind( ) , RawPtr ( _) )
Original file line number Diff line number Diff line change @@ -75,18 +75,19 @@ where
7575 let impl1_ref = tcx. impl_trait_ref ( impl1_def_id) ;
7676 let impl2_ref = tcx. impl_trait_ref ( impl2_def_id) ;
7777
78- // Check if any of the input types definitely mismatch .
78+ // Check if any of the input types definitely do not unify .
7979 if impl1_ref
8080 . iter ( )
8181 . flat_map ( |tref| tref. substs . types ( ) )
8282 . zip ( impl2_ref. iter ( ) . flat_map ( |tref| tref. substs . types ( ) ) )
8383 . chain ( iter:: once ( ( impl1_self, impl2_self) ) )
8484 . any ( |( ty1, ty2) | {
85- let ty1 = fast_reject:: simplify_type ( tcx, ty1, false ) ;
86- let ty2 = fast_reject:: simplify_type ( tcx, ty2, false ) ;
87- if let ( Some ( ty1 ) , Some ( ty2 ) ) = ( ty1 , ty2 ) {
85+ let t1 = fast_reject:: simplify_type ( tcx, ty1, false ) ;
86+ let t2 = fast_reject:: simplify_type ( tcx, ty2, false ) ;
87+ if let ( Some ( t1 ) , Some ( t2 ) ) = ( t1 , t2 ) {
8888 // Simplified successfully
89- ty1 != ty2
89+ // Types cannot unify if they differ in their reference mutability or simplify to different types
90+ ty1. ref_mutability ( ) != ty2. ref_mutability ( ) || t1 != t2
9091 } else {
9192 // Types might unify
9293 false
You can’t perform that action at this time.
0 commit comments