Skip to content

Commit e3b611f

Browse files
committed
Regression test for this particular change.
1 parent 673cd6e commit e3b611f

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// rust-lang/rust#52059: Regardless of whether you are moving out of a
2+
// Drop type or just introducing an inadvertant alias via a borrow of
3+
// one of its fields, it is useful to be reminded of the significance
4+
// of the fact that the type implements Drop.
5+
6+
#![feature(nll)]
7+
#![allow(dead_code)]
8+
9+
pub struct S<'a> { url: &'a mut String }
10+
11+
impl<'a> Drop for S<'a> { fn drop(&mut self) { } }
12+
13+
fn finish_1(s: S) -> &mut String {
14+
s.url
15+
}
16+
//~^^ ERROR borrow may still be in use when destructor runs
17+
18+
fn finish_2(s: S) -> &mut String {
19+
let p = &mut *s.url; p
20+
}
21+
//~^^ ERROR borrow may still be in use when destructor runs
22+
23+
fn finish_3(s: S) -> &mut String {
24+
let p: &mut _ = s.url; p
25+
}
26+
//~^^ ERROR borrow may still be in use when destructor runs
27+
28+
fn finish_4(s: S) -> &mut String {
29+
let p = s.url; p
30+
}
31+
//~^^ ERROR cannot move out of type `S<'_>`, which implements the `Drop` trait
32+
33+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error[E0713]: borrow may still be in use when destructor runs
2+
--> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:14:5
3+
|
4+
LL | s.url
5+
| ^^^^^
6+
LL | }
7+
| - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait
8+
|
9+
note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 13:1...
10+
--> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:13:1
11+
|
12+
LL | / fn finish_1(s: S) -> &mut String {
13+
LL | | s.url
14+
LL | | }
15+
| |_^
16+
17+
error[E0713]: borrow may still be in use when destructor runs
18+
--> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:19:13
19+
|
20+
LL | let p = &mut *s.url; p
21+
| ^^^^^^^^^^^
22+
LL | }
23+
| - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait
24+
|
25+
note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 18:1...
26+
--> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:18:1
27+
|
28+
LL | / fn finish_2(s: S) -> &mut String {
29+
LL | | let p = &mut *s.url; p
30+
LL | | }
31+
| |_^
32+
33+
error[E0713]: borrow may still be in use when destructor runs
34+
--> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:24:21
35+
|
36+
LL | let p: &mut _ = s.url; p
37+
| ^^^^^
38+
LL | }
39+
| - here, drop of `s` needs exclusive access to `*s.url`, because the type `S<'_>` implements the `Drop` trait
40+
|
41+
note: borrowed value must be valid for the anonymous lifetime #1 defined on the function body at 23:1...
42+
--> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:23:1
43+
|
44+
LL | / fn finish_3(s: S) -> &mut String {
45+
LL | | let p: &mut _ = s.url; p
46+
LL | | }
47+
| |_^
48+
49+
error[E0509]: cannot move out of type `S<'_>`, which implements the `Drop` trait
50+
--> $DIR/issue-52059-report-when-borrow-and-drop-conflict.rs:29:13
51+
|
52+
LL | let p = s.url; p
53+
| ^^^^^
54+
| |
55+
| cannot move out of here
56+
| help: consider borrowing here: `&s.url`
57+
58+
error: aborting due to 4 previous errors
59+
60+
Some errors occurred: E0509, E0713.
61+
For more information about an error, try `rustc --explain E0509`.

0 commit comments

Comments
 (0)