Skip to content

Commit d88d045

Browse files
Rollup merge of rust-lang#132332 - nnethercote:use-token_descr-more, r=estebank
Use `token_descr` more in error messages This is the first two commits from rust-lang#124141, put into their own PR to get things rolling. Commit messages have the details. r? `@estebank` cc `@petrochenkov`
2 parents ee6b441 + dd2b027 commit d88d045

File tree

77 files changed

+152
-159
lines changed

Some content is hidden

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

77 files changed

+152
-159
lines changed

Diff for: compiler/rustc_expand/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ expand_helper_attribute_name_invalid =
7474
`{$name}` cannot be a name of derive helper attribute
7575
7676
expand_incomplete_parse =
77-
macro expansion ignores token `{$token}` and any following
77+
macro expansion ignores {$descr} and any tokens following
7878
.label = caused by the macro expansion here
7979
.note = the usage of `{$macro_path}!` is likely invalid in {$kind_name} context
8080
.suggestion_add_semi = you might be missing a semicolon here

Diff for: compiler/rustc_expand/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub(crate) struct UnsupportedKeyValue {
275275
pub(crate) struct IncompleteParse<'a> {
276276
#[primary_span]
277277
pub span: Span,
278-
pub token: Cow<'a, str>,
278+
pub descr: String,
279279
#[label]
280280
pub label_span: Span,
281281
pub macro_path: &'a ast::Path,

Diff for: compiler/rustc_expand/src/expand.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_errors::PResult;
2121
use rustc_feature::Features;
2222
use rustc_parse::parser::{
2323
AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma,
24+
token_descr,
2425
};
2526
use rustc_parse::validate_attr;
2627
use rustc_session::lint::BuiltinLintDiag;
@@ -1013,7 +1014,7 @@ pub(crate) fn ensure_complete_parse<'a>(
10131014
span: Span,
10141015
) {
10151016
if parser.token != token::Eof {
1016-
let token = pprust::token_to_string(&parser.token);
1017+
let descr = token_descr(&parser.token);
10171018
// Avoid emitting backtrace info twice.
10181019
let def_site_span = parser.token.span.with_ctxt(SyntaxContext::root());
10191020

@@ -1029,7 +1030,7 @@ pub(crate) fn ensure_complete_parse<'a>(
10291030

10301031
parser.dcx().emit_err(IncompleteParse {
10311032
span: def_site_span,
1032-
token,
1033+
descr,
10331034
label_span: span,
10341035
macro_path,
10351036
kind_name,

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}")?;

Diff for: compiler/rustc_parse/src/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl TokenDescription {
424424
}
425425
}
426426

427-
pub(super) fn token_descr(token: &Token) -> String {
427+
pub fn token_descr(token: &Token) -> String {
428428
let name = pprust::token_to_string(token).to_string();
429429

430430
let kind = match (TokenDescription::from_token(token), &token.kind) {
+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/issue-118786.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
macro_rules! make_macro {
66
($macro_name:tt) => {
77
macro_rules! $macro_name {
8-
//~^ ERROR macro expansion ignores token `{` and any following
8+
//~^ ERROR macro expansion ignores `{` and any tokens following
99
//~| ERROR cannot find macro `macro_rules` in this scope
1010
//~| put a macro name here
1111
() => {}

Diff for: tests/ui/macros/issue-118786.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ help: add a semicolon
1313
LL | macro_rules! $macro_name; {
1414
| +
1515

16-
error: macro expansion ignores token `{` and any following
16+
error: macro expansion ignores `{` and any tokens following
1717
--> $DIR/issue-118786.rs:7:34
1818
|
1919
LL | macro_rules! $macro_name {

Diff for: tests/ui/macros/issue-30007.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
macro_rules! t {
2-
() => ( String ; ); //~ ERROR macro expansion ignores token `;`
2+
() => ( String ; ); //~ ERROR macro expansion ignores `;`
33
}
44

55
fn main() {

Diff for: tests/ui/macros/issue-30007.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: macro expansion ignores token `;` and any following
1+
error: macro expansion ignores `;` and any tokens following
22
--> $DIR/issue-30007.rs:2:20
33
|
44
LL | () => ( String ; );

0 commit comments

Comments
 (0)