Skip to content

Commit a3aafea

Browse files
committed
Account for paths in incorrect pub qualifier help
1 parent a55c2eb commit a3aafea

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/libsyntax/parse/parser.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7276,7 +7276,9 @@ impl<'a> Parser<'a> {
72767276
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
72777277
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
72787278
// by the following tokens.
7279-
if self.look_ahead(1, |t| t.is_keyword(keywords::Crate)) {
7279+
if self.look_ahead(1, |t| t.is_keyword(keywords::Crate)) &&
7280+
self.look_ahead(2, |t| t != &token::ModSep) // account for `pub(crate::foo)`
7281+
{
72807282
// `pub(crate)`
72817283
self.bump(); // `(`
72827284
self.bump(); // `crate`
@@ -7319,7 +7321,7 @@ impl<'a> Parser<'a> {
73197321
`pub(super)`: visible only in the current module's parent
73207322
`pub(in path::to::module)`: visible only on the specified path"##;
73217323
let path = self.parse_path(PathStyle::Mod)?;
7322-
let sp = self.prev_span;
7324+
let sp = path.span;
73237325
let help_msg = format!("make this visible only to module `{}` with `in`", path);
73247326
self.expect(&token::CloseDelim(token::Paren))?; // `)`
73257327
let mut err = struct_span_err!(self.sess.span_diagnostic, sp, E0704, "{}", msg);

src/test/ui/pub/pub-restricted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ mod a {}
44

55
pub (a) fn afn() {} //~ incorrect visibility restriction
66
pub (b) fn bfn() {} //~ incorrect visibility restriction
7+
pub (crate::a) fn cfn() {} //~ incorrect visibility restriction
8+
79
pub fn privfn() {}
810
mod x {
911
mod y {

src/test/ui/pub/pub-restricted.stderr

+15-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ LL | pub (b) fn bfn() {}
2121
`pub(in path::to::module)`: visible only on the specified path
2222

2323
error[E0704]: incorrect visibility restriction
24-
--> $DIR/pub-restricted.rs:22:14
24+
--> $DIR/pub-restricted.rs:7:6
25+
|
26+
LL | pub (crate::a) fn cfn() {}
27+
| ^^^^^^^^ help: make this visible only to module `crate::a` with `in`: `in crate::a`
28+
|
29+
= help: some possible visibility restrictions are:
30+
`pub(crate)`: visible only on the current crate
31+
`pub(super)`: visible only in the current module's parent
32+
`pub(in path::to::module)`: visible only on the specified path
33+
34+
error[E0704]: incorrect visibility restriction
35+
--> $DIR/pub-restricted.rs:24:14
2536
|
2637
LL | pub (a) invalid: usize,
2738
| ^ help: make this visible only to module `a` with `in`: `in a`
@@ -32,7 +43,7 @@ LL | pub (a) invalid: usize,
3243
`pub(in path::to::module)`: visible only on the specified path
3344

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

4556
error: visibilities can only be restricted to ancestor modules
46-
--> $DIR/pub-restricted.rs:23:17
57+
--> $DIR/pub-restricted.rs:25:17
4758
|
4859
LL | pub (in x) non_parent_invalid: usize,
4960
| ^
5061

51-
error: aborting due to 5 previous errors
62+
error: aborting due to 6 previous errors
5263

0 commit comments

Comments
 (0)