mirror of https://github.com/rust-lang/rust.git
Add code to incorrect `pub` restriction error
This commit is contained in:
parent
09e42bcb10
commit
b3a1d56ebe
|
@ -398,4 +398,5 @@ register_diagnostics! {
|
|||
E0693, // incorrect `repr(align)` attribute format
|
||||
E0694, // an unknown tool name found in scoped attributes
|
||||
E0697, // invalid ABI
|
||||
E0698, // incorrect visibility restriction
|
||||
}
|
||||
|
|
|
@ -5986,12 +5986,13 @@ 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 path_span = self.prev_span;
|
||||
let sp = self.prev_span;
|
||||
let help_msg = format!("make this visible only to module `{}` with `in`", path);
|
||||
self.expect(&token::CloseDelim(token::Paren))?; // `)`
|
||||
let mut err = self.span_fatal_help(path_span, msg, suggestion);
|
||||
let mut err = struct_span_err!(self.sess.span_diagnostic, sp, E0698, "{}", msg);
|
||||
err.help(suggestion);
|
||||
err.span_suggestion_with_applicability(
|
||||
path_span, &help_msg, format!("in {}", path), Applicability::MachineApplicable
|
||||
sp, &help_msg, format!("in {}", path), Applicability::MachineApplicable
|
||||
);
|
||||
err.emit(); // emit diagnostic, but continue with public visibility
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
error: incorrect visibility restriction
|
||||
error[E0698]: incorrect visibility restriction
|
||||
--> $DIR/pub-restricted.rs:15:6
|
||||
|
|
||||
LL | pub (a) fn afn() {} //~ incorrect visibility restriction
|
||||
|
@ -9,7 +9,7 @@ LL | pub (a) fn afn() {} //~ incorrect visibility restriction
|
|||
`pub(super)`: visible only in the current module's parent
|
||||
`pub(in path::to::module)`: visible only on the specified path
|
||||
|
||||
error: incorrect visibility restriction
|
||||
error[E0698]: incorrect visibility restriction
|
||||
--> $DIR/pub-restricted.rs:16:6
|
||||
|
|
||||
LL | pub (b) fn bfn() {} //~ incorrect visibility restriction
|
||||
|
@ -20,7 +20,7 @@ LL | pub (b) fn bfn() {} //~ incorrect visibility restriction
|
|||
`pub(super)`: visible only in the current module's parent
|
||||
`pub(in path::to::module)`: visible only on the specified path
|
||||
|
||||
error: incorrect visibility restriction
|
||||
error[E0698]: incorrect visibility restriction
|
||||
--> $DIR/pub-restricted.rs:32:14
|
||||
|
|
||||
LL | pub (a) invalid: usize, //~ incorrect visibility restriction
|
||||
|
@ -31,7 +31,7 @@ LL | pub (a) invalid: usize, //~ incorrect visibility restriction
|
|||
`pub(super)`: visible only in the current module's parent
|
||||
`pub(in path::to::module)`: visible only on the specified path
|
||||
|
||||
error: incorrect visibility restriction
|
||||
error[E0698]: incorrect visibility restriction
|
||||
--> $DIR/pub-restricted.rs:41:6
|
||||
|
|
||||
LL | pub (xyz) fn xyz() {} //~ incorrect visibility restriction
|
||||
|
@ -50,3 +50,4 @@ LL | pub (in x) non_parent_invalid: usize, //~ ERROR visibilities can on
|
|||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0698`.
|
||||
|
|
Loading…
Reference in New Issue