Skip to content

Commenting a macro branch throws a misleading diagnostic #92846

Closed
@Patryk27

Description

@Patryk27

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'
        () => { }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions