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

Non helpful error message when documenting with inner comment #30318

Closed
est31 opened this issue Dec 11, 2015 · 1 comment
Closed

Non helpful error message when documenting with inner comment #30318

est31 opened this issue Dec 11, 2015 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@est31
Copy link
Member

est31 commented Dec 11, 2015

This piece of code fails compilation (playbot):

use std::io;

//! This is a crate to say hello to the world

/// Main entry function
fn main() {
    println!("Hello, world!");
}

This is because the compiler expects inner comments only before the first item (something like this). It doesn't point this out however, instead, it gives the rather cryptic error message:

<anon>:3:1: 3:46 error: expected outer comment
<anon>:3 //! This is a crate to say hello to the world
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It should say something like "Please place the inner comment to the top".

From reading the code, an error message like this would be sufficient.

Can that be achieved by changing the if near line 38:

                if attr.node.style != ast::AttrStyle::Outer {
                  return Err(self.fatal("expected outer comment"));
                }

to something like

                match attr.node.style {
                  ast::AttrStyle::Inner => return Err(self.fatal("Expected outer comment. Inner comments are only allowed at the top, before any item.")),
                  ast::AttrStyle::Outer => (),
                  _ => return Err(self.fatal("expected outer comment")),
                }

? I haven't tested because I haven't set up a development setup of rustc (and don't know whether there is a better way to do it).

@est31
Copy link
Member Author

est31 commented Dec 11, 2015

It was suggested on irc to cc @nikomatsakis about this because its a bad error.

@huonw huonw added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 6, 2016
birkenfeld added a commit to birkenfeld/rust that referenced this issue May 3, 2016
bors added a commit that referenced this issue May 7, 2016
parser: show a helpful note on unexpected inner comment

Fixes: #30318.
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
Projects
None yet
Development

No branches or pull requests

2 participants