Skip to content

Commit 5042dbd

Browse files
committed
add RegionNameHighlight::Occluded
1 parent 34ff352 commit 5042dbd

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ crate enum RegionNameHighlight {
5757
/// The anonymous region corresponds to a region where the type annotation is completely missing
5858
/// from the code, e.g. in a closure arguments `|x| { ... }`, where `x` is a reference.
5959
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),
6064
}
6165

6266
impl RegionName {
@@ -87,7 +91,8 @@ impl RegionName {
8791
RegionNameSource::AnonRegionFromArgument(ref highlight) => match *highlight {
8892
RegionNameHighlight::MatchedHirTy(span)
8993
| RegionNameHighlight::MatchedAdtAndSegment(span)
90-
| RegionNameHighlight::CannotMatchHirTy(span, _) => Some(span),
94+
| RegionNameHighlight::CannotMatchHirTy(span, _)
95+
| RegionNameHighlight::Occluded(span, _) => Some(span),
9196
},
9297
}
9398
}
@@ -123,6 +128,15 @@ impl RegionName {
123128
) => {
124129
diag.span_label(*span, format!("let's call this `{}`", self));
125130
}
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+
}
126140
RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => {
127141
diag.span_label(
128142
*span,
@@ -349,19 +363,21 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
349363
argument_index,
350364
);
351365

352-
self.get_argument_hir_ty_for_highlighting(argument_index)
366+
let highlight = self
367+
.get_argument_hir_ty_for_highlighting(argument_index)
353368
.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(|| {
355370
// `highlight_if_we_cannot_match_hir_ty` needs to know the number we will give to
356371
// the anonymous region. If it succeeds, the `synthesize_region_name` call below
357372
// will increment the counter, "reserving" the number we just used.
358373
let counter = *self.next_region_name.try_borrow().unwrap();
359374
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+
})
365381
}
366382

367383
fn get_argument_hir_ty_for_highlighting(
@@ -399,7 +415,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
399415
ty: Ty<'tcx>,
400416
span: Span,
401417
counter: usize,
402-
) -> Option<RegionNameHighlight> {
418+
) -> RegionNameHighlight {
403419
let mut highlight = RegionHighlightMode::default();
404420
highlight.highlighting_region_vid(needle_fr, counter);
405421
let type_name =
@@ -411,9 +427,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
411427
);
412428
if type_name.find(&format!("'{}", counter)).is_some() {
413429
// 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)
415431
} else {
416-
None
432+
RegionNameHighlight::Occluded(span, type_name)
417433
}
418434
}
419435

0 commit comments

Comments
 (0)