-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add diagnostic for incorrect pub (restriction)
#40627
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
2daec2f
to
280fd71
Compare
src/libsyntax/parse/parser.rs
Outdated
@@ -5102,6 +5103,29 @@ impl<'a> Parser<'a> { | |||
let vis = Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID }; | |||
self.expect(&token::CloseDelim(token::Paren))?; // `)` | |||
return Ok(vis) | |||
} else if self.look_ahead(0, |t| *t == token::Token::OpenDelim(token::Paren)) { |
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.
Looks like this is always true, we have already checked for (
in the outer condition.
Looks like |
19fd6b3
to
f682709
Compare
It's pretty chatty, but I admit it also looks very helpful. I'm good with it as a message. |
regarding the chattiness, do we really need to keep these two lines:
It seems like these cases are obvious enough, if one assumes that someone using parentheses after |
@pnkfelix that's a reasonable. I'll modify it tonight. |
If we're not going to make it an exhaustive listing, then I would change the heading text from "valid restrictions are" to "some example restrictions are" or something like that. |
The code looks good to me, modulo tweaking the message. I agree it's chatty but also that it seems helpful. |
src/libsyntax/parse/parser.rs
Outdated
@@ -5066,18 +5066,25 @@ impl<'a> Parser<'a> { | |||
fn parse_struct_decl_field(&mut self) -> PResult<'a, StructField> { | |||
let attrs = self.parse_outer_attributes()?; | |||
let lo = self.span.lo; | |||
let vis = self.parse_visibility()?; | |||
let vis = self.parse_visibility(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.
This is false
too.
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, that reminds me. Seems like we should have some tests exercising these paths (i.e., tests that would fail with this being 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.
Done and done.
src/libsyntax/parse/parser.rs
Outdated
@@ -5009,7 +5009,7 @@ impl<'a> Parser<'a> { | |||
|p| { | |||
let attrs = p.parse_outer_attributes()?; | |||
let lo = p.span.lo; | |||
let mut vis = p.parse_visibility()?; | |||
let mut vis = p.parse_visibility(true)?; | |||
let ty_is_interpolated = | |||
p.token.is_interpolated() || p.look_ahead(1, |t| t.is_interpolated()); | |||
let mut ty = p.parse_ty()?; |
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.
It's not fully on-topic, but could you remove all this cruft remaining from the old visibility syntax, I've missed it somehow.
It should be "parse_visibility
" -> "parse_ty
" -> "return the result" now, no extra magic.
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.
☔ The latest upstream changes (presumably #40043) made this pull request unmergeable. Please resolve the merge conflicts. |
4d89d2e
to
c93ccb5
Compare
LGTM, but couple of tests fail after rebase. |
c93ccb5
to
ce52345
Compare
Given the following statement ```rust pub (a) fn afn() {} ``` Provide the following diagnostic: ```rust error: incorrect restriction in `pub` --> file.rs:15:1 | 15 | pub (a) fn afn() {} | ^^^^^^^ | = help: some valid visibility restrictions are: `pub(crate)`: visible only on the current crate `pub(super)`: visible only in the current module's parent `pub(in path::to::module)`: visible only on the specified path help: to make this visible only to module `a`, add `in` before the path: | pub (in a) fn afn() {} ``` Remove cruft from old `pub(path)` syntax.
ce52345
to
769b95d
Compare
@petrochenkov fixed. |
@bors r+ |
📌 Commit 769b95d has been approved by |
…nkov Add diagnostic for incorrect `pub (restriction)` Given the following statement ```rust pub (a) fn afn() {} ``` Provide the following diagnostic: ```rust error: incorrect restriction in `pub` --> file.rs:15:1 | 15 | pub (a) fn afn() {} | ^^^ | = help: some valid visibility restrictions are: `pub(crate)`: visible only on the current crate `pub(super)`: visible only in the current module's parent `pub(in path::to::module)`: visible only on the specified path help: to make this visible only to module `a`, add `in` before the path: | pub (in a) fn afn() {} ``` Follow up to rust-lang#40340, fix rust-lang#40599, cc rust-lang#32409.
Given the following statement
Provide the following diagnostic:
Follow up to #40340, fix #40599, cc #32409.