-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Misleading diagnostic for macro error!
when called with no parameters
#58796
Comments
|
Ran using
Getting the compiler to behave correctly in this case will be difficult, but making the macro itself handle this case and have an appropriate compile time error might be reasonable. What does @rust-lang/libs think? |
I opened rust-lang/log#322 to fix the problem on log's side. The compiler was largely doing the right thing and I consider it a problem with the way log's macro was written that resulted in a misleading error. There is something going wrong in the compiler here too though. Minimized: macro_rules! log {
($lvl:expr, $($arg:tt)+) => {}
}
fn main() {
log!(Level::Error ,);
} error: expected identifier, found `,`
--> src/main.rs:6:17
|
6 | log!(Level::Error ,);
| ^
| |
| expected identifier
| help: remove this comma The error points to something that is an identifier and says it expected an identifier 😞 and points to something that is not a comma and says remove this comma. 😢 |
I noticed that too. My guess is that it's just a token off by one error somewhere. |
@dtolnay I can confirm that that incorrect diagnostic is caused by #52397 :( It'd be the following without it
|
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
Be more discerning on when to attempt suggesting a comma in a macro invocation Fix rust-lang#58796.
When calling the macro with no arguments
error!()
:The diagnostic should instruct the user that a string literal is required as a parameter to the macro.
The text was updated successfully, but these errors were encountered: