Skip to content

Commit b3a1d56

Browse files
committed
Add code to incorrect pub restriction error
1 parent 09e42bc commit b3a1d56

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/libsyntax/diagnostic_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,5 @@ register_diagnostics! {
398398
E0693, // incorrect `repr(align)` attribute format
399399
E0694, // an unknown tool name found in scoped attributes
400400
E0697, // invalid ABI
401+
E0698, // incorrect visibility restriction
401402
}

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5986,12 +5986,13 @@ impl<'a> Parser<'a> {
59865986
`pub(super)`: visible only in the current module's parent
59875987
`pub(in path::to::module)`: visible only on the specified path"##;
59885988
let path = self.parse_path(PathStyle::Mod)?;
5989-
let path_span = self.prev_span;
5989+
let sp = self.prev_span;
59905990
let help_msg = format!("make this visible only to module `{}` with `in`", path);
59915991
self.expect(&token::CloseDelim(token::Paren))?; // `)`
5992-
let mut err = self.span_fatal_help(path_span, msg, suggestion);
5992+
let mut err = struct_span_err!(self.sess.span_diagnostic, sp, E0698, "{}", msg);
5993+
err.help(suggestion);
59935994
err.span_suggestion_with_applicability(
5994-
path_span, &help_msg, format!("in {}", path), Applicability::MachineApplicable
5995+
sp, &help_msg, format!("in {}", path), Applicability::MachineApplicable
59955996
);
59965997
err.emit(); // emit diagnostic, but continue with public visibility
59975998
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: incorrect visibility restriction
1+
error[E0698]: incorrect visibility restriction
22
--> $DIR/pub-restricted.rs:15:6
33
|
44
LL | pub (a) fn afn() {} //~ incorrect visibility restriction
@@ -9,7 +9,7 @@ LL | pub (a) fn afn() {} //~ incorrect visibility restriction
99
`pub(super)`: visible only in the current module's parent
1010
`pub(in path::to::module)`: visible only on the specified path
1111

12-
error: incorrect visibility restriction
12+
error[E0698]: incorrect visibility restriction
1313
--> $DIR/pub-restricted.rs:16:6
1414
|
1515
LL | pub (b) fn bfn() {} //~ incorrect visibility restriction
@@ -20,7 +20,7 @@ LL | pub (b) fn bfn() {} //~ incorrect visibility restriction
2020
`pub(super)`: visible only in the current module's parent
2121
`pub(in path::to::module)`: visible only on the specified path
2222

23-
error: incorrect visibility restriction
23+
error[E0698]: incorrect visibility restriction
2424
--> $DIR/pub-restricted.rs:32:14
2525
|
2626
LL | pub (a) invalid: usize, //~ incorrect visibility restriction
@@ -31,7 +31,7 @@ LL | pub (a) invalid: usize, //~ incorrect visibility restriction
3131
`pub(super)`: visible only in the current module's parent
3232
`pub(in path::to::module)`: visible only on the specified path
3333

34-
error: incorrect visibility restriction
34+
error[E0698]: incorrect visibility restriction
3535
--> $DIR/pub-restricted.rs:41:6
3636
|
3737
LL | pub (xyz) fn xyz() {} //~ incorrect visibility restriction
@@ -50,3 +50,4 @@ LL | pub (in x) non_parent_invalid: usize, //~ ERROR visibilities can on
5050

5151
error: aborting due to 5 previous errors
5252

53+
For more information about this error, try `rustc --explain E0698`.

0 commit comments

Comments
 (0)