Skip to content

Commit dd2b027

Browse files
committed
Tweak more warnings.
Much like the previous commit. I think the removal of "the token" in each message is fine here. There are many more error messages that mention tokens without saying "the token" than those that do say it.
1 parent a201fab commit dd2b027

File tree

50 files changed

+113
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+113
-121
lines changed

Diff for: compiler/rustc_expand/src/mbe/diagnostics.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use std::borrow::Cow;
22

33
use rustc_ast::token::{self, Token, TokenKind};
44
use rustc_ast::tokenstream::TokenStream;
5-
use rustc_ast_pretty::pprust;
65
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, DiagMessage};
76
use rustc_macros::Subdiagnostic;
8-
use rustc_parse::parser::{Parser, Recovery};
7+
use rustc_parse::parser::{Parser, Recovery, token_descr};
98
use rustc_session::parse::ParseSess;
109
use rustc_span::source_map::SourceMap;
1110
use rustc_span::symbol::Ident;
@@ -336,17 +335,11 @@ pub(super) fn annotate_doc_comment(err: &mut Diag<'_>, sm: &SourceMap, span: Spa
336335
/// other tokens, this is "unexpected token...".
337336
pub(super) fn parse_failure_msg(tok: &Token, expected_token: Option<&Token>) -> Cow<'static, str> {
338337
if let Some(expected_token) = expected_token {
339-
Cow::from(format!(
340-
"expected `{}`, found `{}`",
341-
pprust::token_to_string(expected_token),
342-
pprust::token_to_string(tok),
343-
))
338+
Cow::from(format!("expected {}, found {}", token_descr(expected_token), token_descr(tok)))
344339
} else {
345340
match tok.kind {
346341
token::Eof => Cow::from("unexpected end of macro invocation"),
347-
_ => {
348-
Cow::from(format!("no rules expected the token `{}`", pprust::token_to_string(tok)))
349-
}
342+
_ => Cow::from(format!("no rules expected {}", token_descr(tok))),
350343
}
351344
}
352345
}

Diff for: compiler/rustc_expand/src/mbe/macro_parser.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ use std::rc::Rc;
7878
pub(crate) use NamedMatch::*;
7979
pub(crate) use ParseResult::*;
8080
use rustc_ast::token::{self, DocComment, NonterminalKind, Token};
81-
use rustc_ast_pretty::pprust;
8281
use rustc_data_structures::fx::FxHashMap;
8382
use rustc_errors::ErrorGuaranteed;
8483
use rustc_lint_defs::pluralize;
85-
use rustc_parse::parser::{ParseNtResult, Parser};
84+
use rustc_parse::parser::{ParseNtResult, Parser, token_descr};
8685
use rustc_span::Span;
8786
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
8887

@@ -150,7 +149,7 @@ impl Display for MatcherLoc {
150149
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
151150
match self {
152151
MatcherLoc::Token { token } | MatcherLoc::SequenceSep { separator: token } => {
153-
write!(f, "`{}`", pprust::token_to_string(token))
152+
write!(f, "{}", token_descr(token))
154153
}
155154
MatcherLoc::MetaVarDecl { bind, kind, .. } => {
156155
write!(f, "meta-variable `${bind}")?;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub fn main() {
2-
vec![,]; //~ ERROR no rules expected the token `,`
2+
vec![,]; //~ ERROR no rules expected `,`
33
}

Diff for: tests/ui/array-slice-vec/vec-macro-with-comma-only.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `,`
1+
error: no rules expected `,`
22
--> $DIR/vec-macro-with-comma-only.rs:2:10
33
|
44
LL | vec![,];

Diff for: tests/ui/editions/edition-keywords-2015-2015-parsing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub fn check_async() {
1313
let mut r#async = 1; // OK
1414

1515
r#async = consumes_async!(async); // OK
16-
r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
17-
r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
16+
r#async = consumes_async!(r#async); //~ ERROR no rules expected `r#async`
17+
r#async = consumes_async_raw!(async); //~ ERROR no rules expected `async`
1818
r#async = consumes_async_raw!(r#async); // OK
1919

2020
if passes_ident!(async) == 1 {} // OK

Diff for: tests/ui/editions/edition-keywords-2015-2015-parsing.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `r#async`
1+
error: no rules expected `r#async`
22
--> $DIR/edition-keywords-2015-2015-parsing.rs:16:31
33
|
44
LL | r#async = consumes_async!(r#async);
@@ -10,7 +10,7 @@ note: while trying to match `async`
1010
LL | (async) => (1)
1111
| ^^^^^
1212

13-
error: no rules expected the token `async`
13+
error: no rules expected `async`
1414
--> $DIR/edition-keywords-2015-2015-parsing.rs:17:35
1515
|
1616
LL | r#async = consumes_async_raw!(async);

Diff for: tests/ui/editions/edition-keywords-2015-2018-parsing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub fn check_async() {
1313
let mut r#async = 1; // OK
1414

1515
r#async = consumes_async!(async); // OK
16-
r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
17-
r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
16+
r#async = consumes_async!(r#async); //~ ERROR no rules expected `r#async`
17+
r#async = consumes_async_raw!(async); //~ ERROR no rules expected `async`
1818
r#async = consumes_async_raw!(r#async); // OK
1919

2020
if passes_ident!(async) == 1 {} // OK

Diff for: tests/ui/editions/edition-keywords-2015-2018-parsing.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `r#async`
1+
error: no rules expected `r#async`
22
--> $DIR/edition-keywords-2015-2018-parsing.rs:16:31
33
|
44
LL | r#async = consumes_async!(r#async);
@@ -10,7 +10,7 @@ note: while trying to match `async`
1010
LL | (async) => (1)
1111
| ^^^^^
1212

13-
error: no rules expected the token `async`
13+
error: no rules expected `async`
1414
--> $DIR/edition-keywords-2015-2018-parsing.rs:17:35
1515
|
1616
LL | r#async = consumes_async_raw!(async);

Diff for: tests/ui/editions/edition-keywords-2018-2015-parsing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub fn check_async() {
1717
let mut r#async = 1; // OK
1818

1919
r#async = consumes_async!(async); // OK
20-
r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
21-
r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
20+
r#async = consumes_async!(r#async); //~ ERROR no rules expected `r#async`
21+
r#async = consumes_async_raw!(async); //~ ERROR no rules expected keyword `async`
2222
r#async = consumes_async_raw!(r#async); // OK
2323

2424
if passes_ident!(async) == 1 {} // FIXME: Edition hygiene bug, async here is 2018 and reserved

Diff for: tests/ui/editions/edition-keywords-2018-2015-parsing.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ help: escape `async` to use it as an identifier
2020
LL | module::r#async();
2121
| ++
2222

23-
error: no rules expected the token `r#async`
23+
error: no rules expected `r#async`
2424
--> $DIR/edition-keywords-2018-2015-parsing.rs:20:31
2525
|
2626
LL | r#async = consumes_async!(r#async);
2727
| ^^^^^^^ no rules expected this token in macro call
2828
|
29-
note: while trying to match `async`
29+
note: while trying to match keyword `async`
3030
--> $DIR/auxiliary/edition-kw-macro-2015.rs:17:6
3131
|
3232
LL | (async) => (1)
3333
| ^^^^^
3434

35-
error: no rules expected the token `async`
35+
error: no rules expected keyword `async`
3636
--> $DIR/edition-keywords-2018-2015-parsing.rs:21:35
3737
|
3838
LL | r#async = consumes_async_raw!(async);

Diff for: tests/ui/editions/edition-keywords-2018-2018-parsing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub fn check_async() {
2424
let mut r#async = 1; // OK
2525

2626
r#async = consumes_async!(async); // OK
27-
r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
28-
r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
27+
r#async = consumes_async!(r#async); //~ ERROR no rules expected `r#async`
28+
r#async = consumes_async_raw!(async); //~ ERROR no rules expected keyword `async`
2929
r#async = consumes_async_raw!(r#async); // OK
3030

3131
if passes_ident!(async) == 1 {} // FIXME: Edition hygiene bug, async here is 2018 and reserved

Diff for: tests/ui/editions/edition-keywords-2018-2018-parsing.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ help: escape `async` to use it as an identifier
2020
LL | module::r#async();
2121
| ++
2222

23-
error: no rules expected the token `r#async`
23+
error: no rules expected `r#async`
2424
--> $DIR/edition-keywords-2018-2018-parsing.rs:27:31
2525
|
2626
LL | r#async = consumes_async!(r#async);
2727
| ^^^^^^^ no rules expected this token in macro call
2828
|
29-
note: while trying to match `async`
29+
note: while trying to match keyword `async`
3030
--> $DIR/auxiliary/edition-kw-macro-2018.rs:17:6
3131
|
3232
LL | (async) => (1)
3333
| ^^^^^
3434

35-
error: no rules expected the token `async`
35+
error: no rules expected keyword `async`
3636
--> $DIR/edition-keywords-2018-2018-parsing.rs:28:35
3737
|
3838
LL | r#async = consumes_async_raw!(async);

Diff for: tests/ui/fail-simple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn main() {
2-
panic!(@); //~ ERROR no rules expected the token `@`
2+
panic!(@); //~ ERROR no rules expected `@`
33
}

Diff for: tests/ui/fail-simple.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `@`
1+
error: no rules expected `@`
22
--> $DIR/fail-simple.rs:2:12
33
|
44
LL | panic!(@);

Diff for: tests/ui/macros/assert-trailing-junk.with-generic-asset.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: expected one of `,`, `.`, `?`, or an operator, found `some`
1010
LL | assert!(true some extra junk);
1111
| ^^^^ expected one of `,`, `.`, `?`, or an operator
1212

13-
error: no rules expected the token `blah`
13+
error: no rules expected `blah`
1414
--> $DIR/assert-trailing-junk.rs:15:30
1515
|
1616
LL | assert!(true, "whatever" blah);
@@ -28,7 +28,7 @@ LL | assert!(true "whatever" blah);
2828
| |
2929
| help: try adding a comma
3030

31-
error: no rules expected the token `blah`
31+
error: no rules expected `blah`
3232
--> $DIR/assert-trailing-junk.rs:18:29
3333
|
3434
LL | assert!(true "whatever" blah);

Diff for: tests/ui/macros/assert-trailing-junk.without-generic-asset.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: expected one of `,`, `.`, `?`, or an operator, found `some`
1010
LL | assert!(true some extra junk);
1111
| ^^^^ expected one of `,`, `.`, `?`, or an operator
1212

13-
error: no rules expected the token `blah`
13+
error: no rules expected `blah`
1414
--> $DIR/assert-trailing-junk.rs:15:30
1515
|
1616
LL | assert!(true, "whatever" blah);
@@ -28,7 +28,7 @@ LL | assert!(true "whatever" blah);
2828
| |
2929
| help: try adding a comma
3030

31-
error: no rules expected the token `blah`
31+
error: no rules expected `blah`
3232
--> $DIR/assert-trailing-junk.rs:18:29
3333
|
3434
LL | assert!(true "whatever" blah);

Diff for: tests/ui/macros/best-failure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ macro_rules! number {
22
(neg false, $self:ident) => { $self };
33
($signed:tt => $ty:ty;) => {
44
number!(neg $signed, $self);
5-
//~^ ERROR no rules expected the token `$`
5+
//~^ ERROR no rules expected `$`
66
};
77
}
88

Diff for: tests/ui/macros/best-failure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `$`
1+
error: no rules expected `$`
22
--> $DIR/best-failure.rs:4:30
33
|
44
LL | macro_rules! number {

Diff for: tests/ui/macros/expr_2021_inline_const.edi2021.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `const`
1+
error: no rules expected keyword `const`
22
--> $DIR/expr_2021_inline_const.rs:23:12
33
|
44
LL | macro_rules! m2021 {
@@ -13,7 +13,7 @@ note: while trying to match meta-variable `$e:expr_2021`
1313
LL | ($e:expr_2021) => {
1414
| ^^^^^^^^^^^^
1515

16-
error: no rules expected the token `const`
16+
error: no rules expected keyword `const`
1717
--> $DIR/expr_2021_inline_const.rs:24:12
1818
|
1919
LL | macro_rules! m2024 {

Diff for: tests/ui/macros/expr_2021_inline_const.edi2024.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `const`
1+
error: no rules expected keyword `const`
22
--> $DIR/expr_2021_inline_const.rs:23:12
33
|
44
LL | macro_rules! m2021 {

Diff for: tests/ui/macros/expr_2021_inline_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ macro_rules! test {
2020
}
2121

2222
fn main() {
23-
m2021!(const { 1 }); //~ ERROR: no rules expected the token `const`
24-
m2024!(const { 1 }); //[edi2021]~ ERROR: no rules expected the token `const`
23+
m2021!(const { 1 }); //~ ERROR: no rules expected keyword `const`
24+
m2024!(const { 1 }); //[edi2021]~ ERROR: no rules expected keyword `const`
2525

2626
test!(expr);
2727
}

Diff for: tests/ui/macros/expr_2024_underscore_expr.edi2021.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `_`
1+
error: no rules expected reserved identifier `_`
22
--> $DIR/expr_2024_underscore_expr.rs:19:12
33
|
44
LL | macro_rules! m2021 {
@@ -13,7 +13,7 @@ note: while trying to match meta-variable `$e:expr_2021`
1313
LL | ($e:expr_2021) => {
1414
| ^^^^^^^^^^^^
1515

16-
error: no rules expected the token `_`
16+
error: no rules expected reserved identifier `_`
1717
--> $DIR/expr_2024_underscore_expr.rs:20:12
1818
|
1919
LL | macro_rules! m2024 {

Diff for: tests/ui/macros/expr_2024_underscore_expr.edi2024.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: no rules expected the token `_`
1+
error: no rules expected reserved identifier `_`
22
--> $DIR/expr_2024_underscore_expr.rs:19:12
33
|
44
LL | macro_rules! m2021 {

Diff for: tests/ui/macros/expr_2024_underscore_expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ macro_rules! m2024 {
1616
}
1717

1818
fn main() {
19-
m2021!(_); //~ ERROR: no rules expected the token `_`
20-
m2024!(_); //[edi2021]~ ERROR: no rules expected the token `_`
19+
m2021!(_); //~ ERROR: no rules expected reserved identifier `_`
20+
m2024!(_); //[edi2021]~ ERROR: no rules expected reserved identifier `_`
2121
}

Diff for: tests/ui/macros/macro-at-most-once-rep-2015.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ macro_rules! barstar {
2222
pub fn main() {
2323
foo!();
2424
foo!(a);
25-
foo!(a?); //~ ERROR no rules expected the token `?`
26-
foo!(a?a); //~ ERROR no rules expected the token `?`
27-
foo!(a?a?a); //~ ERROR no rules expected the token `?`
25+
foo!(a?); //~ ERROR no rules expected `?`
26+
foo!(a?a); //~ ERROR no rules expected `?`
27+
foo!(a?a?a); //~ ERROR no rules expected `?`
2828

2929
barplus!(); //~ERROR unexpected end of macro invocation
3030
barplus!(a); //~ERROR unexpected end of macro invocation
31-
barplus!(a?); //~ ERROR no rules expected the token `?`
32-
barplus!(a?a); //~ ERROR no rules expected the token `?`
31+
barplus!(a?); //~ ERROR no rules expected `?`
32+
barplus!(a?a); //~ ERROR no rules expected `?`
3333
barplus!(a+);
3434
barplus!(+);
3535

3636
barstar!(); //~ERROR unexpected end of macro invocation
3737
barstar!(a); //~ERROR unexpected end of macro invocation
38-
barstar!(a?); //~ ERROR no rules expected the token `?`
39-
barstar!(a?a); //~ ERROR no rules expected the token `?`
38+
barstar!(a?); //~ ERROR no rules expected `?`
39+
barstar!(a?a); //~ ERROR no rules expected `?`
4040
barstar!(a*);
4141
barstar!(*);
4242
}

0 commit comments

Comments
 (0)