-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Suggest comma when writing println!("{}" a);
#52397
Conversation
println!("{}" a);
println!("{}" a);
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
println!("{}" a);
println!("{}" a);
src/libsyntax/tokenstream.rs
Outdated
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream` | ||
/// separating the two arguments with a comma for diagnostic suggestions. | ||
pub(crate) fn add_comma(&self) -> Option<(TokenStream, Span)> { | ||
// Used ot suggest if a user writes `println!("{}" a);` |
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.
ot -> to
src/libsyntax/tokenstream.rs
Outdated
pub(crate) fn add_comma(&self) -> Option<(TokenStream, Span)> { | ||
// Used ot suggest if a user writes `println!("{}" a);` | ||
if let TokenStreamKind::Stream(ref slice) = self.kind { | ||
if slice.len() == 2 { |
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.
So this doesn't work for println!("{} {}" a, b);
or println!("{} {}", a b);
?
If it does work, please add tests, if it does not work, would it be a lot of effort to fix that?
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.
The further we go from the "{}" a
case, the less likely we're to find a suitable fix by just checking against comma separated list. Having said that, making sure that every element is separated by commas should be easy to add.
r? @oli-obk Advanced mode: Can we ask the macro matcher how far each arm got and suggest the next possible matches in the spirit of "expected one of |
@oli-obk that sounds interesting to do... I'll look into it this week. |
Ping from triage @estebank! It's been a while since we heard from you, will you have time to work on this again? |
@pietroalbini will do soonish. @oli-obk I tried to get this for arbitrary sequences (finding a missing comma that is not the first one) and it was a bit more involved than I anticipated. I need to regroup and write a generalized version, but I feel like we could land this very specific one in the meantime, after I fix the typo. |
Sgtm |
Fixed the typo. |
@bors r+ |
📌 Commit c4b7b1eec4ea0b354bce8c1fb417598b63710966 has been approved by |
This comment has been minimized.
This comment has been minimized.
@bors r- gonna rebase against master, it's probably stale |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - status-travis |
This comment has been minimized.
This comment has been minimized.
@bors retry |
⌛ Testing commit daa5bd3 with merge 80be6b8e7f9b40181807bb6ea7afb5e856f7a1d0... |
💔 Test failed - status-travis |
This comment has been minimized.
This comment has been minimized.
@bors retry |
Suggest comma when writing `println!("{}" a);` Fix #49370.
☀️ Test successful - status-appveyor, status-travis |
This is awesome! Thank you for doing this! I'm the one who filed the original issue about it and I really appreciate that it was fixed. 😁 |
Suggest comma when missing in macro call When missing a comma in a macro call, suggest it, regardless of position. When a macro call doesn't match any of the patterns, check if the call's token stream could be missing a comma between two idents, and if so, create a new token stream containing the comma and try to match against the macro patterns. If successful, emit the suggestion. This works on arbitrary macros, with no need of special support from the macro writers. ``` error: no rules expected the token `d` --> $DIR/missing-comma.rs:26:18 | LL | foo!(a, b, c d, e); | -^ | | | help: missing comma here ``` Follow up to rust-lang#52397.
Suggest comma when missing in macro call When missing a comma in a macro call, suggest it, regardless of position. When a macro call doesn't match any of the patterns, check if the call's token stream could be missing a comma between two idents, and if so, create a new token stream containing the comma and try to match against the macro patterns. If successful, emit the suggestion. This works on arbitrary macros, with no need of special support from the macro writers. ``` error: no rules expected the token `d` --> $DIR/missing-comma.rs:26:18 | LL | foo!(a, b, c d, e); | -^ | | | help: missing comma here ``` Follow up to rust-lang#52397.
Suggest comma when missing in macro call When missing a comma in a macro call, suggest it, regardless of position. When a macro call doesn't match any of the patterns, check if the call's token stream could be missing a comma between two idents, and if so, create a new token stream containing the comma and try to match against the macro patterns. If successful, emit the suggestion. This works on arbitrary macros, with no need of special support from the macro writers. ``` error: no rules expected the token `d` --> $DIR/missing-comma.rs:26:18 | LL | foo!(a, b, c d, e); | -^ | | | help: missing comma here ``` Follow up to rust-lang#52397.
Suggest comma when missing in macro call When missing a comma in a macro call, suggest it, regardless of position. When a macro call doesn't match any of the patterns, check if the call's token stream could be missing a comma between two idents, and if so, create a new token stream containing the comma and try to match against the macro patterns. If successful, emit the suggestion. This works on arbitrary macros, with no need of special support from the macro writers. ``` error: no rules expected the token `d` --> $DIR/missing-comma.rs:26:18 | LL | foo!(a, b, c d, e); | -^ | | | help: missing comma here ``` Follow up to rust-lang#52397.
Fix #49370.