-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #87956 - m-ou-se:closure-migration-macro-body, r=Aaron1011
Fix closure migration suggestion when the body is a macro. Fixes #87955 Before: ``` warning: changes to closure capture in Rust 2021 will affect drop order --> src/main.rs:5:13 | 5 | let _ = || panic!(a.0); | ^^^^^^^^^^---^ | | | in Rust 2018, closure captures all of `a`, but in Rust 2021, it only captures `a.0` 6 | } | - in Rust 2018, `a` would be dropped here, but in Rust 2021, only `a.0` would be dropped here alongside the closure | help: add a dummy let to cause `a` to be fully captured | 20~ ($msg:expr $(,)?) => ({ let _ = &a; 21+ $crate::rt::begin_panic($msg) 22~ }), | ``` After: ``` warning: changes to closure capture in Rust 2021 will affect drop order --> src/main.rs:5:13 | 5 | let _ = || panic!(a.0); | ^^^^^^^^^^---^ | | | in Rust 2018, closure captures all of `a`, but in Rust 2021, it only captures `a.0` 6 | } | - in Rust 2018, `a` would be dropped here, but in Rust 2021, only `a.0` would be dropped here alongside the closure | help: add a dummy let to cause `a` to be fully captured | 5 | let _ = || { let _ = &a; panic!(a.0) }; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
- Loading branch information
Showing
4 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/ui/closures/2229_closure_analysis/migrations/macro.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
|
||
// See https://github.com/rust-lang/rust/issues/87955 | ||
|
||
#![deny(rust_2021_incompatible_closure_captures)] | ||
//~^ NOTE: the lint level is defined here | ||
|
||
fn main() { | ||
let a = ("hey".to_string(), "123".to_string()); | ||
let _ = || { let _ = &a; dbg!(a.0) }; | ||
//~^ ERROR: drop order | ||
//~| NOTE: only captures `a.0` | ||
//~| NOTE: for more information, see | ||
//~| HELP: add a dummy let to cause `a` to be fully captured | ||
} | ||
//~^ NOTE: dropped here |
16 changes: 16 additions & 0 deletions
16
src/test/ui/closures/2229_closure_analysis/migrations/macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
|
||
// See https://github.com/rust-lang/rust/issues/87955 | ||
|
||
#![deny(rust_2021_incompatible_closure_captures)] | ||
//~^ NOTE: the lint level is defined here | ||
|
||
fn main() { | ||
let a = ("hey".to_string(), "123".to_string()); | ||
let _ = || dbg!(a.0); | ||
//~^ ERROR: drop order | ||
//~| NOTE: only captures `a.0` | ||
//~| NOTE: for more information, see | ||
//~| HELP: add a dummy let to cause `a` to be fully captured | ||
} | ||
//~^ NOTE: dropped here |
24 changes: 24 additions & 0 deletions
24
src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: changes to closure capture in Rust 2021 will affect drop order | ||
--> $DIR/macro.rs:10:13 | ||
| | ||
LL | let _ = || dbg!(a.0); | ||
| ^^^^^^^^---^ | ||
| | | ||
| in Rust 2018, closure captures all of `a`, but in Rust 2021, it only captures `a.0` | ||
... | ||
LL | } | ||
| - in Rust 2018, `a` would be dropped here, but in Rust 2021, only `a.0` would be dropped here alongside the closure | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/macro.rs:5:9 | ||
| | ||
LL | #![deny(rust_2021_incompatible_closure_captures)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html> | ||
help: add a dummy let to cause `a` to be fully captured | ||
| | ||
LL | let _ = || { let _ = &a; dbg!(a.0) }; | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|