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

Account for paths in incorrect pub qualifier help #60429

Merged
merged 1 commit into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7276,7 +7276,9 @@ impl<'a> Parser<'a> {
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
// by the following tokens.
if self.look_ahead(1, |t| t.is_keyword(keywords::Crate)) {
if self.look_ahead(1, |t| t.is_keyword(keywords::Crate)) &&
self.look_ahead(2, |t| t != &token::ModSep) // account for `pub(crate::foo)`
{
// `pub(crate)`
self.bump(); // `(`
self.bump(); // `crate`
Expand Down Expand Up @@ -7319,7 +7321,7 @@ impl<'a> Parser<'a> {
`pub(super)`: visible only in the current module's parent
`pub(in path::to::module)`: visible only on the specified path"##;
let path = self.parse_path(PathStyle::Mod)?;
let sp = self.prev_span;
let sp = path.span;
let help_msg = format!("make this visible only to module `{}` with `in`", path);
self.expect(&token::CloseDelim(token::Paren))?; // `)`
let mut err = struct_span_err!(self.sess.span_diagnostic, sp, E0704, "{}", msg);
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/pub/pub-restricted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod a {}

pub (a) fn afn() {} //~ incorrect visibility restriction
pub (b) fn bfn() {} //~ incorrect visibility restriction
pub (crate::a) fn cfn() {} //~ incorrect visibility restriction

pub fn privfn() {}
mod x {
mod y {
Expand Down
19 changes: 15 additions & 4 deletions src/test/ui/pub/pub-restricted.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ LL | pub (b) fn bfn() {}
`pub(in path::to::module)`: visible only on the specified path

error[E0704]: incorrect visibility restriction
--> $DIR/pub-restricted.rs:22:14
--> $DIR/pub-restricted.rs:7:6
|
LL | pub (crate::a) fn cfn() {}
| ^^^^^^^^ help: make this visible only to module `crate::a` with `in`: `in crate::a`
|
= help: some possible 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This help text and suggestion don't trigger without this change.


error[E0704]: incorrect visibility restriction
--> $DIR/pub-restricted.rs:24:14
|
LL | pub (a) invalid: usize,
| ^ help: make this visible only to module `a` with `in`: `in a`
Expand All @@ -32,7 +43,7 @@ LL | pub (a) invalid: usize,
`pub(in path::to::module)`: visible only on the specified path

error[E0704]: incorrect visibility restriction
--> $DIR/pub-restricted.rs:31:6
--> $DIR/pub-restricted.rs:33:6
|
LL | pub (xyz) fn xyz() {}
| ^^^ help: make this visible only to module `xyz` with `in`: `in xyz`
Expand All @@ -43,10 +54,10 @@ LL | pub (xyz) fn xyz() {}
`pub(in path::to::module)`: visible only on the specified path

error: visibilities can only be restricted to ancestor modules
--> $DIR/pub-restricted.rs:23:17
--> $DIR/pub-restricted.rs:25:17
|
LL | pub (in x) non_parent_invalid: usize,
| ^

error: aborting due to 5 previous errors
error: aborting due to 6 previous errors