@@ -57,6 +57,10 @@ crate enum RegionNameHighlight {
57
57
/// The anonymous region corresponds to a region where the type annotation is completely missing
58
58
/// from the code, e.g. in a closure arguments `|x| { ... }`, where `x` is a reference.
59
59
CannotMatchHirTy ( Span , String ) ,
60
+ /// The anonymous region corresponds to a region where the type annotation is completely missing
61
+ /// from the code, and *even if* we print out the full name of the type, the region name won't
62
+ /// be included. This currently occurs for opaque types like `impl Future`.
63
+ Occluded ( Span , String ) ,
60
64
}
61
65
62
66
impl RegionName {
@@ -87,7 +91,8 @@ impl RegionName {
87
91
RegionNameSource :: AnonRegionFromArgument ( ref highlight) => match * highlight {
88
92
RegionNameHighlight :: MatchedHirTy ( span)
89
93
| RegionNameHighlight :: MatchedAdtAndSegment ( span)
90
- | RegionNameHighlight :: CannotMatchHirTy ( span, _) => Some ( span) ,
94
+ | RegionNameHighlight :: CannotMatchHirTy ( span, _)
95
+ | RegionNameHighlight :: Occluded ( span, _) => Some ( span) ,
91
96
} ,
92
97
}
93
98
}
@@ -123,6 +128,15 @@ impl RegionName {
123
128
) => {
124
129
diag. span_label ( * span, format ! ( "let's call this `{}`" , self ) ) ;
125
130
}
131
+ RegionNameSource :: AnonRegionFromArgument ( RegionNameHighlight :: Occluded (
132
+ span,
133
+ type_name,
134
+ ) ) => {
135
+ diag. span_label (
136
+ * span,
137
+ format ! ( "lifetime `{}` appears in the type {}" , self , type_name) ,
138
+ ) ;
139
+ }
126
140
RegionNameSource :: AnonRegionFromUpvar ( span, upvar_name) => {
127
141
diag. span_label (
128
142
* span,
@@ -349,19 +363,21 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
349
363
argument_index,
350
364
) ;
351
365
352
- self . get_argument_hir_ty_for_highlighting ( argument_index)
366
+ let highlight = self
367
+ . get_argument_hir_ty_for_highlighting ( argument_index)
353
368
. and_then ( |arg_hir_ty| self . highlight_if_we_can_match_hir_ty ( fr, arg_ty, arg_hir_ty) )
354
- . or_else ( || {
369
+ . unwrap_or_else ( || {
355
370
// `highlight_if_we_cannot_match_hir_ty` needs to know the number we will give to
356
371
// the anonymous region. If it succeeds, the `synthesize_region_name` call below
357
372
// will increment the counter, "reserving" the number we just used.
358
373
let counter = * self . next_region_name . try_borrow ( ) . unwrap ( ) ;
359
374
self . highlight_if_we_cannot_match_hir_ty ( fr, arg_ty, span, counter)
360
- } )
361
- . map ( |highlight| RegionName {
362
- name : self . synthesize_region_name ( ) ,
363
- source : RegionNameSource :: AnonRegionFromArgument ( highlight) ,
364
- } )
375
+ } ) ;
376
+
377
+ Some ( RegionName {
378
+ name : self . synthesize_region_name ( ) ,
379
+ source : RegionNameSource :: AnonRegionFromArgument ( highlight) ,
380
+ } )
365
381
}
366
382
367
383
fn get_argument_hir_ty_for_highlighting (
@@ -399,7 +415,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
399
415
ty : Ty < ' tcx > ,
400
416
span : Span ,
401
417
counter : usize ,
402
- ) -> Option < RegionNameHighlight > {
418
+ ) -> RegionNameHighlight {
403
419
let mut highlight = RegionHighlightMode :: default ( ) ;
404
420
highlight. highlighting_region_vid ( needle_fr, counter) ;
405
421
let type_name =
@@ -411,9 +427,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
411
427
) ;
412
428
if type_name. find ( & format ! ( "'{}" , counter) ) . is_some ( ) {
413
429
// Only add a label if we can confirm that a region was labelled.
414
- Some ( RegionNameHighlight :: CannotMatchHirTy ( span, type_name) )
430
+ RegionNameHighlight :: CannotMatchHirTy ( span, type_name)
415
431
} else {
416
- None
432
+ RegionNameHighlight :: Occluded ( span , type_name )
417
433
}
418
434
}
419
435
0 commit comments