borrow_span,
format!("`{}` would have to be valid for `{}`", name, region_name)
);
- err.span_label(drop_span, format!("but `{}` dropped here while still borrowed", name));
+
+ if let Some(fn_node_id) = self.infcx.tcx.hir.as_local_node_id(self.mir_def_id) {
+ err.span_label(
+ drop_span,
+ format!(
+ "...but `{}` is only valid for the duration of the `{}` function, so it \
+ is dropped here while still borrowed",
+ name,
+ self.infcx.tcx.hir.name(fn_node_id),
+ )
+ );
+ } else {
+ err.span_label(
+ drop_span,
+ format!("...but `{}` dropped here while still borrowed", name)
+ );
+ }
if let BorrowExplanation::MustBeValidFor(..) = explanation { } else {
explanation.emit(self.infcx.tcx, &mut err);
| ^^ `x` would have to be valid for `'y`
LL | //~^ ERROR: `x` does not live long enough
LL | }
- | - but `x` dropped here while still borrowed
+ | - ...but `x` is only valid for the duration of the `silly` function, so it is dropped here while still borrowed
error: aborting due to previous error
| ^^ `v` would have to be valid for `'a`
LL | //~^ ERROR `v` does not live long enough [E0597]
LL | }
- | - but `v` dropped here while still borrowed
+ | - ...but `v` is only valid for the duration of the `foo` function, so it is dropped here while still borrowed
error: aborting due to previous error
LL | &x
| ^^ `x` would have to be valid for `'0`
LL | }
- | - but `x` dropped here while still borrowed
+ | - ...but `x` is only valid for the duration of the `bar` function, so it is dropped here while still borrowed
error[E0597]: `x` does not live long enough
--> $DIR/issue-52534-1.rs:25:5
LL | &x
| ^^ `x` would have to be valid for `'0`
LL | }
- | - but `x` dropped here while still borrowed
+ | - ...but `x` is only valid for the duration of the `foo` function, so it is dropped here while still borrowed
error[E0597]: `x` does not live long enough
--> $DIR/issue-52534-1.rs:30:6
LL | &&x
| ^^ `x` would have to be valid for `'0`
LL | }
- | - but `x` dropped here while still borrowed
+ | - ...but `x` is only valid for the duration of the `baz` function, so it is dropped here while still borrowed
error[E0597]: borrowed value does not live long enough
--> $DIR/issue-52534-1.rs:30:6
| |
| has type `&'0 u32`
LL | }
- | - but `x` dropped here while still borrowed
+ | - ...but `x` is only valid for the duration of the `bar` function, so it is dropped here while still borrowed
error: aborting due to previous error
| ^ `y` would have to be valid for `'0`
LL | });
LL | }
- | - but `y` dropped here while still borrowed
+ | - ...but `y` is only valid for the duration of the `nested` function, so it is dropped here while still borrowed
error: aborting due to previous error
| ^ `y` would have to be valid for `'0`
...
LL | }
- | - but `y` dropped here while still borrowed
+ | - ...but `y` is only valid for the duration of the `nested` function, so it is dropped here while still borrowed
error: unsatisfied lifetime constraints
--> $DIR/regions-nested-fns.rs:23:68