Recover from incorrect pub kw in "reasonable" places
This commit is contained in:
parent
532dd4475b
commit
b2b9555f95
9 changed files with 26 additions and 40 deletions
|
|
@ -1524,7 +1524,7 @@ impl<'a> Parser<'a> {
|
|||
at_end: &mut bool,
|
||||
mut attrs: Vec<Attribute>) -> PResult<'a, TraitItem> {
|
||||
let lo = self.span;
|
||||
|
||||
self.eat_bad_pub();
|
||||
let (name, node, generics) = if self.eat_keyword(keywords::Type) {
|
||||
self.parse_trait_item_assoc_ty()?
|
||||
} else if self.is_const_item() {
|
||||
|
|
@ -7680,6 +7680,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let struct_def;
|
||||
let mut disr_expr = None;
|
||||
self.eat_bad_pub();
|
||||
let ident = self.parse_ident()?;
|
||||
if self.check(&token::OpenDelim(token::Brace)) {
|
||||
// Parse a struct variant.
|
||||
|
|
@ -8618,6 +8619,17 @@ impl<'a> Parser<'a> {
|
|||
Applicability::MaybeIncorrect,
|
||||
).emit();
|
||||
}
|
||||
|
||||
/// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedBrace>, handler: &errors::Handler) {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
enum Bird {
|
||||
pub Duck,
|
||||
//~^ ERROR expected identifier, found keyword `pub`
|
||||
//~| ERROR missing comma
|
||||
//~| WARN variant `pub` should have an upper camel case name
|
||||
//~^ ERROR unnecessary visibility qualifier
|
||||
Goose
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,26 +1,8 @@
|
|||
error: expected identifier, found keyword `pub`
|
||||
error: unnecessary visibility qualifier
|
||||
--> $DIR/issue-28433.rs:4:5
|
||||
|
|
||||
LL | pub Duck,
|
||||
| ^^^ expected identifier, found keyword
|
||||
help: you can escape reserved keywords to use them as identifiers
|
||||
|
|
||||
LL | r#pub Duck,
|
||||
| ^^^^^
|
||||
| ^^^ `pub` not permitted here
|
||||
|
||||
error: missing comma
|
||||
--> $DIR/issue-28433.rs:4:8
|
||||
|
|
||||
LL | pub Duck,
|
||||
| ^ help: missing comma
|
||||
|
||||
warning: variant `pub` should have an upper camel case name
|
||||
--> $DIR/issue-28433.rs:4:5
|
||||
|
|
||||
LL | pub Duck,
|
||||
| ^^^ help: convert the identifier to upper camel case: `Pub`
|
||||
|
|
||||
= note: #[warn(non_camel_case_types)] on by default
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
trait Foo {
|
||||
pub const Foo: u32;
|
||||
//~^ ERROR expected one of `async`, `const`, `extern`, `fn`, `type`, `unsafe`, or `}`, found
|
||||
//~^ ERROR unnecessary visibility qualifier
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
error: expected one of `async`, `const`, `extern`, `fn`, `type`, `unsafe`, or `}`, found `pub`
|
||||
error: unnecessary visibility qualifier
|
||||
--> $DIR/trait-pub-assoc-const.rs:2:5
|
||||
|
|
||||
LL | trait Foo {
|
||||
| - expected one of 7 possible tokens here
|
||||
LL | pub const Foo: u32;
|
||||
| ^^^ unexpected token
|
||||
| ^^^ `pub` not permitted here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
trait Foo {
|
||||
pub type Foo;
|
||||
//~^ ERROR expected one of `async`, `const`, `extern`, `fn`, `type`, `unsafe`, or `}`, found
|
||||
//~^ ERROR unnecessary visibility qualifier
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
error: expected one of `async`, `const`, `extern`, `fn`, `type`, `unsafe`, or `}`, found `pub`
|
||||
error: unnecessary visibility qualifier
|
||||
--> $DIR/trait-pub-assoc-ty.rs:2:5
|
||||
|
|
||||
LL | trait Foo {
|
||||
| - expected one of 7 possible tokens here
|
||||
LL | pub type Foo;
|
||||
| ^^^ unexpected token
|
||||
| ^^^ `pub` not permitted here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
trait Foo {
|
||||
pub fn foo();
|
||||
//~^ ERROR expected one of `async`, `const`, `extern`, `fn`, `type`, `unsafe`, or `}`, found
|
||||
//~^ ERROR unnecessary visibility qualifier
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
error: expected one of `async`, `const`, `extern`, `fn`, `type`, `unsafe`, or `}`, found `pub`
|
||||
error: unnecessary visibility qualifier
|
||||
--> $DIR/trait-pub-method.rs:2:5
|
||||
|
|
||||
LL | trait Foo {
|
||||
| - expected one of 7 possible tokens here
|
||||
LL | pub fn foo();
|
||||
| ^^^ unexpected token
|
||||
| ^^^ `pub` not permitted here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue