-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve closure dummy capture suggestion in macros. #88543
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve closure dummy capture suggestion in macros. #88543
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @estebank |
--> $DIR/closure-body-macro-fragment.rs:8:17 | ||
| | ||
LL | let f = || $body; | ||
| _________________^ | ||
LL | | | ||
LL | | f(); | ||
LL | | }}; | ||
| | - in Rust 2018, `a` is dropped here, but in Rust 2021, only `a.0` will be dropped here as part of the closure | ||
LL | | ($body:block) => {{ | ||
LL | | m!(@ $body); | ||
| |__________________^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's... an unfortunate span.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, some weird things are going on when mixing :block
and :expr
fragments. And closures just use their first and last token to create their full span, which isn't always great. Something to improve another time. ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh aboslutely, mixed spans involving macros have long standing issues :)
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: add a dummy let to cause `a` to be fully captured | ||
| | ||
LL ~ m!({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm intrigued at why this line is shown to have a change. The correct fix might be changing the suggestion printing machinery to verify that before and after are actually different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It got a \n
appended to it. I'm using the span at the end of this line to add a "\n let _ = .."
suggestion. I guess the \n
is counted as part of this line.
@bors r+ |
📌 Commit 7d18052 has been approved by |
|
||
if let Ok(mut s) = self.tcx.sess.source_map().span_to_snippet(closure_body_span) { | ||
if s.starts_with('$') { | ||
// Looks like a macro fragment. Try to find the real block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should we walk up the backtrace in the expansion instead of this? I guess this works, I'm thinking to think if there is some kind of "catch".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We track things like "1
is expanded from foo!()
" (which was and is already used here), but we don't track "1
was substituted from $a
", which is sort-of the opposite, and the problem here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see.
…ck-fragment, r=estebank Improve closure dummy capture suggestion in macros. Fixes some cases of rust-lang#88440 Fixes https://crater-reports.s3.amazonaws.com/pr-87190-3/try%23a7a572ce3edd6d476191fbfe92c9c1986e009b34/reg/rcodec-1.0.1/log.txt
…ck-fragment, r=estebank Improve closure dummy capture suggestion in macros. Fixes some cases of rust-lang#88440 Fixes https://crater-reports.s3.amazonaws.com/pr-87190-3/try%23a7a572ce3edd6d476191fbfe92c9c1986e009b34/reg/rcodec-1.0.1/log.txt
…ck-fragment, r=estebank Improve closure dummy capture suggestion in macros. Fixes some cases of rust-lang#88440 Fixes https://crater-reports.s3.amazonaws.com/pr-87190-3/try%23a7a572ce3edd6d476191fbfe92c9c1986e009b34/reg/rcodec-1.0.1/log.txt
Rollup of 12 pull requests Successful merges: - rust-lang#88177 (Stabilize std::os::unix::fs::chroot) - rust-lang#88505 (Use `unwrap_unchecked` where possible) - rust-lang#88512 (Upgrade array_into_iter lint to include Deref-to-array types.) - rust-lang#88532 (Remove single use variables) - rust-lang#88543 (Improve closure dummy capture suggestion in macros.) - rust-lang#88560 (`fmt::Formatter::pad`: don't call chars().count() more than one time) - rust-lang#88565 (Add regression test for issue 83190) - rust-lang#88567 (Remove redundant `Span` in `QueryJobInfo`) - rust-lang#88573 (rustdoc: Don't panic on ambiguous inherent associated types) - rust-lang#88582 (Implement rust-lang#88581) - rust-lang#88589 (Correct doc comments inside `use_expr_visitor.rs`) - rust-lang#88592 (Fix ICE in const check) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes some cases of #88440
Fixes https://crater-reports.s3.amazonaws.com/pr-87190-3/try%23a7a572ce3edd6d476191fbfe92c9c1986e009b34/reg/rcodec-1.0.1/log.txt