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

Commenting a macro branch throws a misleading diagnostic #92846

Closed
Patryk27 opened this issue Jan 13, 2022 · 0 comments · Fixed by #98882
Closed

Commenting a macro branch throws a misleading diagnostic #92846

Patryk27 opened this issue Jan 13, 2022 · 0 comments · Fixed by #98882
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Patryk27
Copy link
Contributor

Patryk27 commented Jan 13, 2022

Commenting a macro branch:

macro_rules! something {
    /// This macro branch expands to nottin'
    () => { }
}

(https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=425968561ccf8122bba35a7396e2d5dd)

... throws an error:

error: no rules expected the token `[`
 --> src/lib.rs:...:...
  |
  |     /// This macro branch expands to nottin'
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no rules expected this token in macro call

Now, this error message makes sense if you think of /// as a shorthand for #[doc = "..."], but imho it'd be better to print something in terms of:

error: macro branches can't have outer-line documentation
 --> src/lib.rs:...:...
  |
  |     /// This macro branch expands to nottin'
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `///` is an outer-line documentation

hint: either move the comment before the macro:

    /// This macro branch expands to nottin'
    macro_rules! something {
        () => { }
    }

hint: ... or replace `///` with `//`:

    macro_rules! something {
        // This macro branch expands to nottin'
        () => { }
    }
@Patryk27 Patryk27 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 13, 2022
@Patryk27 Patryk27 changed the title Commeting a macro branch throws a misleading diagnostic Commenting a macro branch throws a misleading diagnostic Jan 13, 2022
@TaKO8Ki TaKO8Ki self-assigned this Jan 22, 2022
@TaKO8Ki TaKO8Ki removed their assignment Jun 1, 2022
@bors bors closed this as completed in 9431520 Jul 11, 2022
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 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.

2 participants