@@ -7,6 +7,7 @@ use rustc_infer::infer::TyCtxtInferExt as _;
7
7
use rustc_infer:: traits:: { Obligation , ObligationCause } ;
8
8
use rustc_middle:: traits:: DefiningAnchor ;
9
9
use rustc_middle:: ty:: visit:: TypeVisitableExt ;
10
+ use rustc_middle:: ty:: RegionVid ;
10
11
use rustc_middle:: ty:: { self , OpaqueHiddenType , OpaqueTypeKey , Ty , TyCtxt , TypeFoldable } ;
11
12
use rustc_middle:: ty:: { GenericArgKind , GenericArgs } ;
12
13
use rustc_span:: Span ;
@@ -26,13 +27,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
26
27
. find_map ( |lb| self . eval_equal ( vid, lb) . then_some ( self . definitions [ lb] . external_name ?) )
27
28
}
28
29
29
- fn gen_arg_to_name ( & self , arg : ty:: GenericArg < ' tcx > ) -> Option < ty :: Region < ' tcx > > {
30
+ fn generic_arg_to_region ( & self , arg : ty:: GenericArg < ' tcx > ) -> Option < RegionVid > {
30
31
let region = arg. as_region ( ) ?;
31
32
32
33
if let ty:: RePlaceholder ( ..) = region. kind ( ) {
33
- return None ;
34
+ None
35
+ } else {
36
+ Some ( self . to_region_vid ( region) )
34
37
}
35
- self . universal_name ( self . to_region_vid ( region) )
36
38
}
37
39
38
40
/// Check that all opaque types have the same region parameters if they have the same
@@ -54,19 +56,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
54
56
}
55
57
trace ! ( ?a, ?b) ;
56
58
for ( a, b) in a. args . iter ( ) . zip ( b. args ) {
57
- if a. as_region ( ) . is_none ( ) {
58
- break ;
59
- }
60
- let a = self . gen_arg_to_name ( a) . unwrap ( ) ;
61
- let b = self . gen_arg_to_name ( b) . unwrap ( ) ;
62
59
trace ! ( ?a, ?b) ;
63
- if a == b {
60
+ let Some ( r1) = self . generic_arg_to_region ( a) else {
61
+ continue ;
62
+ } ;
63
+ let r2 = self . generic_arg_to_region ( b) . unwrap ( ) ;
64
+ if self . eval_equal ( r1, r2) {
64
65
continue ;
65
66
}
66
67
67
68
infcx. tcx . sess . emit_err ( LifetimeMismatchOpaqueParam {
68
- arg : a . into ( ) ,
69
- prev : b . into ( ) ,
69
+ arg : self . universal_name ( r1 ) . unwrap ( ) . into ( ) ,
70
+ prev : self . universal_name ( r2 ) . unwrap ( ) . into ( ) ,
70
71
span : a_ty. span ,
71
72
prev_span : b_ty. span ,
72
73
} ) ;
0 commit comments