Skip to content

Commit 556f583

Browse files
committed
Regression test for issue #54382
(I opted to rely on compare-mode=nll rather than opt into `#![feature(nll)]`, mostly to make it easy to observe the interesting differences between the AST-borrwock diagnostic and the NLL one.)
1 parent 3011ecd commit 556f583

3 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0597]: `_thing1` does not live long enough
2+
--> $DIR/issue-54382-use-span-of-tail-of-block.rs:7:29
3+
|
4+
LL | D("other").next(&_thing1)
5+
| ----------------^^^^^^^^-
6+
| | |
7+
| | borrowed value does not live long enough
8+
| a temporary with access to the borrow is created here ...
9+
LL | }
10+
LL | }
11+
| - `_thing1` dropped here while still borrowed
12+
LL |
13+
LL | ;
14+
| - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D`
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0597`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
fn main() {
2+
{
3+
let mut _thing1 = D(Box::new("thing1"));
4+
{
5+
let _thing2 = D("thing2");
6+
side_effects();
7+
D("other").next(&_thing1)
8+
}
9+
}
10+
11+
;
12+
}
13+
14+
#[derive(Debug)]
15+
struct D<T: std::fmt::Debug>(T);
16+
17+
impl<T: std::fmt::Debug> Drop for D<T> {
18+
fn drop(&mut self) {
19+
println!("dropping {:?})", self);
20+
}
21+
}
22+
23+
impl<T: std::fmt::Debug> D<T> {
24+
fn next<U: std::fmt::Debug>(&self, _other: U) -> D<U> { D(_other) }
25+
fn end(&self) { }
26+
}
27+
28+
fn side_effects() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0597]: `_thing1` does not live long enough
2+
--> $DIR/issue-54382-use-span-of-tail-of-block.rs:7:30
3+
|
4+
LL | D("other").next(&_thing1)
5+
| ^^^^^^^ borrowed value does not live long enough
6+
LL | }
7+
LL | }
8+
| - `_thing1` dropped here while still borrowed
9+
LL |
10+
LL | ;
11+
| - borrowed value needs to live until here
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)