parser: tweak unmatched wording
This commit is contained in:
parent
d446c73e6a
commit
ab84914fe4
src
librustc_parse/parser
test/ui
parser
default-unmatched-assoc.rsdefault-unmatched-assoc.stderrdefault-unmatched-extern.rsdefault-unmatched-extern.stderrdefault-unmatched.rsdefault-unmatched.stderrdefault.rsdefault.stderrduplicate-visibility.rsduplicate-visibility.stderrimpl-parsing.rsimpl-parsing.stderrissue-41155.rsissue-41155.stderr
pub
@ -119,17 +119,18 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
let vs = pprust::vis_to_string(&vis);
|
let vs = pprust::vis_to_string(&vis);
|
||||||
let vs = vs.trim_end();
|
let vs = vs.trim_end();
|
||||||
self.struct_span_err(vis.span, &format!("unmatched visibility `{}`", vs))
|
self.struct_span_err(vis.span, &format!("visibility `{}` not followed by an item", vs))
|
||||||
.span_label(vis.span, "the unmatched visibility")
|
.span_label(vis.span, "the visibility")
|
||||||
.help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs))
|
.help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs))
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error in-case a `default` was parsed but no item followed.
|
/// Error in-case a `default` was parsed but no item followed.
|
||||||
fn error_on_unmatched_defaultness(&self, def: Defaultness) {
|
fn error_on_unmatched_defaultness(&self, def: Defaultness) {
|
||||||
if let Defaultness::Default(span) = def {
|
if let Defaultness::Default(sp) = def {
|
||||||
self.struct_span_err(span, "unmatched `default`")
|
self.struct_span_err(sp, "`default` not followed by an item")
|
||||||
.span_label(span, "the unmatched `default`")
|
.span_label(sp, "the `default` qualifier")
|
||||||
|
.note("only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ fn main() {}
|
|||||||
trait Foo {
|
trait Foo {
|
||||||
default!(); //~ ERROR cannot find macro `default` in this scope
|
default!(); //~ ERROR cannot find macro `default` in this scope
|
||||||
default do
|
default do
|
||||||
//~^ ERROR unmatched `default`
|
//~^ ERROR `default` not followed by an item
|
||||||
//~| ERROR non-item in item list
|
//~| ERROR non-item in item list
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11,6 +11,6 @@ struct S;
|
|||||||
impl S {
|
impl S {
|
||||||
default!(); //~ ERROR cannot find macro `default` in this scope
|
default!(); //~ ERROR cannot find macro `default` in this scope
|
||||||
default do
|
default do
|
||||||
//~^ ERROR unmatched `default`
|
//~^ ERROR `default` not followed by an item
|
||||||
//~| ERROR non-item in item list
|
//~| ERROR non-item in item list
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
error: unmatched `default`
|
error: `default` not followed by an item
|
||||||
--> $DIR/default-unmatched-assoc.rs:5:5
|
--> $DIR/default-unmatched-assoc.rs:5:5
|
||||||
|
|
|
|
||||||
LL | default do
|
LL | default do
|
||||||
| ^^^^^^^ the unmatched `default`
|
| ^^^^^^^ the `default` qualifier
|
||||||
|
|
|
||||||
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
||||||
|
|
||||||
error: non-item in item list
|
error: non-item in item list
|
||||||
--> $DIR/default-unmatched-assoc.rs:5:13
|
--> $DIR/default-unmatched-assoc.rs:5:13
|
||||||
@ -16,11 +18,13 @@ LL | default do
|
|||||||
LL | }
|
LL | }
|
||||||
| - item list ends here
|
| - item list ends here
|
||||||
|
|
||||||
error: unmatched `default`
|
error: `default` not followed by an item
|
||||||
--> $DIR/default-unmatched-assoc.rs:13:5
|
--> $DIR/default-unmatched-assoc.rs:13:5
|
||||||
|
|
|
|
||||||
LL | default do
|
LL | default do
|
||||||
| ^^^^^^^ the unmatched `default`
|
| ^^^^^^^ the `default` qualifier
|
||||||
|
|
|
||||||
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
||||||
|
|
||||||
error: non-item in item list
|
error: non-item in item list
|
||||||
--> $DIR/default-unmatched-assoc.rs:13:13
|
--> $DIR/default-unmatched-assoc.rs:13:13
|
||||||
|
@ -3,6 +3,6 @@ fn main() {}
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
default!(); //~ ERROR cannot find macro `default` in this scope
|
default!(); //~ ERROR cannot find macro `default` in this scope
|
||||||
default do
|
default do
|
||||||
//~^ ERROR unmatched `default`
|
//~^ ERROR `default` not followed by an item
|
||||||
//~| ERROR non-item in item list
|
//~| ERROR non-item in item list
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
error: unmatched `default`
|
error: `default` not followed by an item
|
||||||
--> $DIR/default-unmatched-extern.rs:5:5
|
--> $DIR/default-unmatched-extern.rs:5:5
|
||||||
|
|
|
|
||||||
LL | default do
|
LL | default do
|
||||||
| ^^^^^^^ the unmatched `default`
|
| ^^^^^^^ the `default` qualifier
|
||||||
|
|
|
||||||
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
||||||
|
|
||||||
error: non-item in item list
|
error: non-item in item list
|
||||||
--> $DIR/default-unmatched-extern.rs:5:13
|
--> $DIR/default-unmatched-extern.rs:5:13
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
mod foo {
|
mod foo {
|
||||||
default!(); // OK.
|
default!(); // OK.
|
||||||
default do
|
default do
|
||||||
//~^ ERROR unmatched `default`
|
//~^ ERROR `default` not followed by an item
|
||||||
//~| ERROR expected item, found reserved keyword `do`
|
//~| ERROR expected item, found reserved keyword `do`
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
error: unmatched `default`
|
error: `default` not followed by an item
|
||||||
--> $DIR/default-unmatched.rs:3:5
|
--> $DIR/default-unmatched.rs:3:5
|
||||||
|
|
|
|
||||||
LL | default do
|
LL | default do
|
||||||
| ^^^^^^^ the unmatched `default`
|
| ^^^^^^^ the `default` qualifier
|
||||||
|
|
|
||||||
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
||||||
|
|
||||||
error: expected item, found reserved keyword `do`
|
error: expected item, found reserved keyword `do`
|
||||||
--> $DIR/default-unmatched.rs:3:13
|
--> $DIR/default-unmatched.rs:3:13
|
||||||
|
@ -20,7 +20,7 @@ impl Foo for u16 {
|
|||||||
|
|
||||||
impl Foo for u32 { //~ ERROR not all trait items implemented, missing: `foo`
|
impl Foo for u32 { //~ ERROR not all trait items implemented, missing: `foo`
|
||||||
default pub fn foo<T: Default>() -> T { T::default() }
|
default pub fn foo<T: Default>() -> T { T::default() }
|
||||||
//~^ ERROR unmatched `default`
|
//~^ ERROR `default` not followed by an item
|
||||||
//~| ERROR non-item in item list
|
//~| ERROR non-item in item list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
error: unmatched `default`
|
error: `default` not followed by an item
|
||||||
--> $DIR/default.rs:22:5
|
--> $DIR/default.rs:22:5
|
||||||
|
|
|
|
||||||
LL | default pub fn foo<T: Default>() -> T { T::default() }
|
LL | default pub fn foo<T: Default>() -> T { T::default() }
|
||||||
| ^^^^^^^ the unmatched `default`
|
| ^^^^^^^ the `default` qualifier
|
||||||
|
|
|
||||||
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
||||||
|
|
||||||
error: non-item in item list
|
error: non-item in item list
|
||||||
--> $DIR/default.rs:22:13
|
--> $DIR/default.rs:22:13
|
||||||
|
@ -2,6 +2,6 @@ fn main() {}
|
|||||||
|
|
||||||
extern {
|
extern {
|
||||||
pub pub fn foo();
|
pub pub fn foo();
|
||||||
//~^ ERROR unmatched visibility `pub`
|
//~^ ERROR visibility `pub` not followed by an item
|
||||||
//~| ERROR non-item in item list
|
//~| ERROR non-item in item list
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: unmatched visibility `pub`
|
error: visibility `pub` not followed by an item
|
||||||
--> $DIR/duplicate-visibility.rs:4:5
|
--> $DIR/duplicate-visibility.rs:4:5
|
||||||
|
|
|
|
||||||
LL | pub pub fn foo();
|
LL | pub pub fn foo();
|
||||||
| ^^^ the unmatched visibility
|
| ^^^ the visibility
|
||||||
|
|
|
|
||||||
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
|
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
|
||||||
|
|
||||||
|
@ -7,4 +7,4 @@ impl ?Sized for Type {} //~ ERROR expected a trait, found type
|
|||||||
impl ?Sized for .. {} //~ ERROR expected a trait, found type
|
impl ?Sized for .. {} //~ ERROR expected a trait, found type
|
||||||
|
|
||||||
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
|
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
|
||||||
//~^ ERROR unmatched `default`
|
//~^ ERROR `default` not followed by an item
|
||||||
|
@ -22,11 +22,13 @@ error: expected a trait, found type
|
|||||||
LL | impl ?Sized for .. {}
|
LL | impl ?Sized for .. {}
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: unmatched `default`
|
error: `default` not followed by an item
|
||||||
--> $DIR/impl-parsing.rs:9:1
|
--> $DIR/impl-parsing.rs:9:1
|
||||||
|
|
|
|
||||||
LL | default unsafe FAIL
|
LL | default unsafe FAIL
|
||||||
| ^^^^^^^ the unmatched `default`
|
| ^^^^^^^ the `default` qualifier
|
||||||
|
|
|
||||||
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
||||||
|
|
||||||
error: expected item, found keyword `unsafe`
|
error: expected item, found keyword `unsafe`
|
||||||
--> $DIR/impl-parsing.rs:9:9
|
--> $DIR/impl-parsing.rs:9:9
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
struct S;
|
struct S;
|
||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
pub //~ ERROR unmatched visibility `pub`
|
pub //~ ERROR visibility `pub` not followed by an item
|
||||||
} //~ ERROR non-item in item list
|
} //~ ERROR non-item in item list
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: unmatched visibility `pub`
|
error: visibility `pub` not followed by an item
|
||||||
--> $DIR/issue-41155.rs:4:5
|
--> $DIR/issue-41155.rs:4:5
|
||||||
|
|
|
|
||||||
LL | pub
|
LL | pub
|
||||||
| ^^^ the unmatched visibility
|
| ^^^ the visibility
|
||||||
|
|
|
|
||||||
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
|
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
pub(crate) () fn foo() {} //~ unmatched visibility
|
pub(crate) () fn foo() {} //~ ERROR visibility `pub(crate)` not followed by an item
|
||||||
//~^ ERROR expected item, found `(`
|
//~^ ERROR expected item, found `(`
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error: unmatched visibility `pub(crate)`
|
error: visibility `pub(crate)` not followed by an item
|
||||||
--> $DIR/pub-restricted-error-fn.rs:1:1
|
--> $DIR/pub-restricted-error-fn.rs:1:1
|
||||||
|
|
|
|
||||||
LL | pub(crate) () fn foo() {}
|
LL | pub(crate) () fn foo() {}
|
||||||
| ^^^^^^^^^^ the unmatched visibility
|
| ^^^^^^^^^^ the visibility
|
||||||
|
|
|
|
||||||
= help: you likely meant to define an item, e.g., `pub(crate) fn foo() {}`
|
= help: you likely meant to define an item, e.g., `pub(crate) fn foo() {}`
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user