@@ -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,58 +80,12 @@ 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 > ,
88
86
suffix : & str ,
89
87
) {
90
88
let ( description, span) = match * region {
91
- ty:: ReScope ( scope) => {
92
- let new_string;
93
- let unknown_scope =
94
- || format ! ( "{}unknown scope: {:?}{}. Please report a bug." , prefix, scope, suffix) ;
95
- let span = scope. span ( tcx, region_scope_tree) ;
96
- let hir_id = scope. hir_id ( region_scope_tree) ;
97
- let tag = match hir_id. and_then ( |hir_id| tcx. hir ( ) . find ( hir_id) ) {
98
- Some ( Node :: Block ( _) ) => "block" ,
99
- Some ( Node :: Expr ( expr) ) => match expr. kind {
100
- hir:: ExprKind :: Call ( ..) => "call" ,
101
- hir:: ExprKind :: MethodCall ( ..) => "method call" ,
102
- hir:: ExprKind :: Match ( .., hir:: MatchSource :: IfLetDesugar { .. } ) => "if let" ,
103
- hir:: ExprKind :: Match ( .., hir:: MatchSource :: WhileLetDesugar ) => "while let" ,
104
- hir:: ExprKind :: Match ( .., hir:: MatchSource :: ForLoopDesugar ) => "for" ,
105
- hir:: ExprKind :: Match ( ..) => "match" ,
106
- _ => "expression" ,
107
- } ,
108
- Some ( Node :: Stmt ( _) ) => "statement" ,
109
- Some ( Node :: Item ( it) ) => item_scope_tag ( & it) ,
110
- Some ( Node :: TraitItem ( it) ) => trait_item_scope_tag ( & it) ,
111
- Some ( Node :: ImplItem ( it) ) => impl_item_scope_tag ( & it) ,
112
- Some ( _) | None => {
113
- err. span_note ( span, & unknown_scope ( ) ) ;
114
- return ;
115
- }
116
- } ;
117
- let scope_decorated_tag = match scope. data {
118
- region:: ScopeData :: Node => tag,
119
- region:: ScopeData :: CallSite => "scope of call-site for function" ,
120
- region:: ScopeData :: Arguments => "scope of function body" ,
121
- region:: ScopeData :: Destruction => {
122
- new_string = format ! ( "destruction scope surrounding {}" , tag) ;
123
- & new_string[ ..]
124
- }
125
- region:: ScopeData :: Remainder ( first_statement_index) => {
126
- new_string = format ! (
127
- "block suffix following statement {}" ,
128
- first_statement_index. index( )
129
- ) ;
130
- & new_string[ ..]
131
- }
132
- } ;
133
- explain_span ( tcx, scope_decorated_tag, span)
134
- }
135
-
136
89
ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic => {
137
90
msg_span_from_free_region ( tcx, region)
138
91
}
@@ -284,7 +237,6 @@ fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option
284
237
285
238
pub fn unexpected_hidden_region_diagnostic (
286
239
tcx : TyCtxt < ' tcx > ,
287
- region_scope_tree : Option < & region:: ScopeTree > ,
288
240
span : Span ,
289
241
hidden_ty : Ty < ' tcx > ,
290
242
hidden_region : ty:: Region < ' tcx > ,
@@ -297,64 +249,56 @@ pub fn unexpected_hidden_region_diagnostic(
297
249
) ;
298
250
299
251
// Explain the region we are capturing.
300
- if let ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic | ty:: ReEmpty ( _) = hidden_region {
301
- // Assuming regionck succeeded (*), we ought to always be
302
- // capturing *some* region from the fn header, and hence it
303
- // ought to be free. So under normal circumstances, we will go
304
- // down this path which gives a decent human readable
305
- // explanation.
306
- //
307
- // (*) if not, the `tainted_by_errors` field would be set to
308
- // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
309
- note_and_explain_free_region (
310
- tcx,
311
- & mut err,
312
- & format ! ( "hidden type `{}` captures " , hidden_ty) ,
313
- hidden_region,
314
- "" ,
315
- ) ;
316
- } else {
317
- // Ugh. This is a painful case: the hidden region is not one
318
- // that we can easily summarize or explain. This can happen
319
- // in a case like
320
- // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
321
- //
322
- // ```
323
- // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
324
- // if condition() { a } else { b }
325
- // }
326
- // ```
327
- //
328
- // Here the captured lifetime is the intersection of `'a` and
329
- // `'b`, which we can't quite express.
330
-
331
- if let Some ( region_scope_tree) = region_scope_tree {
332
- // If the `region_scope_tree` is available, this is being
333
- // invoked from the "region inferencer error". We can at
334
- // least report a really cryptic error for now.
335
- note_and_explain_region (
252
+ match hidden_region {
253
+ ty:: ReEmpty ( ty:: UniverseIndex :: ROOT ) => {
254
+ // All lifetimes shorter than the function body are `empty` in
255
+ // lexical region resolution. The default explanation of "an empty
256
+ // lifetime" isn't really accurate here.
257
+ let message = format ! (
258
+ "hidden type `{}` captures lifetime smaller than the function body" ,
259
+ hidden_ty
260
+ ) ;
261
+ err. span_note ( span, & message) ;
262
+ }
263
+ ty:: ReEarlyBound ( _) | ty:: ReFree ( _) | ty:: ReStatic | ty:: ReEmpty ( _) => {
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 (
336
273
tcx,
337
- region_scope_tree,
338
274
& mut err,
339
275
& format ! ( "hidden type `{}` captures " , hidden_ty) ,
340
276
hidden_region,
341
277
"" ,
342
278
) ;
343
- } else {
344
- // If the `region_scope_tree` is *unavailable*, this is
345
- // being invoked by the code that comes *after* region
346
- // inferencing. This is a bug, as the region inferencer
347
- // ought to have noticed the failed constraint and invoked
348
- // error reporting, which in turn should have prevented us
349
- // from getting trying to infer the hidden type
350
- // completely.
351
- tcx. sess . delay_span_bug (
352
- span,
353
- & format ! (
354
- "hidden type captures unexpected lifetime `{:?}` \
355
- but no region inference failure",
356
- hidden_region,
357
- ) ,
279
+ }
280
+ _ => {
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.
296
+ note_and_explain_region (
297
+ tcx,
298
+ & mut err,
299
+ & format ! ( "hidden type `{}` captures " , hidden_ty) ,
300
+ hidden_region,
301
+ "" ,
358
302
) ;
359
303
}
360
304
}
@@ -363,11 +307,7 @@ pub fn unexpected_hidden_region_diagnostic(
363
307
}
364
308
365
309
impl < ' a , ' tcx > InferCtxt < ' a , ' tcx > {
366
- pub fn report_region_errors (
367
- & self ,
368
- region_scope_tree : & region:: ScopeTree ,
369
- errors : & Vec < RegionResolutionError < ' tcx > > ,
370
- ) {
310
+ pub fn report_region_errors ( & self , errors : & Vec < RegionResolutionError < ' tcx > > ) {
371
311
debug ! ( "report_region_errors(): {} errors to start" , errors. len( ) ) ;
372
312
373
313
// try to pre-process the errors, which will group some of them
@@ -390,17 +330,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
390
330
// general bit of code that displays the error information
391
331
RegionResolutionError :: ConcreteFailure ( origin, sub, sup) => {
392
332
if sub. is_placeholder ( ) || sup. is_placeholder ( ) {
393
- self . report_placeholder_failure ( region_scope_tree, origin, sub, sup)
394
- . emit ( ) ;
333
+ self . report_placeholder_failure ( origin, sub, sup) . emit ( ) ;
395
334
} else {
396
- self . report_concrete_failure ( region_scope_tree, origin, sub, sup)
397
- . emit ( ) ;
335
+ self . report_concrete_failure ( origin, sub, sup) . emit ( ) ;
398
336
}
399
337
}
400
338
401
339
RegionResolutionError :: GenericBoundFailure ( origin, param_ty, sub) => {
402
340
self . report_generic_bound_failure (
403
- region_scope_tree,
404
341
origin. span ( ) ,
405
342
Some ( origin) ,
406
343
param_ty,
@@ -417,29 +354,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
417
354
sup_r,
418
355
) => {
419
356
if sub_r. is_placeholder ( ) {
420
- self . report_placeholder_failure (
421
- region_scope_tree,
422
- sub_origin,
423
- sub_r,
424
- sup_r,
425
- )
426
- . emit ( ) ;
357
+ self . report_placeholder_failure ( sub_origin, sub_r, sup_r) . emit ( ) ;
427
358
} else if sup_r. is_placeholder ( ) {
428
- self . report_placeholder_failure (
429
- region_scope_tree,
430
- sup_origin,
431
- sub_r,
432
- sup_r,
433
- )
434
- . emit ( ) ;
359
+ self . report_placeholder_failure ( sup_origin, sub_r, sup_r) . emit ( ) ;
435
360
} else {
436
361
self . report_sub_sup_conflict (
437
- region_scope_tree,
438
- var_origin,
439
- sub_origin,
440
- sub_r,
441
- sup_origin,
442
- sup_r,
362
+ var_origin, sub_origin, sub_r, sup_origin, sup_r,
443
363
) ;
444
364
}
445
365
}
@@ -460,13 +380,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
460
380
// value.
461
381
let sub_r = self . tcx . mk_region ( ty:: ReEmpty ( var_universe) ) ;
462
382
463
- self . report_placeholder_failure (
464
- region_scope_tree,
465
- sup_origin,
466
- sub_r,
467
- sup_r,
468
- )
469
- . emit ( ) ;
383
+ self . report_placeholder_failure ( sup_origin, sub_r, sup_r) . emit ( ) ;
470
384
}
471
385
472
386
RegionResolutionError :: MemberConstraintFailure {
@@ -477,7 +391,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
477
391
let hidden_ty = self . resolve_vars_if_possible ( & hidden_ty) ;
478
392
unexpected_hidden_region_diagnostic (
479
393
self . tcx ,
480
- Some ( region_scope_tree) ,
481
394
span,
482
395
hidden_ty,
483
396
member_region,
@@ -1754,19 +1667,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1754
1667
1755
1668
pub fn report_generic_bound_failure (
1756
1669
& self ,
1757
- region_scope_tree : & region:: ScopeTree ,
1758
1670
span : Span ,
1759
1671
origin : Option < SubregionOrigin < ' tcx > > ,
1760
1672
bound_kind : GenericKind < ' tcx > ,
1761
1673
sub : Region < ' tcx > ,
1762
1674
) {
1763
- self . construct_generic_bound_failure ( region_scope_tree, span, origin, bound_kind, sub)
1764
- . emit ( ) ;
1675
+ self . construct_generic_bound_failure ( span, origin, bound_kind, sub) . emit ( ) ;
1765
1676
}
1766
1677
1767
1678
pub fn construct_generic_bound_failure (
1768
1679
& self ,
1769
- region_scope_tree : & region:: ScopeTree ,
1770
1680
span : Span ,
1771
1681
origin : Option < SubregionOrigin < ' tcx > > ,
1772
1682
bound_kind : GenericKind < ' tcx > ,
@@ -1918,7 +1828,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1918
1828
) ) ;
1919
1829
note_and_explain_region (
1920
1830
self . tcx ,
1921
- region_scope_tree,
1922
1831
& mut err,
1923
1832
& format ! ( "{} must be valid for " , labeled_user_string) ,
1924
1833
sub,
@@ -1936,7 +1845,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1936
1845
1937
1846
fn report_sub_sup_conflict (
1938
1847
& self ,
1939
- region_scope_tree : & region:: ScopeTree ,
1940
1848
var_origin : RegionVariableOrigin ,
1941
1849
sub_origin : SubregionOrigin < ' tcx > ,
1942
1850
sub_region : Region < ' tcx > ,
@@ -1947,7 +1855,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1947
1855
1948
1856
note_and_explain_region (
1949
1857
self . tcx ,
1950
- region_scope_tree,
1951
1858
& mut err,
1952
1859
"first, the lifetime cannot outlive " ,
1953
1860
sup_region,
@@ -1973,7 +1880,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1973
1880
if sub_expected == sup_expected && sub_found == sup_found {
1974
1881
note_and_explain_region (
1975
1882
self . tcx ,
1976
- region_scope_tree,
1977
1883
& mut err,
1978
1884
"...but the lifetime must also be valid for " ,
1979
1885
sub_region,
@@ -1995,7 +1901,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1995
1901
1996
1902
note_and_explain_region (
1997
1903
self . tcx ,
1998
- region_scope_tree,
1999
1904
& mut err,
2000
1905
"but, the lifetime must be valid for " ,
2001
1906
sub_region,
0 commit comments