@@ -61,7 +61,6 @@ use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
61
61
use rustc_hir as hir;
62
62
use rustc_hir:: def_id:: DefId ;
63
63
use rustc_hir:: Node ;
64
- use rustc_middle:: middle:: region;
65
64
use rustc_middle:: ty:: error:: TypeError ;
66
65
use rustc_middle:: ty:: {
67
66
self ,
@@ -81,7 +80,6 @@ pub mod nice_region_error;
81
80
82
81
pub ( super ) fn note_and_explain_region (
83
82
tcx : TyCtxt < ' tcx > ,
84
- region_scope_tree : & region:: ScopeTree ,
85
83
err : & mut DiagnosticBuilder < ' _ > ,
86
84
prefix : & str ,
87
85
region : ty:: Region < ' tcx > ,
@@ -239,7 +237,6 @@ fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option
239
237
240
238
pub fn unexpected_hidden_region_diagnostic (
241
239
tcx : TyCtxt < ' tcx > ,
242
- region_scope_tree : Option < & region:: ScopeTree > ,
243
240
span : Span ,
244
241
hidden_ty : Ty < ' tcx > ,
245
242
hidden_region : ty:: Region < ' tcx > ,
@@ -264,78 +261,53 @@ pub fn unexpected_hidden_region_diagnostic(
264
261
err. span_note ( span, & message) ;
265
262
}
266
263
ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic | ty:: ReEmpty ( _) => {
267
- // Assuming regionck succeeded (*), we ought to always be
268
- // capturing *some* region from the fn header, and hence it
269
- // ought to be free. So under normal circumstances, we will go
270
- // down this path which gives a decent human readable
271
- // explanation.
272
- //
273
- // (*) if not, the `tainted_by_errors` field would be set to
274
- // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
275
- note_and_explain_free_region (
276
- tcx,
277
- & mut err,
278
- & format ! ( "hidden type `{}` captures " , hidden_ty) ,
279
- hidden_region,
280
- "" ,
281
- ) ;
264
+ // Assuming regionck succeeded (*), we ought to always be
265
+ // capturing *some* region from the fn header, and hence it
266
+ // ought to be free. So under normal circumstances, we will go
267
+ // down this path which gives a decent human readable
268
+ // explanation.
269
+ //
270
+ // (*) if not, the `tainted_by_errors` field would be set to
271
+ // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
272
+ note_and_explain_free_region (
273
+ tcx,
274
+ & mut err,
275
+ & format ! ( "hidden type `{}` captures " , hidden_ty) ,
276
+ hidden_region,
277
+ "" ,
278
+ ) ;
282
279
}
283
280
_ => {
284
- // Ugh. This is a painful case: the hidden region is not one
285
- // that we can easily summarize or explain. This can happen
286
- // in a case like
287
- // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
288
- //
289
- // ```
290
- // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
291
- // if condition() { a } else { b }
292
- // }
293
- // ```
294
- //
295
- // Here the captured lifetime is the intersection of `'a` and
296
- // `'b`, which we can't quite express.
297
-
298
- if let Some ( region_scope_tree) = region_scope_tree {
299
- // If the `region_scope_tree` is available, this is being
300
- // invoked from the "region inferencer error". We can at
301
- // least report a really cryptic error for now.
281
+ // Ugh. This is a painful case: the hidden region is not one
282
+ // that we can easily summarize or explain. This can happen
283
+ // in a case like
284
+ // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
285
+ //
286
+ // ```
287
+ // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
288
+ // if condition() { a } else { b }
289
+ // }
290
+ // ```
291
+ //
292
+ // Here the captured lifetime is the intersection of `'a` and
293
+ // `'b`, which we can't quite express.
294
+
295
+ // We can at least report a really cryptic error for now.
302
296
note_and_explain_region (
303
297
tcx,
304
- region_scope_tree,
305
298
& mut err,
306
299
& format ! ( "hidden type `{}` captures " , hidden_ty) ,
307
300
hidden_region,
308
301
"" ,
309
302
) ;
310
- } else {
311
- // If the `region_scope_tree` is *unavailable*, this is
312
- // being invoked by the code that comes *after* region
313
- // inferencing. This is a bug, as the region inferencer
314
- // ought to have noticed the failed constraint and invoked
315
- // error reporting, which in turn should have prevented us
316
- // from getting trying to infer the hidden type
317
- // completely.
318
- tcx. sess . delay_span_bug (
319
- span,
320
- & format ! (
321
- "hidden type captures unexpected lifetime `{:?}` \
322
- but no region inference failure",
323
- hidden_region,
324
- ) ,
325
- ) ;
326
303
}
327
304
}
328
- }
329
305
330
306
err
331
307
}
332
308
333
309
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
334
- pub fn report_region_errors (
335
- & self ,
336
- region_scope_tree : & region:: ScopeTree ,
337
- errors : & Vec < RegionResolutionError < ' tcx > > ,
338
- ) {
310
+ pub fn report_region_errors ( & self , errors : & Vec < RegionResolutionError < ' tcx > > ) {
339
311
debug ! ( "report_region_errors(): {} errors to start" , errors. len( ) ) ;
340
312
341
313
// try to pre-process the errors, which will group some of them
@@ -358,17 +330,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
358
330
// general bit of code that displays the error information
359
331
RegionResolutionError :: ConcreteFailure ( origin, sub, sup) => {
360
332
if sub. is_placeholder ( ) || sup. is_placeholder ( ) {
361
- self . report_placeholder_failure ( region_scope_tree, origin, sub, sup)
362
- . emit ( ) ;
333
+ self . report_placeholder_failure ( origin, sub, sup) . emit ( ) ;
363
334
} else {
364
- self . report_concrete_failure ( region_scope_tree, origin, sub, sup)
365
- . emit ( ) ;
335
+ self . report_concrete_failure ( origin, sub, sup) . emit ( ) ;
366
336
}
367
337
}
368
338
369
339
RegionResolutionError :: GenericBoundFailure ( origin, param_ty, sub) => {
370
340
self . report_generic_bound_failure (
371
- region_scope_tree,
372
341
origin. span ( ) ,
373
342
Some ( origin) ,
374
343
param_ty,
@@ -385,29 +354,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
385
354
sup_r,
386
355
) => {
387
356
if sub_r. is_placeholder ( ) {
388
- self . report_placeholder_failure (
389
- region_scope_tree,
390
- sub_origin,
391
- sub_r,
392
- sup_r,
393
- )
394
- . emit ( ) ;
357
+ self . report_placeholder_failure ( sub_origin, sub_r, sup_r) . emit ( ) ;
395
358
} else if sup_r. is_placeholder ( ) {
396
- self . report_placeholder_failure (
397
- region_scope_tree,
398
- sup_origin,
399
- sub_r,
400
- sup_r,
401
- )
402
- . emit ( ) ;
359
+ self . report_placeholder_failure ( sup_origin, sub_r, sup_r) . emit ( ) ;
403
360
} else {
404
361
self . report_sub_sup_conflict (
405
- region_scope_tree,
406
- var_origin,
407
- sub_origin,
408
- sub_r,
409
- sup_origin,
410
- sup_r,
362
+ var_origin, sub_origin, sub_r, sup_origin, sup_r,
411
363
) ;
412
364
}
413
365
}
@@ -428,13 +380,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
428
380
// value.
429
381
let sub_r = self . tcx . mk_region ( ty:: ReEmpty ( var_universe) ) ;
430
382
431
- self . report_placeholder_failure (
432
- region_scope_tree,
433
- sup_origin,
434
- sub_r,
435
- sup_r,
436
- )
437
- . emit ( ) ;
383
+ self . report_placeholder_failure ( sup_origin, sub_r, sup_r) . emit ( ) ;
438
384
}
439
385
440
386
RegionResolutionError :: MemberConstraintFailure {
@@ -445,7 +391,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
445
391
let hidden_ty = self . resolve_vars_if_possible ( & hidden_ty) ;
446
392
unexpected_hidden_region_diagnostic (
447
393
self . tcx ,
448
- Some ( region_scope_tree) ,
449
394
span,
450
395
hidden_ty,
451
396
member_region,
@@ -1722,19 +1667,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1722
1667
1723
1668
pub fn report_generic_bound_failure (
1724
1669
& self ,
1725
- region_scope_tree : & region:: ScopeTree ,
1726
1670
span : Span ,
1727
1671
origin : Option < SubregionOrigin < ' tcx > > ,
1728
1672
bound_kind : GenericKind < ' tcx > ,
1729
1673
sub : Region < ' tcx > ,
1730
1674
) {
1731
- self . construct_generic_bound_failure ( region_scope_tree, span, origin, bound_kind, sub)
1732
- . emit ( ) ;
1675
+ self . construct_generic_bound_failure ( span, origin, bound_kind, sub) . emit ( ) ;
1733
1676
}
1734
1677
1735
1678
pub fn construct_generic_bound_failure (
1736
1679
& self ,
1737
- region_scope_tree : & region:: ScopeTree ,
1738
1680
span : Span ,
1739
1681
origin : Option < SubregionOrigin < ' tcx > > ,
1740
1682
bound_kind : GenericKind < ' tcx > ,
@@ -1886,7 +1828,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1886
1828
) ) ;
1887
1829
note_and_explain_region (
1888
1830
self . tcx ,
1889
- region_scope_tree,
1890
1831
& mut err,
1891
1832
& format ! ( "{} must be valid for " , labeled_user_string) ,
1892
1833
sub,
@@ -1904,7 +1845,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1904
1845
1905
1846
fn report_sub_sup_conflict (
1906
1847
& self ,
1907
- region_scope_tree : & region:: ScopeTree ,
1908
1848
var_origin : RegionVariableOrigin ,
1909
1849
sub_origin : SubregionOrigin < ' tcx > ,
1910
1850
sub_region : Region < ' tcx > ,
@@ -1915,7 +1855,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1915
1855
1916
1856
note_and_explain_region (
1917
1857
self . tcx ,
1918
- region_scope_tree,
1919
1858
& mut err,
1920
1859
"first, the lifetime cannot outlive " ,
1921
1860
sup_region,
@@ -1941,7 +1880,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1941
1880
if sub_expected == sup_expected && sub_found == sup_found {
1942
1881
note_and_explain_region (
1943
1882
self . tcx ,
1944
- region_scope_tree,
1945
1883
& mut err,
1946
1884
"...but the lifetime must also be valid for " ,
1947
1885
sub_region,
@@ -1963,7 +1901,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1963
1901
1964
1902
note_and_explain_region (
1965
1903
self . tcx ,
1966
- region_scope_tree,
1967
1904
& mut err,
1968
1905
"but, the lifetime must be valid for " ,
1969
1906
sub_region,
0 commit comments