-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Detect ;
-> ,
typo on vec!["_", 10]
#80173
Comments
Is it possible to do this in a declarative macro? I wonder if we could have a "peephole warning/suggestion generator" for this kind of thing where we pattern match in terms in different contexts (e.g. types, expressions, items, perhaps with the errors in the spans) and suggest alternatives. |
Today it is possible to do this in a proc-macro (by explicitly looking for cases), and in the compiler ( Edit before submitting: Actually, this has to be in the compiler because macros do not have access to the type information, which you need to properly handle this. The first field can be anything that is |
@estebank Would this help message only be emitted when the code fails and/or when the program compiles successfully (if there is a way to do such a thing)? |
Only on error. The only "suspect" cases would be like |
@rustbot claim |
@estebank Do you know roughly where I need to search for cases such as this one? Thanks |
@rustbot claim |
vec!["_", 10]
;
-> ,
typo on vec!["_", 10]
…gillot Suggest Replacing Comma with Semicolon in Incorrect Repeat Expressions Fixes rust-lang#80173 This PR detects typos in repeat expressions like `["_", 10]` and `vec![String::new(), 10]` and suggests replacing comma with semicolon. Also, improves code in other place by adding doc comments and making use of a helper function to check if a type implements `Clone`. References: 1. For `vec![T; N]`: https://doc.rust-lang.org/std/macro.vec.html 2. For `[T; N]`: https://doc.rust-lang.org/std/primitive.array.html
Rollup merge of rust-lang#128110 - veera-sivarajan:bugfix-80173, r=cjgillot Suggest Replacing Comma with Semicolon in Incorrect Repeat Expressions Fixes rust-lang#80173 This PR detects typos in repeat expressions like `["_", 10]` and `vec![String::new(), 10]` and suggests replacing comma with semicolon. Also, improves code in other place by adding doc comments and making use of a helper function to check if a type implements `Clone`. References: 1. For `vec![T; N]`: https://doc.rust-lang.org/std/macro.vec.html 2. For `[T; N]`: https://doc.rust-lang.org/std/primitive.array.html
Only when writing
vec!["_", 10]
we could suggest replacing the,
with;
.The text was updated successfully, but these errors were encountered: