@@ -24,15 +24,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
24
24
cause,
25
25
values : ValuePairs :: TraitRefs ( ExpectedFound { expected, found } ) ,
26
26
} ) ,
27
- ty:: RePlaceholder ( sub_placeholder ) ,
27
+ sub_placeholder @ ty:: RePlaceholder ( _ ) ,
28
28
_,
29
- ty:: RePlaceholder ( sup_placeholder ) ,
29
+ sup_placeholder @ ty:: RePlaceholder ( _ ) ,
30
30
) ) => if expected. def_id == found. def_id {
31
31
return Some ( self . try_report_placeholders_trait (
32
- Some ( * vid) ,
32
+ Some ( self . tcx . mk_region ( ty :: ReVar ( * vid) ) ) ,
33
33
cause,
34
- Some ( * sub_placeholder) ,
35
- Some ( * sup_placeholder) ,
34
+ Some ( sub_placeholder) ,
35
+ Some ( sup_placeholder) ,
36
36
expected. def_id ,
37
37
expected. substs ,
38
38
found. substs ,
@@ -48,14 +48,14 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
48
48
cause,
49
49
values : ValuePairs :: TraitRefs ( ExpectedFound { expected, found } ) ,
50
50
} ) ,
51
- ty:: RePlaceholder ( sub_placeholder ) ,
51
+ sub_placeholder @ ty:: RePlaceholder ( _ ) ,
52
52
_,
53
53
_,
54
54
) ) => if expected. def_id == found. def_id {
55
55
return Some ( self . try_report_placeholders_trait (
56
- Some ( * vid) ,
56
+ Some ( self . tcx . mk_region ( ty :: ReVar ( * vid) ) ) ,
57
57
cause,
58
- Some ( * sub_placeholder) ,
58
+ Some ( sub_placeholder) ,
59
59
None ,
60
60
expected. def_id ,
61
61
expected. substs ,
@@ -74,10 +74,10 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
74
74
} ) ,
75
75
_,
76
76
_,
77
- ty:: RePlaceholder ( sup_placeholder ) ,
77
+ sup_placeholder @ ty:: RePlaceholder ( _ ) ,
78
78
) ) => if expected. def_id == found. def_id {
79
79
return Some ( self . try_report_placeholders_trait (
80
- Some ( * vid) ,
80
+ Some ( self . tcx . mk_region ( ty :: ReVar ( * vid) ) ) ,
81
81
cause,
82
82
None ,
83
83
Some ( * sup_placeholder) ,
@@ -106,10 +106,10 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
106
106
// = note: However, the type `T` only implements `...` for some specific lifetime `'2`.
107
107
fn try_report_placeholders_trait (
108
108
& self ,
109
- vid : Option < ty:: RegionVid > ,
109
+ vid : Option < ty:: Region < ' tcx > > ,
110
110
cause : & ObligationCause < ' tcx > ,
111
- sub_placeholder : Option < ty:: PlaceholderRegion > ,
112
- sup_placeholder : Option < ty:: PlaceholderRegion > ,
111
+ sub_placeholder : Option < ty:: Region < ' tcx > > ,
112
+ sup_placeholder : Option < ty:: Region < ' tcx > > ,
113
113
trait_def_id : DefId ,
114
114
expected_substs : & ' tcx Substs < ' tcx > ,
115
115
actual_substs : & ' tcx Substs < ' tcx > ,
@@ -152,120 +152,75 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
152
152
let mut has_sup = None ;
153
153
let mut has_vid = None ;
154
154
155
- self . tcx
156
- . for_each_free_region ( & expected_trait_ref, |r| match r {
157
- ty:: RePlaceholder ( p) => {
158
- if Some ( * p) == sub_placeholder {
159
- if has_sub. is_none ( ) {
160
- has_sub = Some ( counter) ;
161
- counter += 1 ;
162
- }
163
- } else if Some ( * p) == sup_placeholder {
164
- if has_sup. is_none ( ) {
165
- has_sup = Some ( counter) ;
166
- counter += 1 ;
167
- }
168
- }
169
- }
170
- _ => { }
171
- } ) ;
155
+ self . tcx . for_each_free_region ( & expected_trait_ref, |r| {
156
+ if Some ( r) == sub_placeholder && has_sub. is_none ( ) {
157
+ has_sub = Some ( counter) ;
158
+ counter += 1 ;
159
+ } else if Some ( r) == sup_placeholder && has_sup. is_none ( ) {
160
+ has_sup = Some ( counter) ;
161
+ counter += 1 ;
162
+ }
163
+ } ) ;
172
164
173
- self . tcx
174
- . for_each_free_region ( & actual_trait_ref, |r| match r {
175
- ty:: ReVar ( v) if Some ( * v) == vid => {
176
- if has_vid. is_none ( ) {
177
- has_vid = Some ( counter) ;
178
- counter += 1 ;
165
+ self . tcx . for_each_free_region ( & actual_trait_ref, |r| {
166
+ if Some ( r) == vid && has_vid. is_none ( ) {
167
+ has_vid = Some ( counter) ;
168
+ counter += 1 ;
169
+ }
170
+ } ) ;
171
+
172
+ RegionHighlightMode :: maybe_highlighting_region ( sub_placeholder, has_sub, || {
173
+ RegionHighlightMode :: maybe_highlighting_region ( sup_placeholder, has_sup, || {
174
+ match ( has_sub, has_sup) {
175
+ ( Some ( n1) , Some ( n2) ) => {
176
+ err. note ( & format ! (
177
+ "`{}` must implement `{}` \
178
+ for any two lifetimes `'{}` and `'{}`",
179
+ expected_trait_ref. self_ty( ) ,
180
+ expected_trait_ref,
181
+ std:: cmp:: min( n1, n2) ,
182
+ std:: cmp:: max( n1, n2) ,
183
+ ) ) ;
184
+ }
185
+ ( Some ( n) , _) | ( _, Some ( n) ) => {
186
+ err. note ( & format ! (
187
+ "`{}` must implement `{}` \
188
+ for any lifetime `'{}`",
189
+ expected_trait_ref. self_ty( ) ,
190
+ expected_trait_ref,
191
+ n,
192
+ ) ) ;
193
+ }
194
+ ( None , None ) => {
195
+ err. note ( & format ! (
196
+ "`{}` must implement `{}`" ,
197
+ expected_trait_ref. self_ty( ) ,
198
+ expected_trait_ref,
199
+ ) ) ;
179
200
}
180
201
}
181
- _ => { }
182
- } ) ;
183
-
184
- maybe_highlight (
185
- sub_placeholder,
186
- has_sub,
187
- RegionHighlightMode :: highlighting_placeholder,
188
- || {
189
- maybe_highlight (
190
- sup_placeholder,
191
- has_sup,
192
- RegionHighlightMode :: highlighting_placeholder,
193
- || match ( has_sub, has_sup) {
194
- ( Some ( n1) , Some ( n2) ) => {
195
- err. note ( & format ! (
196
- "`{}` must implement `{}` \
197
- for any two lifetimes `'{}` and `'{}`",
198
- expected_trait_ref. self_ty( ) ,
199
- expected_trait_ref,
200
- std:: cmp:: min( n1, n2) ,
201
- std:: cmp:: max( n1, n2) ,
202
- ) ) ;
203
- }
204
- ( Some ( n) , _) | ( _, Some ( n) ) => {
205
- err. note ( & format ! (
206
- "`{}` must implement `{}` \
207
- for any lifetime `'{}`",
208
- expected_trait_ref. self_ty( ) ,
209
- expected_trait_ref,
210
- n,
211
- ) ) ;
212
- }
213
- ( None , None ) => {
214
- err. note ( & format ! (
215
- "`{}` must implement `{}`" ,
216
- expected_trait_ref. self_ty( ) ,
217
- expected_trait_ref,
218
- ) ) ;
219
- }
220
- } ,
221
- )
222
- } ,
223
- ) ;
202
+ } )
203
+ } ) ;
224
204
225
- maybe_highlight (
226
- vid,
227
- has_vid,
228
- RegionHighlightMode :: highlighting_region_vid,
229
- || match has_vid {
230
- Some ( n) => {
231
- err. note ( & format ! (
232
- "but `{}` only implements `{}` for some lifetime `'{}`" ,
233
- actual_trait_ref. self_ty( ) ,
234
- actual_trait_ref,
235
- n
236
- ) ) ;
237
- }
238
- None => {
239
- err. note ( & format ! (
240
- "but `{}` only implements `{}`" ,
241
- actual_trait_ref. self_ty( ) ,
242
- actual_trait_ref,
243
- ) ) ;
244
- }
245
- } ,
246
- ) ;
205
+ RegionHighlightMode :: maybe_highlighting_region ( vid, has_vid, || match has_vid {
206
+ Some ( n) => {
207
+ err. note ( & format ! (
208
+ "but `{}` only implements `{}` for some lifetime `'{}`" ,
209
+ actual_trait_ref. self_ty( ) ,
210
+ actual_trait_ref,
211
+ n
212
+ ) ) ;
213
+ }
214
+ None => {
215
+ err. note ( & format ! (
216
+ "but `{}` only implements `{}`" ,
217
+ actual_trait_ref. self_ty( ) ,
218
+ actual_trait_ref,
219
+ ) ) ;
220
+ }
221
+ } ) ;
247
222
248
223
err. emit ( ) ;
249
224
ErrorReported
250
225
}
251
226
}
252
-
253
- /// If both `thing` and `counter` are `Some`, invoke
254
- /// `highlighting_func` with their contents (and the `op`). Else just
255
- /// invoke `op`.
256
- fn maybe_highlight < T , F , R > (
257
- thing : Option < T > ,
258
- counter : Option < usize > ,
259
- highlighting_func : impl FnOnce ( T , usize , F ) -> R ,
260
- op : F ,
261
- ) -> R
262
- where
263
- F : FnOnce ( ) -> R ,
264
- {
265
- if let Some ( thing) = thing {
266
- if let Some ( n) = counter {
267
- return highlighting_func ( thing, n, op) ;
268
- }
269
- }
270
- op ( )
271
- }
0 commit comments