Skip to content

Commit 12037ff

Browse files
committed
Fallback to 'has type' error messages rather than 'lifetime appears in type'.
1 parent 5187ad1 commit 12037ff

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

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
208208
return Some(region_name);
209209
}
210210

211-
let (_argument_name, argument_span) = self.get_argument_name_and_span_for_region(
212-
mir, argument_index);
213-
214-
let region_name = self.synthesize_region_name(counter);
215-
216-
diag.span_label(
217-
argument_span,
218-
format!("lifetime `{}` appears in this argument", region_name,),
219-
);
220-
221-
Some(region_name)
211+
self.give_name_if_we_cannot_match_hir_ty(
212+
infcx,
213+
mir,
214+
fr,
215+
arg_ty,
216+
counter,
217+
diag,
218+
)
222219
}
223220

224221
fn give_name_if_we_can_match_hir_ty_from_argument(
@@ -336,14 +333,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
336333

337334
search_stack.push((argument_ty, argument_hir_ty));
338335

339-
let mut closest_match: &hir::Ty = argument_hir_ty;
340-
341336
while let Some((ty, hir_ty)) = search_stack.pop() {
342-
// While we search, also track the closet match.
343-
if tcx.any_free_region_meets(&ty, |r| r.to_region_vid() == needle_fr) {
344-
closest_match = hir_ty;
345-
}
346-
347337
match (&ty.sty, &hir_ty.node) {
348338
// Check if the `argument_ty` is `&'X ..` where `'X`
349339
// is the region we are looking for -- if so, and we have a `&T`
@@ -418,13 +408,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
418408
}
419409
}
420410

421-
let region_name = self.synthesize_region_name(counter);
422-
diag.span_label(
423-
closest_match.span,
424-
format!("lifetime `{}` appears in this type", region_name),
425-
);
426-
427-
return Some(region_name);
411+
return None;
428412
}
429413

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

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

Lines changed: 1 addition & 1 deletion
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)