@@ -34,19 +34,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
34
34
sub_placeholder @ ty:: RePlaceholder ( _) ,
35
35
_,
36
36
sup_placeholder @ ty:: RePlaceholder ( _) ,
37
- ) )
38
- if expected. def_id == found. def_id =>
39
- {
40
- Some ( self . try_report_placeholders_trait (
41
- Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
42
- cause,
43
- Some ( sub_placeholder) ,
44
- Some ( sup_placeholder) ,
45
- expected. def_id ,
46
- expected. substs ,
47
- found. substs ,
48
- ) )
49
- }
37
+ ) ) if expected. def_id == found. def_id => Some ( self . try_report_placeholders_trait (
38
+ Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
39
+ cause,
40
+ Some ( sub_placeholder) ,
41
+ Some ( sup_placeholder) ,
42
+ expected. def_id ,
43
+ expected. substs ,
44
+ found. substs ,
45
+ ) ) ,
50
46
51
47
Some ( RegionResolutionError :: SubSupConflict (
52
48
vid,
@@ -58,19 +54,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
58
54
sub_placeholder @ ty:: RePlaceholder ( _) ,
59
55
_,
60
56
_,
61
- ) )
62
- if expected. def_id == found. def_id =>
63
- {
64
- Some ( self . try_report_placeholders_trait (
65
- Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
66
- cause,
67
- Some ( sub_placeholder) ,
68
- None ,
69
- expected. def_id ,
70
- expected. substs ,
71
- found. substs ,
72
- ) )
73
- }
57
+ ) ) if expected. def_id == found. def_id => Some ( self . try_report_placeholders_trait (
58
+ Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
59
+ cause,
60
+ Some ( sub_placeholder) ,
61
+ None ,
62
+ expected. def_id ,
63
+ expected. substs ,
64
+ found. substs ,
65
+ ) ) ,
74
66
75
67
Some ( RegionResolutionError :: SubSupConflict (
76
68
vid,
@@ -82,19 +74,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
82
74
_,
83
75
_,
84
76
sup_placeholder @ ty:: RePlaceholder ( _) ,
85
- ) )
86
- if expected. def_id == found. def_id =>
87
- {
88
- Some ( self . try_report_placeholders_trait (
89
- Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
90
- cause,
91
- None ,
92
- Some ( * sup_placeholder) ,
93
- expected. def_id ,
94
- expected. substs ,
95
- found. substs ,
96
- ) )
97
- }
77
+ ) ) if expected. def_id == found. def_id => Some ( self . try_report_placeholders_trait (
78
+ Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
79
+ cause,
80
+ None ,
81
+ Some ( * sup_placeholder) ,
82
+ expected. def_id ,
83
+ expected. substs ,
84
+ found. substs ,
85
+ ) ) ,
98
86
99
87
Some ( RegionResolutionError :: SubSupConflict (
100
88
vid,
@@ -106,19 +94,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
106
94
values : ValuePairs :: TraitRefs ( ExpectedFound { expected, found } ) ,
107
95
} ) ,
108
96
sup_placeholder @ ty:: RePlaceholder ( _) ,
109
- ) )
110
- if expected. def_id == found. def_id =>
111
- {
112
- Some ( self . try_report_placeholders_trait (
113
- Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
114
- cause,
115
- None ,
116
- Some ( * sup_placeholder) ,
117
- expected. def_id ,
118
- expected. substs ,
119
- found. substs ,
120
- ) )
121
- }
97
+ ) ) if expected. def_id == found. def_id => Some ( self . try_report_placeholders_trait (
98
+ Some ( self . tcx ( ) . mk_region ( ty:: ReVar ( * vid) ) ) ,
99
+ cause,
100
+ None ,
101
+ Some ( * sup_placeholder) ,
102
+ expected. def_id ,
103
+ expected. substs ,
104
+ found. substs ,
105
+ ) ) ,
122
106
123
107
Some ( RegionResolutionError :: ConcreteFailure (
124
108
SubregionOrigin :: Subtype ( TypeTrace {
@@ -127,19 +111,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
127
111
} ) ,
128
112
sub_region @ ty:: RePlaceholder ( _) ,
129
113
sup_region @ ty:: RePlaceholder ( _) ,
130
- ) )
131
- if expected. def_id == found. def_id =>
132
- {
133
- Some ( self . try_report_placeholders_trait (
134
- None ,
135
- cause,
136
- Some ( * sub_region) ,
137
- Some ( * sup_region) ,
138
- expected. def_id ,
139
- expected. substs ,
140
- found. substs ,
141
- ) )
142
- }
114
+ ) ) if expected. def_id == found. def_id => Some ( self . try_report_placeholders_trait (
115
+ None ,
116
+ cause,
117
+ Some ( * sub_region) ,
118
+ Some ( * sup_region) ,
119
+ expected. def_id ,
120
+ expected. substs ,
121
+ found. substs ,
122
+ ) ) ,
143
123
144
124
Some ( RegionResolutionError :: ConcreteFailure (
145
125
SubregionOrigin :: Subtype ( TypeTrace {
@@ -148,19 +128,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
148
128
} ) ,
149
129
sub_region @ ty:: RePlaceholder ( _) ,
150
130
sup_region,
151
- ) )
152
- if expected. def_id == found. def_id =>
153
- {
154
- Some ( self . try_report_placeholders_trait (
155
- Some ( sup_region) ,
156
- cause,
157
- Some ( * sub_region) ,
158
- None ,
159
- expected. def_id ,
160
- expected. substs ,
161
- found. substs ,
162
- ) )
163
- }
131
+ ) ) if expected. def_id == found. def_id => Some ( self . try_report_placeholders_trait (
132
+ Some ( sup_region) ,
133
+ cause,
134
+ Some ( * sub_region) ,
135
+ None ,
136
+ expected. def_id ,
137
+ expected. substs ,
138
+ found. substs ,
139
+ ) ) ,
164
140
165
141
Some ( RegionResolutionError :: ConcreteFailure (
166
142
SubregionOrigin :: Subtype ( TypeTrace {
@@ -169,19 +145,15 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
169
145
} ) ,
170
146
sub_region,
171
147
sup_region @ ty:: RePlaceholder ( _) ,
172
- ) )
173
- if expected. def_id == found. def_id =>
174
- {
175
- Some ( self . try_report_placeholders_trait (
176
- Some ( sub_region) ,
177
- cause,
178
- None ,
179
- Some ( * sup_region) ,
180
- expected. def_id ,
181
- expected. substs ,
182
- found. substs ,
183
- ) )
184
- }
148
+ ) ) if expected. def_id == found. def_id => Some ( self . try_report_placeholders_trait (
149
+ Some ( sub_region) ,
150
+ cause,
151
+ None ,
152
+ Some ( * sup_region) ,
153
+ expected. def_id ,
154
+ expected. substs ,
155
+ found. substs ,
156
+ ) ) ,
185
157
186
158
_ => None ,
187
159
}
@@ -206,14 +178,16 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
206
178
expected_substs : & ' tcx Substs < ' tcx > ,
207
179
actual_substs : & ' tcx Substs < ' tcx > ,
208
180
) -> ErrorReported {
209
- debug ! ( "try_report_placeholders_trait(\
210
- vid={:?}, \
211
- sub_placeholder={:?}, \
212
- sup_placeholder={:?}, \
213
- trait_def_id={:?}, \
214
- expected_substs={:?}, \
215
- actual_substs={:?})",
216
- vid, sub_placeholder, sup_placeholder, trait_def_id, expected_substs, actual_substs) ;
181
+ debug ! (
182
+ "try_report_placeholders_trait(\
183
+ vid={:?}, \
184
+ sub_placeholder={:?}, \
185
+ sup_placeholder={:?}, \
186
+ trait_def_id={:?}, \
187
+ expected_substs={:?}, \
188
+ actual_substs={:?})",
189
+ vid, sub_placeholder, sup_placeholder, trait_def_id, expected_substs, actual_substs
190
+ ) ;
217
191
218
192
let mut err = self . tcx ( ) . sess . struct_span_err (
219
193
cause. span ( & self . tcx ( ) ) ,
@@ -233,18 +207,14 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
233
207
_ => ( ) ,
234
208
}
235
209
236
- let expected_trait_ref = self . infcx . resolve_type_vars_if_possible (
237
- & ty:: TraitRef {
238
- def_id : trait_def_id,
239
- substs : expected_substs,
240
- }
241
- ) ;
242
- let actual_trait_ref = self . infcx . resolve_type_vars_if_possible (
243
- & ty:: TraitRef {
244
- def_id : trait_def_id,
245
- substs : actual_substs,
246
- }
247
- ) ;
210
+ let expected_trait_ref = self . infcx . resolve_type_vars_if_possible ( & ty:: TraitRef {
211
+ def_id : trait_def_id,
212
+ substs : expected_substs,
213
+ } ) ;
214
+ let actual_trait_ref = self . infcx . resolve_type_vars_if_possible ( & ty:: TraitRef {
215
+ def_id : trait_def_id,
216
+ substs : actual_substs,
217
+ } ) ;
248
218
249
219
// Search the expected and actual trait references to see (a)
250
220
// whether the sub/sup placeholders appear in them (sometimes
@@ -285,19 +255,28 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
285
255
. tcx ( )
286
256
. any_free_region_meets ( & actual_trait_ref. self_ty ( ) , |r| Some ( r) == vid) ;
287
257
288
- debug ! ( "try_report_placeholders_trait: actual_has_vid={:?}" , actual_has_vid) ;
289
- debug ! ( "try_report_placeholders_trait: expected_has_vid={:?}" , expected_has_vid) ;
258
+ debug ! (
259
+ "try_report_placeholders_trait: actual_has_vid={:?}" ,
260
+ actual_has_vid
261
+ ) ;
262
+ debug ! (
263
+ "try_report_placeholders_trait: expected_has_vid={:?}" ,
264
+ expected_has_vid
265
+ ) ;
290
266
debug ! ( "try_report_placeholders_trait: has_sub={:?}" , has_sub) ;
291
267
debug ! ( "try_report_placeholders_trait: has_sup={:?}" , has_sup) ;
292
- debug ! ( "try_report_placeholders_trait: self_ty_has_vid={:?}" , self_ty_has_vid) ;
268
+ debug ! (
269
+ "try_report_placeholders_trait: self_ty_has_vid={:?}" ,
270
+ self_ty_has_vid
271
+ ) ;
293
272
294
273
RegionHighlightMode :: maybe_highlighting_region ( sub_placeholder, has_sub, || {
295
274
RegionHighlightMode :: maybe_highlighting_region ( sup_placeholder, has_sup, || {
296
275
match ( has_sub, has_sup) {
297
276
( Some ( n1) , Some ( n2) ) => {
298
277
err. note ( & format ! (
299
278
"`{}` would have to be implemented for the type `{}`, \
300
- for any two lifetimes `'{}` and `'{}`",
279
+ for any two lifetimes `'{}` and `'{}`",
301
280
expected_trait_ref,
302
281
expected_trait_ref. self_ty( ) ,
303
282
std:: cmp:: min( n1, n2) ,
@@ -307,40 +286,54 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
307
286
( Some ( n) , _) | ( _, Some ( n) ) => {
308
287
err. note ( & format ! (
309
288
"`{}` would have to be implemented for the type `{}`, \
310
- for any lifetime `'{}`",
289
+ for any lifetime `'{}`",
311
290
expected_trait_ref,
312
291
expected_trait_ref. self_ty( ) ,
313
292
n,
314
293
) ) ;
315
294
}
316
- ( None , None ) => {
317
- err. note ( & format ! (
318
- "`{}` would have to be implemented for the type `{}`" ,
319
- expected_trait_ref,
320
- expected_trait_ref. self_ty( ) ,
321
- ) ) ;
322
- }
295
+ ( None , None ) => RegionHighlightMode :: maybe_highlighting_region (
296
+ vid,
297
+ expected_has_vid,
298
+ || {
299
+ if let Some ( n) = expected_has_vid {
300
+ err. note ( & format ! (
301
+ "`{}` would have to be implemented for the type `{}`, \
302
+ for some specific lifetime `'{}`",
303
+ expected_trait_ref,
304
+ expected_trait_ref. self_ty( ) ,
305
+ n,
306
+ ) ) ;
307
+ } else {
308
+ err. note ( & format ! (
309
+ "`{}` would have to be implemented for the type `{}`" ,
310
+ expected_trait_ref,
311
+ expected_trait_ref. self_ty( ) ,
312
+ ) ) ;
313
+ }
314
+ } ,
315
+ ) ,
323
316
}
324
317
} )
325
318
} ) ;
326
319
327
320
RegionHighlightMode :: maybe_highlighting_region (
328
321
vid,
329
- actual_has_vid. or ( expected_has_vid ) ,
322
+ actual_has_vid,
330
323
|| match actual_has_vid {
331
324
Some ( n) => {
332
325
if self_ty_has_vid {
333
326
err. note ( & format ! (
334
327
"but `{}` is actually implemented for the type `{}`, \
335
- for the specific lifetime `'{}`",
328
+ for the specific lifetime `'{}`",
336
329
actual_trait_ref,
337
330
actual_trait_ref. self_ty( ) ,
338
331
n
339
332
) ) ;
340
333
} else {
341
334
err. note ( & format ! (
342
335
"but `{}` is actually implemented for the type `{}`, \
343
- for some lifetime `'{}`",
336
+ for some lifetime `'{}`",
344
337
actual_trait_ref,
345
338
actual_trait_ref. self_ty( ) ,
346
339
n
@@ -355,7 +348,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
355
348
actual_trait_ref. self_ty( ) ,
356
349
) ) ;
357
350
}
358
- }
351
+ } ,
359
352
) ;
360
353
361
354
err. emit ( ) ;
0 commit comments