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

Wrong span/confusing error for comma in macro pattern #60233

Closed
oli-obk opened this issue Apr 24, 2019 · 1 comment · Fixed by #60248
Closed

Wrong span/confusing error for comma in macro pattern #60233

oli-obk opened this issue Apr 24, 2019 · 1 comment · Fixed by #60248
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Apr 24, 2019

I don't know what to make of this error.

use std::fmt::Debug;

macro_rules! check {
    ($ty:ty, $expected:expr) => {
        
    };
    ($ty_of:expr, $expected:expr) => {
        
    };
}

fn main() {
    check!(
        <str as Debug>::fmt,
        "foo",
    );
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: expected identifier, found `,`
  --> src/main.rs:14:16
   |
14 |         <str as Debug>::fmt,
   |                ^
   |                |
   |                expected identifier
   |                help: remove this comma

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

On stable (1.34) the output is

error: expected identifier, found `,`
  --> src/main.rs:14:25
   |
14 |         <str as Debug>::fmt,
   |                         ^
   |                         |
   |                         expected identifier
   |                         help: remove this comma
@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Apr 24, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 24, 2019
@estebank
Copy link
Contributor

I'm pretty sure this is fallout from the "missing comma here" suggestion for macros, that evaluates the macro again with the current arguments but adding a comma token in between the argument tokens in different combinations to see if it would be correct. My guess is that that is causing a parse error that doesn't happen for normal things than only have one token in them. We can disable the suggestion when fully qualified paths are involved.

bors added a commit that referenced this issue Apr 25, 2019
Add guard for missing comma in macro call suggestion

Fix #60233. Follow up to #58796.

r? @oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants