@@ -46,7 +46,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
46
46
let tcx = infcx. tcx ;
47
47
// We need to eagerly map all regions to NLL vars here, as we need to make sure we've
48
48
// introduced nll vars for all used placeholders.
49
- let opaque_types = opaque_types
49
+ let mut opaque_types = opaque_types
50
50
. into_iter ( )
51
51
. map ( |entry| {
52
52
fold_regions ( tcx, infcx. resolve_vars_if_possible ( entry) , |r, _| {
@@ -84,6 +84,14 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
84
84
let mut scc_values =
85
85
RegionValues :: new ( location_map, universal_regions. len ( ) , placeholder_indices) ;
86
86
scc_values. propagate_constraints ( & constraint_sccs) ;
87
+ for entry in & mut opaque_types {
88
+ // Map all opaque types to their SCC representatives.
89
+ * entry = fold_regions ( tcx, * entry, |r, _| {
90
+ let scc = constraint_sccs. scc ( r. as_var ( ) ) ;
91
+ let vid = constraint_sccs. annotation ( scc) . representative ;
92
+ Region :: new_var ( tcx, vid)
93
+ } )
94
+ }
87
95
88
96
let mut unexpected_hidden_regions = Vec :: new ( ) ;
89
97
@@ -99,8 +107,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
99
107
let mut arg_regions = vec ! [ ( universal_regions. fr_static, tcx. lifetimes. re_static) ] ;
100
108
for ( _idx, captured_arg) in opaque_type_key. iter_captured_args ( tcx) {
101
109
if let Some ( region) = captured_arg. as_region ( ) {
102
- let scc = constraint_sccs. scc ( region. as_var ( ) ) ;
103
- let vid = constraint_sccs. annotation ( scc) . representative ;
110
+ let vid = region. as_var ( ) ;
104
111
if matches ! ( definitions[ vid] . origin, NllRegionVariableOrigin :: FreeRegion )
105
112
&& !matches ! (
106
113
universal_regions. region_classification( vid) ,
@@ -117,8 +124,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
117
124
debug ! ( ?opaque_type_key, ?hidden_type, "check defining use" ) ;
118
125
119
126
let opaque_type_key = opaque_type_key. fold_captured_lifetime_args ( tcx, |region| {
120
- let scc = constraint_sccs. scc ( region. as_var ( ) ) ;
121
- let vid = constraint_sccs. annotation ( scc) . representative ;
127
+ let vid = region. as_var ( ) ;
122
128
if matches ! ( definitions[ vid] . origin, NllRegionVariableOrigin :: FreeRegion ) {
123
129
definitions[ vid] . external_name . unwrap ( )
124
130
} else {
@@ -174,6 +180,15 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
174
180
}
175
181
176
182
for & ( key, hidden_type) in & opaque_types {
183
+ if !tcx. use_typing_mode_borrowck ( ) {
184
+ if let ty:: Alias ( ty:: Opaque , alias_ty) = hidden_type. ty . kind ( )
185
+ && alias_ty. def_id == key. def_id . to_def_id ( )
186
+ && alias_ty. args == key. args
187
+ {
188
+ continue ;
189
+ }
190
+ }
191
+
177
192
let Some ( expected) = root_cx. get_concrete_opaque_type ( key. def_id ) else {
178
193
let guar =
179
194
tcx. dcx ( ) . span_err ( hidden_type. span , "non-defining use in the defining scope" ) ;
@@ -257,10 +272,9 @@ struct OpaqueHiddenTypeFolder<'a, 'tcx> {
257
272
258
273
impl < ' tcx > OpaqueHiddenTypeFolder < ' _ , ' tcx > {
259
274
#[ instrument( level = "debug" , skip( self ) ) ]
260
- fn apply_member_constraint ( & mut self , r : RegionVid ) -> Option < Region < ' tcx > > {
261
- let member = self . constraint_sccs . scc ( r) ;
262
- let r = self . constraint_sccs . annotation ( member) . representative ;
263
- if let Some ( ( _, reg) ) = self . arg_regions . iter ( ) . copied ( ) . find ( |& ( vid, _) | vid == r) {
275
+ fn apply_member_constraint ( & mut self , member_vid : RegionVid ) -> Option < Region < ' tcx > > {
276
+ let member = self . constraint_sccs . scc ( member_vid) ;
277
+ if let Some ( ( _, reg) ) = self . arg_regions . iter ( ) . copied ( ) . find ( |& ( vid, _) | vid == member_vid) {
264
278
debug ! ( "member equal to arg" ) ;
265
279
return Some ( reg) ;
266
280
}
0 commit comments