Skip to content

Commit 99a0477

Browse files
committed
Add test for closure migration with a macro body.
1 parent 945a4b1 commit 99a0477

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-rustfix
2+
3+
// See https://github.com/rust-lang/rust/issues/87955
4+
5+
#![deny(rust_2021_incompatible_closure_captures)]
6+
//~^ NOTE: the lint level is defined here
7+
8+
fn main() {
9+
let a = ("hey".to_string(), "123".to_string());
10+
let _ = || { let _ = &a; dbg!(a.0) };
11+
//~^ ERROR: drop order
12+
//~| NOTE: only captures `a.0`
13+
//~| NOTE: for more information, see
14+
//~| HELP: add a dummy let to cause `a` to be fully captured
15+
}
16+
//~^ NOTE: dropped here
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-rustfix
2+
3+
// See https://github.com/rust-lang/rust/issues/87955
4+
5+
#![deny(rust_2021_incompatible_closure_captures)]
6+
//~^ NOTE: the lint level is defined here
7+
8+
fn main() {
9+
let a = ("hey".to_string(), "123".to_string());
10+
let _ = || dbg!(a.0);
11+
//~^ ERROR: drop order
12+
//~| NOTE: only captures `a.0`
13+
//~| NOTE: for more information, see
14+
//~| HELP: add a dummy let to cause `a` to be fully captured
15+
}
16+
//~^ NOTE: dropped here
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: changes to closure capture in Rust 2021 will affect drop order
2+
--> $DIR/macro.rs:10:13
3+
|
4+
LL | let _ = || dbg!(a.0);
5+
| ^^^^^^^^---^
6+
| |
7+
| in Rust 2018, closure captures all of `a`, but in Rust 2021, it only captures `a.0`
8+
...
9+
LL | }
10+
| - in Rust 2018, `a` would be dropped here, but in Rust 2021, only `a.0` would be dropped here alongside the closure
11+
|
12+
note: the lint level is defined here
13+
--> $DIR/macro.rs:5:9
14+
|
15+
LL | #![deny(rust_2021_incompatible_closure_captures)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
18+
help: add a dummy let to cause `a` to be fully captured
19+
|
20+
LL | let _ = || { let _ = &a; dbg!(a.0) };
21+
| ~~~~~~~~~~~~~~~~~~~~~~~~~
22+
23+
error: aborting due to previous error
24+

0 commit comments

Comments
 (0)