Skip to content

Using doc comments where they aren't allowed should have a better error message #36946

Closed
@solson

Description

@solson

Code: playpen

fn main() {
    /// print to terminal
    println!("Hello, world!");
}

Error:

rustc 1.14.0-nightly (289f3a4ca 2016-09-29)
error: attributes on non-item statements and expressions are experimental. (see issue #15701)
 --> <anon>:2:5
  |
2 |     /// print to terminal
  |     ^^^^^^^^^^^^^^^^^^^^^

The current error message is pretty unfortunate for new users. Imagine someone saw /// everywhere and just assumed it was the comment syntax. Then they are presented with this weird error about attributes, items, statements, experimental features, and issue numbers, and all they wanted to do was comment their code! Many advanced users don't even know doc comments desugar to attributes in my experience.

Ideally we would detect this and print a help message suggesting the correct non-doc comment syntax.

cc @joshtriplett

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions