parse full visibility when recovering

This commit is contained in:
Esteban Küber 2019-03-09 15:14:22 -08:00
parent b2b9555f95
commit 1aa43af370
3 changed files with 19 additions and 7 deletions

View File

@ -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(),
}
}
}
}

View File

@ -3,7 +3,9 @@
enum Bird {
pub Duck,
//~^ ERROR unnecessary visibility qualifier
Goose
Goose,
pub(crate) Dove
//~^ ERROR unnecessary visibility qualifier
}

View File

@ -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