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

Commit 94f6e5a

Browse files
nnethercotecompiler-errors
authored andcommitted
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 5e3ede2 commit 94f6e5a

27 files changed

+40
-39
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ expand_helper_attribute_name_invalid =
6868
`{$name}` cannot be a name of derive helper attribute
6969
7070
expand_incomplete_parse =
71-
macro expansion ignores token `{$token}` and any following
71+
macro expansion ignores {$descr} and any tokens following
7272
.label = caused by the macro expansion here
7373
.note = the usage of `{$macro_path}!` is likely invalid in {$kind_name} context
7474
.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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use rustc_data_structures::sync::Lrc;
2020
use rustc_errors::PResult;
2121
use rustc_feature::Features;
2222
use rustc_parse::parser::{
23-
AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma,
23+
token_descr, AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon,
24+
RecoverComma,
2425
};
2526
use rustc_parse::validate_attr;
2627
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
@@ -1011,7 +1012,7 @@ pub(crate) fn ensure_complete_parse<'a>(
10111012
span: Span,
10121013
) {
10131014
if parser.token != token::Eof {
1014-
let token = pprust::token_to_string(&parser.token);
1015+
let descr = token_descr(&parser.token);
10151016
// Avoid emitting backtrace info twice.
10161017
let def_site_span = parser.token.span.with_ctxt(SyntaxContext::root());
10171018

@@ -1027,7 +1028,7 @@ pub(crate) fn ensure_complete_parse<'a>(
10271028

10281029
parser.dcx().emit_err(IncompleteParse {
10291030
span: def_site_span,
1030-
token,
1031+
descr,
10311032
label_span: span,
10321033
macro_path,
10331034
kind_name,

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl TokenDescription {
420420
}
421421
}
422422

423-
pub(super) fn token_descr(token: &Token) -> String {
423+
pub fn token_descr(token: &Token) -> String {
424424
let name = pprust::token_to_string(token).to_string();
425425

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