Skip to content

Commit 77e5b60

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.
1 parent 1cec373 commit 77e5b60

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
@@ -57,7 +57,7 @@ expand_helper_attribute_name_invalid =
5757
`{$name}` cannot be a name of derive helper attribute
5858
5959
expand_incomplete_parse =
60-
macro expansion ignores token `{$token}` and any following
60+
macro expansion ignores {$descr} and any tokens following
6161
.label = caused by the macro expansion here
6262
.note = the usage of `{$macro_path}!` is likely invalid in {$kind_name} context
6363
.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
@@ -297,7 +297,7 @@ pub(crate) struct UnsupportedKeyValue {
297297
pub(crate) struct IncompleteParse<'a> {
298298
#[primary_span]
299299
pub span: Span,
300-
pub token: Cow<'a, str>,
300+
pub descr: String,
301301
#[label]
302302
pub label_span: Span,
303303
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
@@ -25,7 +25,8 @@ use rustc_data_structures::sync::Lrc;
2525
use rustc_errors::PResult;
2626
use rustc_feature::Features;
2727
use rustc_parse::parser::{
28-
AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma,
28+
token_descr, AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon,
29+
RecoverComma,
2930
};
3031
use rustc_parse::validate_attr;
3132
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
@@ -964,7 +965,7 @@ pub fn ensure_complete_parse<'a>(
964965
span: Span,
965966
) {
966967
if parser.token != token::Eof {
967-
let token = pprust::token_to_string(&parser.token);
968+
let descr = token_descr(&parser.token);
968969
// Avoid emitting backtrace info twice.
969970
let def_site_span = parser.token.span.with_ctxt(SyntaxContext::root());
970971

@@ -980,7 +981,7 @@ pub fn ensure_complete_parse<'a>(
980981

981982
parser.dcx().emit_err(IncompleteParse {
982983
span: def_site_span,
983-
token,
984+
descr,
984985
label_span: span,
985986
macro_path,
986987
kind_name,

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl TokenDescription {
397397
}
398398
}
399399

400-
pub(super) fn token_descr(token: &Token) -> String {
400+
pub fn token_descr(token: &Token) -> String {
401401
let name = pprust::token_to_string(token).to_string();
402402

403403
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
() => {}
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)