-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Doc comments present after a particular syntax error cause an unhelpful error message to be output. #48946
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @estebank (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. |
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.
Sorry for the delay in reviewing. Could you add a test for this case?
Also, could you rebase against master? We shouldn't submit PRs with merge commits in them.
src/libsyntax/parse/parser.rs
Outdated
&format!("expected `,`, or `}}`, found `{}`", current_token), | ||
"struct fields should be separated by commas"); | ||
err.emit(); | ||
return Err(comma_err); | ||
} | ||
} |
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.
Could you add a test in src/test/ui
for this case?
struct S {
x: u8
/// The id of the parent core
y: u8,
}
src/libsyntax/parse/parser.rs
Outdated
&format!("expected `,`, or `}}`, found `{}`", current_token), | ||
"struct fields should be separated by commas"); | ||
err.emit(); | ||
return Err(comma_err); |
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.
I'm not convinced that this code will perform the expected behavior. current_token
would, if I'm reading this correctly, be the doc comment.
I think that what you'd want to do is keep a mut seen_comma: bool
that gets set to true either if self.token
is Comma
or if the comma is eat
en after consuming the doc comment. If that happens, then you perform the logic in the else
branch above. Makes sense?
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.
@estebank : If we are inside token::DocComment(_)
block instead of token::Comma
then it means current token is not comma
but doc
, from here we can imply that comma
is missing between doc comment
and struct field
and if next token is not comma
then we are going inside else
block, this is where, we are emitting comma missing message
. This is my current approach, I will go with your approach because that looks much cleaner version :)
Now problem is my testcase is failing because of unknown reasons. Problem is test case will fail even if we write testcase for default
block of switch case
. Any tips how I can fix my testcase?
Let me know if I am getting all this wrong :)
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.
The test is failing due to missing whitespace in the missing main error:
[00:43:14]
[00:43:14] ---- [ui] ui/issue-48636.rs stdout ----
[00:43:14] diff of stderr:
[00:43:14]
[00:43:14] 15 = help: struct fields should be separated by commas
[00:43:14] 16
[00:43:14] 17 error[E0601]: `main` function not found in crate `issue_48636`
[00:43:14] - |
[00:43:14] - = note: consider adding a `main` function to `$DIR/issue-48636.rs`
[00:43:14] + |
[00:43:14] + = note: consider adding a `main` function to `$DIR/issue-48636.rs`
[00:43:14] 20
[00:43:14] 21 error: aborting due to 3 previous errors
[00:43:14] 22
Add an empty fn main() {}
in the file so that we reduce the amount of text in the stderr
file only to the relevant diagnostic. Also, you'll have to annotate the rs
test file with a comment in line 16 as follows:
//~^^^ ERROR found a documentation comment that doesn't document anything
Each ^
makes the check happen one line up, and then it just matches the text against the diagnostics emitted.
074cfe0
to
d9a9ead
Compare
Ping from triage, @PramodBisht ! Looks like your new test is causing a build failure:
|
@shepmaster will check that today or tomorrow, I could not pick this up because of bandwidth issue. Sorry for the delay. |
Weekly ping from triage, @PramodBisht ! Are you still actively working on this issue? |
@shepmaster sorry for the delay, I will work on this during a weekend. |
src/libsyntax/parse/parser.rs
Outdated
self.bump(); // consume the doc comment | ||
if self.eat(&token::Comma) || self.token == token::CloseDelim(token::Brace) { | ||
err.emit(); | ||
} else { | ||
return Err(err); | ||
let mut comma_err = self.span_fatal_help(current_span, | ||
&format!("expected `,`, or `}}`, found `{}`", current_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.
current_token
could be a really long doc string, use instead the token description.
src/test/ui/issue-48636.stderr
Outdated
LL | /// The id of the parent core | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: struct fields should be separated by commas |
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.
I feel that in this case the desired full output would be:
error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/issue-48636.rs:13:5
|
LL | x: u8
| - help: missing comma here: `,`
LL | /// The id of the parent core
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: doc comments must come before what they document, maybe a comment was intended with `//`?
using a span_suggestion
.
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.
done!
ac68aa1
to
f72a756
Compare
@estebank could you review again? |
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.
Looking great! Just one last change needed.
src/libsyntax/parse/parser.rs
Outdated
err.emit(); | ||
} else { | ||
if seen_comma== false { | ||
err.span_suggestion(previous_span, "missing comma here: `,`", "".into()); |
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 should be
err.span_suggestion(sp, "missing comma here", ",".into());
The output will be the same, but now third party tools, like VSCode can apply the suggestion.
sp
should be the result of calling codemap.next_point(previous_span)
, otherwise it is pointing at the type, instead of pointing after the type, where the comma is supposed to be.
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.
done
src/libsyntax/parse/parser.rs
Outdated
let comma_after_doc_seen = self.eat(&token::Comma); | ||
// `seen_comma` is always false, because we are inside doc block | ||
// condition is here to make code more readable | ||
if seen_comma == false && comma_after_doc_seen == true{ |
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.
missing space before the brace
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.
done!
src/libsyntax/parse/parser.rs
Outdated
err.emit(); | ||
} else { | ||
if seen_comma== false { |
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.
missing space before the ==
.
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.
done!
src/test/ui/issue-48636.stderr
Outdated
--> $DIR/issue-48636.rs:13:5 | ||
| | ||
LL | x: u8 | ||
| -- help: missing comma here: `,` |
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.
As pointed out above, this suggestion should be pointing at the span after u8
.
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.
fixed!
2) Changed position of help message, incase comma is missing 3) added few missing spaces and handled span_suggestion for vscode 4) updated stderr file
acdf2ce
to
1bed654
Compare
@estebank could you please check again? |
@bors r+ rollup |
📌 Commit 1bed654 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
fixed: #48636
r? @estebank