Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust_2021_incompatible_closure_captures suggestion expands macro #87955

Closed
m-ou-se opened this issue Aug 12, 2021 · 2 comments · Fixed by #87956
Closed

rust_2021_incompatible_closure_captures suggestion expands macro #87955

m-ou-se opened this issue Aug 12, 2021 · 2 comments · Fixed by #87956
Assignees
Labels
A-closures Area: Closures (`|…| { … }`) D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.

Comments

@m-ou-se
Copy link
Member

m-ou-se commented Aug 12, 2021

#![warn(rust_2021_incompatible_closure_captures)]

fn main() {
    let a = ("hey".to_string(), "123".to_string());
    let _ = || dbg!(a.0);
}

produces:

help: add a dummy let to cause `a` to be fully captured
  |
29~         { let _ = &a; match $val {
29+             tmp => {
29+                 $crate::eprintln!("[{}:{}] {} = {:#?}",
30+                     $crate::file!(), $crate::line!(), $crate::stringify!($val), &tmp);
30+                 tmp
30+             }
...

It expanded the dbg!() macro. This only happens when the macro invocation is the entire body of the closure.

@m-ou-se m-ou-se added A-closures Area: Closures (`|…| { … }`) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-edition Diagnostics: An error or lint that should account for edition differences. labels Aug 12, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Aug 12, 2021

cc @rust-lang/wg-rfc-2229

@m-ou-se m-ou-se self-assigned this Aug 12, 2021
@m-ou-se
Copy link
Member Author

m-ou-se commented Aug 12, 2021

Working on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant