Skip to content

Commit ab84914

Browse files
committed
parser: tweak unmatched wording
1 parent d446c73 commit ab84914

17 files changed

+45
-32
lines changed

src/librustc_parse/parser/item.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,18 @@ impl<'a> Parser<'a> {
119119
}
120120
let vs = pprust::vis_to_string(&vis);
121121
let vs = vs.trim_end();
122-
self.struct_span_err(vis.span, &format!("unmatched visibility `{}`", vs))
123-
.span_label(vis.span, "the unmatched visibility")
122+
self.struct_span_err(vis.span, &format!("visibility `{}` not followed by an item", vs))
123+
.span_label(vis.span, "the visibility")
124124
.help(&format!("you likely meant to define an item, e.g., `{} fn foo() {{}}`", vs))
125125
.emit();
126126
}
127127

128128
/// Error in-case a `default` was parsed but no item followed.
129129
fn error_on_unmatched_defaultness(&self, def: Defaultness) {
130-
if let Defaultness::Default(span) = def {
131-
self.struct_span_err(span, "unmatched `default`")
132-
.span_label(span, "the unmatched `default`")
130+
if let Defaultness::Default(sp) = def {
131+
self.struct_span_err(sp, "`default` not followed by an item")
132+
.span_label(sp, "the `default` qualifier")
133+
.note("only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`")
133134
.emit();
134135
}
135136
}

src/test/ui/parser/default-unmatched-assoc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ fn main() {}
33
trait Foo {
44
default!(); //~ ERROR cannot find macro `default` in this scope
55
default do
6-
//~^ ERROR unmatched `default`
6+
//~^ ERROR `default` not followed by an item
77
//~| ERROR non-item in item list
88
}
99

1010
struct S;
1111
impl S {
1212
default!(); //~ ERROR cannot find macro `default` in this scope
1313
default do
14-
//~^ ERROR unmatched `default`
14+
//~^ ERROR `default` not followed by an item
1515
//~| ERROR non-item in item list
1616
}

src/test/ui/parser/default-unmatched-assoc.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: unmatched `default`
1+
error: `default` not followed by an item
22
--> $DIR/default-unmatched-assoc.rs:5:5
33
|
44
LL | default do
5-
| ^^^^^^^ the unmatched `default`
5+
| ^^^^^^^ the `default` qualifier
6+
|
7+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
68

79
error: non-item in item list
810
--> $DIR/default-unmatched-assoc.rs:5:13
@@ -16,11 +18,13 @@ LL | default do
1618
LL | }
1719
| - item list ends here
1820

19-
error: unmatched `default`
21+
error: `default` not followed by an item
2022
--> $DIR/default-unmatched-assoc.rs:13:5
2123
|
2224
LL | default do
23-
| ^^^^^^^ the unmatched `default`
25+
| ^^^^^^^ the `default` qualifier
26+
|
27+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
2428

2529
error: non-item in item list
2630
--> $DIR/default-unmatched-assoc.rs:13:13

src/test/ui/parser/default-unmatched-extern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ fn main() {}
33
extern "C" {
44
default!(); //~ ERROR cannot find macro `default` in this scope
55
default do
6-
//~^ ERROR unmatched `default`
6+
//~^ ERROR `default` not followed by an item
77
//~| ERROR non-item in item list
88
}

src/test/ui/parser/default-unmatched-extern.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: unmatched `default`
1+
error: `default` not followed by an item
22
--> $DIR/default-unmatched-extern.rs:5:5
33
|
44
LL | default do
5-
| ^^^^^^^ the unmatched `default`
5+
| ^^^^^^^ the `default` qualifier
6+
|
7+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
68

79
error: non-item in item list
810
--> $DIR/default-unmatched-extern.rs:5:13
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod foo {
22
default!(); // OK.
33
default do
4-
//~^ ERROR unmatched `default`
4+
//~^ ERROR `default` not followed by an item
55
//~| ERROR expected item, found reserved keyword `do`
66
}

src/test/ui/parser/default-unmatched.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: unmatched `default`
1+
error: `default` not followed by an item
22
--> $DIR/default-unmatched.rs:3:5
33
|
44
LL | default do
5-
| ^^^^^^^ the unmatched `default`
5+
| ^^^^^^^ the `default` qualifier
6+
|
7+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
68

79
error: expected item, found reserved keyword `do`
810
--> $DIR/default-unmatched.rs:3:13

src/test/ui/parser/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Foo for u16 {
2020

2121
impl Foo for u32 { //~ ERROR not all trait items implemented, missing: `foo`
2222
default pub fn foo<T: Default>() -> T { T::default() }
23-
//~^ ERROR unmatched `default`
23+
//~^ ERROR `default` not followed by an item
2424
//~| ERROR non-item in item list
2525
}
2626

src/test/ui/parser/default.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: unmatched `default`
1+
error: `default` not followed by an item
22
--> $DIR/default.rs:22:5
33
|
44
LL | default pub fn foo<T: Default>() -> T { T::default() }
5-
| ^^^^^^^ the unmatched `default`
5+
| ^^^^^^^ the `default` qualifier
6+
|
7+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
68

79
error: non-item in item list
810
--> $DIR/default.rs:22:13

src/test/ui/parser/duplicate-visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ fn main() {}
22

33
extern {
44
pub pub fn foo();
5-
//~^ ERROR unmatched visibility `pub`
5+
//~^ ERROR visibility `pub` not followed by an item
66
//~| ERROR non-item in item list
77
}

src/test/ui/parser/duplicate-visibility.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: unmatched visibility `pub`
1+
error: visibility `pub` not followed by an item
22
--> $DIR/duplicate-visibility.rs:4:5
33
|
44
LL | pub pub fn foo();
5-
| ^^^ the unmatched visibility
5+
| ^^^ the visibility
66
|
77
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
88

src/test/ui/parser/impl-parsing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ impl ?Sized for Type {} //~ ERROR expected a trait, found type
77
impl ?Sized for .. {} //~ ERROR expected a trait, found type
88

99
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
10-
//~^ ERROR unmatched `default`
10+
//~^ ERROR `default` not followed by an item

src/test/ui/parser/impl-parsing.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ error: expected a trait, found type
2222
LL | impl ?Sized for .. {}
2323
| ^^^^^^
2424

25-
error: unmatched `default`
25+
error: `default` not followed by an item
2626
--> $DIR/impl-parsing.rs:9:1
2727
|
2828
LL | default unsafe FAIL
29-
| ^^^^^^^ the unmatched `default`
29+
| ^^^^^^^ the `default` qualifier
30+
|
31+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
3032

3133
error: expected item, found keyword `unsafe`
3234
--> $DIR/impl-parsing.rs:9:9

src/test/ui/parser/issue-41155.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct S;
22

33
impl S {
4-
pub //~ ERROR unmatched visibility `pub`
4+
pub //~ ERROR visibility `pub` not followed by an item
55
} //~ ERROR non-item in item list
66

77
fn main() {}

src/test/ui/parser/issue-41155.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: unmatched visibility `pub`
1+
error: visibility `pub` not followed by an item
22
--> $DIR/issue-41155.rs:4:5
33
|
44
LL | pub
5-
| ^^^ the unmatched visibility
5+
| ^^^ the visibility
66
|
77
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
88

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub(crate) () fn foo() {} //~ unmatched visibility
1+
pub(crate) () fn foo() {} //~ ERROR visibility `pub(crate)` not followed by an item
22
//~^ ERROR expected item, found `(`

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: unmatched visibility `pub(crate)`
1+
error: visibility `pub(crate)` not followed by an item
22
--> $DIR/pub-restricted-error-fn.rs:1:1
33
|
44
LL | pub(crate) () fn foo() {}
5-
| ^^^^^^^^^^ the unmatched visibility
5+
| ^^^^^^^^^^ the visibility
66
|
77
= help: you likely meant to define an item, e.g., `pub(crate) fn foo() {}`
88

0 commit comments

Comments
 (0)