Skip to content

Commit

Permalink
parse full visibility when recovering
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 17, 2019
1 parent b2b9555 commit 1aa43af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8623,11 +8623,15 @@ impl<'a> Parser<'a> {
/// Recover from `pub` keyword in places where it seems _reasonable_ but isn't valid.
fn eat_bad_pub(&mut self) {
if self.token.is_keyword(keywords::Pub) {
self.bump();
let mut err = self.diagnostic()
.struct_span_err(self.prev_span, "unnecessary visibility qualifier");
err.span_label(self.prev_span, "`pub` not permitted here");
err.emit();
match self.parse_visibility(false) {
Ok(vis) => {
let mut err = self.diagnostic()
.struct_span_err(vis.span, "unnecessary visibility qualifier");
err.span_label(vis.span, "`pub` not permitted here");
err.emit();
}
Err(mut err) => err.emit(),
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/issues/issue-28433.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
enum Bird {
pub Duck,
//~^ ERROR unnecessary visibility qualifier
Goose
Goose,
pub(crate) Dove
//~^ ERROR unnecessary visibility qualifier
}


Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-28433.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ error: unnecessary visibility qualifier
LL | pub Duck,
| ^^^ `pub` not permitted here

error: aborting due to previous error
error: unnecessary visibility qualifier
--> $DIR/issue-28433.rs:7:5
|
LL | pub(crate) Dove
| ^^^^^^^^^^ `pub` not permitted here

error: aborting due to 2 previous errors

0 comments on commit 1aa43af

Please sign in to comment.