Closed
Description
Spun off of my investigation of #21114, #54556
Consider this code (play):
#![cfg_attr(use_nll, feature(nll))]
fn main() {
{
let mut _thing1 = D(Box::new("thing1"));
D("other").next(&_thing1)
}
;
}
#[derive(Debug)]
struct D<T: std::fmt::Debug>(T);
impl<T: std::fmt::Debug> Drop for D<T> {
fn drop(&mut self) {
println!("dropping {:?})", self);
}
}
impl<T: std::fmt::Debug> D<T> {
fn next<U: std::fmt::Debug>(&self, _other: U) -> D<U> { D(_other) }
fn end(&self) { }
}
Under AST-borrowck, this emits the diagnostics:
Standard Error
Compiling playground v0.0.1 (/playground)
error[E0597]: `_thing1` does not live long enough
--> src/main.rs:6:26
|
6 | D("other").next(&_thing1)
| ^^^^^^^ borrowed value does not live long enough
7 | }
| - `_thing1` dropped here while still borrowed
8 |
9 | ;
| - borrowed value needs to live until here
under NLL, it only emits this:
error[E0597]: `_thing1` does not live long enough
--> src/main.rs:6:25
|
6 | D("other").next(&_thing1)
| ^^^^^^^^ borrowed value does not live long enough
7 | }
| - `_thing1` dropped here while still borrowed
In particular, the note 8 "borrowed value needs to live until here" that highlights the semi-colon after the end of the block is no longer emitted.
My current plan for addressing #54556 is to improve diagnostics. The first step in that path, IMO, would be to figure out how to bring back the note about how long the borrowed value needs to live.