Skip to content

Commit 255ead5

Browse files
committed
Fallback to 'has type' error messages rather than 'lifetime appears in type'.
1 parent 82b4827 commit 255ead5

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

+9-25
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
242242
return Some(region_name);
243243
}
244244

245-
let (_argument_name, argument_span) = self.get_argument_name_and_span_for_region(
246-
mir, argument_index);
247-
248-
let region_name = self.synthesize_region_name(counter);
249-
250-
diag.span_label(
251-
argument_span,
252-
format!("lifetime `{}` appears in this argument", region_name,),
253-
);
254-
255-
Some(region_name)
245+
self.give_name_if_we_cannot_match_hir_ty(
246+
infcx,
247+
mir,
248+
fr,
249+
arg_ty,
250+
counter,
251+
diag,
252+
)
256253
}
257254

258255
fn give_name_if_we_can_match_hir_ty_from_argument(
@@ -370,14 +367,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
370367

371368
search_stack.push((argument_ty, argument_hir_ty));
372369

373-
let mut closest_match: &hir::Ty = argument_hir_ty;
374-
375370
while let Some((ty, hir_ty)) = search_stack.pop() {
376-
// While we search, also track the closet match.
377-
if tcx.any_free_region_meets(&ty, |r| r.to_region_vid() == needle_fr) {
378-
closest_match = hir_ty;
379-
}
380-
381371
match (&ty.sty, &hir_ty.node) {
382372
// Check if the `argument_ty` is `&'X ..` where `'X`
383373
// is the region we are looking for -- if so, and we have a `&T`
@@ -452,13 +442,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
452442
}
453443
}
454444

455-
let region_name = self.synthesize_region_name(counter);
456-
diag.span_label(
457-
closest_match.span,
458-
format!("lifetime `{}` appears in this type", region_name),
459-
);
460-
461-
return Some(region_name);
445+
return None;
462446
}
463447

464448
/// We've found an enum/struct/union type with the substitutions

src/test/ui/nll/issue-52742.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: unsatisfied lifetime constraints
44
LL | fn take_bar(&mut self, b: Bar<'_>) {
55
| --------- -- let's call this `'1`
66
| |
7-
| lifetime `'2` appears in this type
7+
| has type `&mut Foo<'_, '2>`
88
LL | self.y = b.z
99
| ^^^^^^^^^^^^ requires that `'1` must outlive `'2`
1010

0 commit comments

Comments
 (0)