Skip to content

Commit a201fab

Browse files
committed
Tweak expand_incomplete_parse warning.
By using `token_descr`, as is done for many other errors, we can get slightly better descriptions in error messages, e.g. "macro expansion ignores token `let` and any following" becomes "macro expansion ignores keyword `let` and any tokens following". This will be more important once invisible delimiters start being mentioned in error messages -- without this commit, that leads to error messages such as "error at ``" because invisible delimiters are pretty printed as an empty string.
1 parent df4ca44 commit a201fab

27 files changed

+39
-38
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_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) {

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 ; );

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
macro_rules! m {
22
() => {
3-
let //~ ERROR macro expansion ignores token `let` and any following
3+
let //~ ERROR macro expansion ignores keyword `let` and any tokens following
44
};
55
}
66

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: macro expansion ignores token `let` and any following
1+
error: macro expansion ignores keyword `let` and any tokens following
22
--> $DIR/issue-54441.rs:3:9
33
|
44
LL | let

Diff for: tests/ui/macros/macro-context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// (typeof used because it's surprisingly hard to find an unparsed token after a stmt)
22
macro_rules! m {
33
() => ( i ; typeof ); //~ ERROR expected expression, found reserved keyword `typeof`
4-
//~| ERROR macro expansion ignores token `typeof`
5-
//~| ERROR macro expansion ignores token `;`
6-
//~| ERROR macro expansion ignores token `;`
4+
//~| ERROR macro expansion ignores reserved keyword `typeof`
5+
//~| ERROR macro expansion ignores `;`
6+
//~| ERROR macro expansion ignores `;`
77
//~| ERROR cannot find type `i` in this scope
88
//~| ERROR cannot find value `i` in this scope
99
//~| WARN trailing semicolon in macro

Diff for: tests/ui/macros/macro-context.stderr

+3-3
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/macro-context.rs:3:15
33
|
44
LL | () => ( i ; typeof );
@@ -9,7 +9,7 @@ LL | let a: m!();
99
|
1010
= note: the usage of `m!` is likely invalid in type context
1111

12-
error: macro expansion ignores token `typeof` and any following
12+
error: macro expansion ignores reserved keyword `typeof` and any tokens following
1313
--> $DIR/macro-context.rs:3:17
1414
|
1515
LL | () => ( i ; typeof );
@@ -20,7 +20,7 @@ LL | let i = m!();
2020
|
2121
= note: the usage of `m!` is likely invalid in expression context
2222

23-
error: macro expansion ignores token `;` and any following
23+
error: macro expansion ignores `;` and any tokens following
2424
--> $DIR/macro-context.rs:3:15
2525
|
2626
LL | () => ( i ; typeof );

Diff for: tests/ui/macros/macro-in-expression-context.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ macro_rules! foo {
1111
//~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default
1212
assert_eq!("B", "B");
1313
}
14-
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
14+
//~^^ ERROR macro expansion ignores `assert_eq` and any tokens following
1515
//~| NOTE the usage of `foo!` is likely invalid in expression context
1616
}
1717

Diff for: tests/ui/macros/macro-in-expression-context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ macro_rules! foo {
1111
//~| NOTE `#[warn(semicolon_in_expressions_from_macros)]` on by default
1212
assert_eq!("B", "B");
1313
}
14-
//~^^ ERROR macro expansion ignores token `assert_eq` and any following
14+
//~^^ ERROR macro expansion ignores `assert_eq` and any tokens following
1515
//~| NOTE the usage of `foo!` is likely invalid in expression context
1616
}
1717

Diff for: tests/ui/macros/macro-in-expression-context.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: macro expansion ignores token `assert_eq` and any following
1+
error: macro expansion ignores `assert_eq` and any tokens following
22
--> $DIR/macro-in-expression-context.rs:12:9
33
|
44
LL | assert_eq!("B", "B");

Diff for: tests/ui/macros/syntax-error-recovery.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ macro_rules! values {
1010
};
1111
}
1212
//~^^^^^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found type `(String)`
13-
//~| ERROR macro expansion ignores token `(String)` and any following
13+
//~| ERROR macro expansion ignores type `(String)` and any tokens following
1414

1515
values!(STRING(1) as (String) => cfg(test),);
1616
//~^ ERROR expected one of `!` or `::`, found `<eof>`

Diff for: tests/ui/macros/syntax-error-recovery.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | values!(STRING(1) as (String) => cfg(test),);
1010
= help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
1111
= note: this error originates in the macro `values` (in Nightly builds, run with -Z macro-backtrace for more info)
1212

13-
error: macro expansion ignores token `(String)` and any following
13+
error: macro expansion ignores type `(String)` and any tokens following
1414
--> $DIR/syntax-error-recovery.rs:7:26
1515
|
1616
LL | $token $($inner)? = $value,

Diff for: tests/ui/parser/macro/macro-expand-to-match-arm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
macro_rules! arm {
22
($pattern:pat => $block:block) => {
33
$pattern => $block
4-
//~^ ERROR macro expansion ignores token `=>` and any following
4+
//~^ ERROR macro expansion ignores `=>` and any tokens following
55
//~| NOTE the usage of `arm!` is likely invalid in pattern context
66
//~| NOTE macros cannot expand to match arms
77
};

Diff for: tests/ui/parser/macro/macro-expand-to-match-arm.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/macro-expand-to-match-arm.rs:3:18
33
|
44
LL | $pattern => $block

Diff for: tests/ui/parser/macro/macro-incomplete-parse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ macro_rules! ignored_item {
22
() => {
33
fn foo() {}
44
fn bar() {}
5-
, //~ ERROR macro expansion ignores token `,`
5+
, //~ ERROR macro expansion ignores `,`
66
}
77
}
88

@@ -13,7 +13,7 @@ macro_rules! ignored_expr {
1313
}
1414

1515
macro_rules! ignored_pat {
16-
() => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
16+
() => ( 1, 2 ) //~ ERROR macro expansion ignores `,`
1717
}
1818

1919
ignored_item!();

Diff for: tests/ui/parser/macro/macro-incomplete-parse.stderr

+2-2
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/macro-incomplete-parse.rs:5:9
33
|
44
LL | ,
@@ -20,7 +20,7 @@ LL | ignored_expr!();
2020
|
2121
= note: this error originates in the macro `ignored_expr` (in Nightly builds, run with -Z macro-backtrace for more info)
2222

23-
error: macro expansion ignores token `,` and any following
23+
error: macro expansion ignores `,` and any tokens following
2424
--> $DIR/macro-incomplete-parse.rs:16:14
2525
|
2626
LL | () => ( 1, 2 )

Diff for: tests/ui/parser/macro/trait-non-item-macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
macro_rules! bah {
22
($a:expr) => {
33
$a
4-
}; //~^ ERROR macro expansion ignores token `2` and any following
4+
}; //~^ ERROR macro expansion ignores expression `2` and any tokens following
55
}
66

77
trait Bar {

Diff for: tests/ui/parser/macro/trait-non-item-macros.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: macro expansion ignores token `2` and any following
1+
error: macro expansion ignores expression `2` and any tokens following
22
--> $DIR/trait-non-item-macros.rs:3:9
33
|
44
LL | $a

Diff for: tests/ui/proc-macro/attr-invalid-exprs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
//~^ ERROR expected expression, found end of macro arguments
1414

1515
let _ = #[duplicate] "Hello, world!";
16-
//~^ ERROR macro expansion ignores token `,` and any following
16+
//~^ ERROR macro expansion ignores `,` and any tokens following
1717

1818
let _ = {
1919
#[no_output]
@@ -22,7 +22,7 @@ fn main() {
2222

2323
let _ = {
2424
#[duplicate]
25-
//~^ ERROR macro expansion ignores token `,` and any following
25+
//~^ ERROR macro expansion ignores `,` and any tokens following
2626
"Hello, world!"
2727
};
2828
}

Diff for: tests/ui/proc-macro/attr-invalid-exprs.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: expected expression, found end of macro arguments
44
LL | let _ = #[no_output] "Hello, world!";
55
| ^^^^^^^^^^^^
66

7-
error: macro expansion ignores token `,` and any following
7+
error: macro expansion ignores `,` and any tokens following
88
--> $DIR/attr-invalid-exprs.rs:15:13
99
|
1010
LL | let _ = #[duplicate] "Hello, world!";
@@ -16,7 +16,7 @@ help: you might be missing a semicolon here
1616
LL | let _ = #[duplicate]; "Hello, world!";
1717
| +
1818

19-
error: macro expansion ignores token `,` and any following
19+
error: macro expansion ignores `,` and any tokens following
2020
--> $DIR/attr-invalid-exprs.rs:24:9
2121
|
2222
LL | #[duplicate]

Diff for: tests/ui/proc-macro/expand-expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ expand_expr_fail!(echo_pm!($)); //~ ERROR: expected expression, found `$`
114114

115115
// We get errors reported and recover during macro expansion if the macro
116116
// doesn't produce a valid expression.
117-
expand_expr_is!("string", echo_tts!("string"; hello)); //~ ERROR: macro expansion ignores token `hello` and any following
118-
expand_expr_is!("string", echo_pm!("string"; hello)); //~ ERROR: macro expansion ignores token `;` and any following
117+
expand_expr_is!("string", echo_tts!("string"; hello)); //~ ERROR: macro expansion ignores `hello` and any tokens following
118+
expand_expr_is!("string", echo_pm!("string"; hello)); //~ ERROR: macro expansion ignores `;` and any tokens following
119119

120120
// For now, fail if a non-literal expression is expanded.
121121
expand_expr_fail!(arbitrary_expression() + "etc");

Diff for: tests/ui/proc-macro/expand-expr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error: expected expression, found `$`
2222
LL | expand_expr_fail!(echo_pm!($));
2323
| ^ expected expression
2424

25-
error: macro expansion ignores token `hello` and any following
25+
error: macro expansion ignores `hello` and any tokens following
2626
--> $DIR/expand-expr.rs:117:47
2727
|
2828
LL | expand_expr_is!("string", echo_tts!("string"; hello));
@@ -34,7 +34,7 @@ help: you might be missing a semicolon here
3434
LL | expand_expr_is!("string", echo_tts!("string"; hello););
3535
| +
3636

37-
error: macro expansion ignores token `;` and any following
37+
error: macro expansion ignores `;` and any tokens following
3838
--> $DIR/expand-expr.rs:118:44
3939
|
4040
LL | expand_expr_is!("string", echo_pm!("string"; hello));

0 commit comments

Comments
 (0)