Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

compiler/rustc_expand/messages.ftl

Lines changed: 1 addition & 1 deletion
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

compiler/rustc_expand/src/errors.rs

Lines changed: 1 addition & 1 deletion
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,

compiler/rustc_expand/src/expand.rs

Lines changed: 3 additions & 2 deletions
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,

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
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) {

tests/ui/macros/issue-118786.rs

Lines changed: 1 addition & 1 deletion
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
() => {}

tests/ui/macros/issue-118786.stderr

Lines changed: 1 addition & 1 deletion
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 {

tests/ui/macros/issue-30007.rs

Lines changed: 1 addition & 1 deletion
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() {

tests/ui/macros/issue-30007.stderr

Lines changed: 1 addition & 1 deletion
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 ; );

tests/ui/macros/issue-54441.rs

Lines changed: 1 addition & 1 deletion
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

tests/ui/macros/issue-54441.stderr

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)