// `()` 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`
`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);
`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
+
+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`
`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`
`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