-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Trying to show reasonable errors for trailing doc comments... #30025
Conversation
r? @Manishearth |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
if let token::DocComment(_) = p.token { | ||
// bump again if the token's a trailing doc comment | ||
if p.look_ahead(1, |t| *t == token::CloseDelim(token::Brace)) { | ||
try!(p.bump()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the whole thing's going on. We could either bump the parser, so that it neglects this "event" (which I've done now), or we could span an error here.
r? @eddyb or some other parser person |
I really hoped that I could fix this elsewhere, but while parsing the trait, we're filling the parser's I also guess that the real issue is behind |
|
||
trait Boom { | ||
fn kaboom(); | ||
/// This comment shouldn't throw an error! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why doesn't this throw an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, whoops, it should. The goal I had at first was to not throw an error :)
I'll have a closer look at the PR later, but you need review from someone more familiar with the parser than I 😄 |
} | ||
token::Semi => { | ||
try!(p.bump()); | ||
if let token::DocComment(_) = p.token { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You likely want some sort of loop, because lexer may emit multiple DocComment
in a row.
That being said… I do not think lookahead is the correct way or this is the place to do this kind of thing. Lets see what other people have to say about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you think it is the best way to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While look ahead would be a viable approach if you were guaranteed to only get a single DocComment
token, it doesn’t work here, because you effectively have to do infinite look-ahead now. This also is a very uncommonly used strategy in our parser: we just parse ahead and figure out what’s wrong when we hit a token we do not expect. I believe it should be possible to do the same in this situation as well.
This seems to only address the issue for trait items, not for top-level items or impl items (or I guess doc comments in random positions, like inside a struct). |
Seems like a better approach (as you kind of suggest earlier) is for real_token to skip doc comments unless they're specifically asked for, but issue a warning or error if one is encountered unexpectedly. |
5ceef86
to
c620c5e
Compare
So, I'll summarize the problem I'm experiencing right now.
Even if we add a flag to the parser to ignore the doc comments all the time (except those areas checked by the lint), the problem remains unchanged (except that it will be a "when to enable the doc comments check" instead of "when to ignore them"). Any ideas people? |
c620c5e
to
f9a725f
Compare
☔ The latest upstream changes (presumably #30654) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing due to inactivity, but feel free to resubmit with a rebase! |
fixes #2789