Rollup merge of #132332 - nnethercote:use-token_descr-more, r=estebank
Use `token_descr` more in error messages This is the first two commits from #124141, put into their own PR to get things rolling. Commit messages have the details. r? ``@estebank`` cc ``@petrochenkov``
This commit is contained in:
commit
2480e3bbc5
77 changed files with 152 additions and 159 deletions
|
@ -275,7 +275,7 @@ pub(crate) struct UnsupportedKeyValue {
|
|||
pub(crate) struct IncompleteParse<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub token: Cow<'a, str>,
|
||||
pub descr: String,
|
||||
#[label]
|
||||
pub label_span: Span,
|
||||
pub macro_path: &'a ast::Path,
|
||||
|
|
|
@ -21,6 +21,7 @@ use rustc_errors::PResult;
|
|||
use rustc_feature::Features;
|
||||
use rustc_parse::parser::{
|
||||
AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma,
|
||||
token_descr,
|
||||
};
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session::lint::BuiltinLintDiag;
|
||||
|
@ -1013,7 +1014,7 @@ pub(crate) fn ensure_complete_parse<'a>(
|
|||
span: Span,
|
||||
) {
|
||||
if parser.token != token::Eof {
|
||||
let token = pprust::token_to_string(&parser.token);
|
||||
let descr = token_descr(&parser.token);
|
||||
// Avoid emitting backtrace info twice.
|
||||
let def_site_span = parser.token.span.with_ctxt(SyntaxContext::root());
|
||||
|
||||
|
@ -1029,7 +1030,7 @@ pub(crate) fn ensure_complete_parse<'a>(
|
|||
|
||||
parser.dcx().emit_err(IncompleteParse {
|
||||
span: def_site_span,
|
||||
token,
|
||||
descr,
|
||||
label_span: span,
|
||||
macro_path,
|
||||
kind_name,
|
||||
|
|
|
@ -2,10 +2,9 @@ use std::borrow::Cow;
|
|||
|
||||
use rustc_ast::token::{self, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, DiagMessage};
|
||||
use rustc_macros::Subdiagnostic;
|
||||
use rustc_parse::parser::{Parser, Recovery};
|
||||
use rustc_parse::parser::{Parser, Recovery, token_descr};
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::Ident;
|
||||
|
@ -336,17 +335,11 @@ pub(super) fn annotate_doc_comment(err: &mut Diag<'_>, sm: &SourceMap, span: Spa
|
|||
/// other tokens, this is "unexpected token...".
|
||||
pub(super) fn parse_failure_msg(tok: &Token, expected_token: Option<&Token>) -> Cow<'static, str> {
|
||||
if let Some(expected_token) = expected_token {
|
||||
Cow::from(format!(
|
||||
"expected `{}`, found `{}`",
|
||||
pprust::token_to_string(expected_token),
|
||||
pprust::token_to_string(tok),
|
||||
))
|
||||
Cow::from(format!("expected {}, found {}", token_descr(expected_token), token_descr(tok)))
|
||||
} else {
|
||||
match tok.kind {
|
||||
token::Eof => Cow::from("unexpected end of macro invocation"),
|
||||
_ => {
|
||||
Cow::from(format!("no rules expected the token `{}`", pprust::token_to_string(tok)))
|
||||
}
|
||||
_ => Cow::from(format!("no rules expected {}", token_descr(tok))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,11 +78,10 @@ use std::rc::Rc;
|
|||
pub(crate) use NamedMatch::*;
|
||||
pub(crate) use ParseResult::*;
|
||||
use rustc_ast::token::{self, DocComment, NonterminalKind, Token};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_lint_defs::pluralize;
|
||||
use rustc_parse::parser::{ParseNtResult, Parser};
|
||||
use rustc_parse::parser::{ParseNtResult, Parser, token_descr};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
|
||||
|
||||
|
@ -150,7 +149,7 @@ impl Display for MatcherLoc {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
MatcherLoc::Token { token } | MatcherLoc::SequenceSep { separator: token } => {
|
||||
write!(f, "`{}`", pprust::token_to_string(token))
|
||||
write!(f, "{}", token_descr(token))
|
||||
}
|
||||
MatcherLoc::MetaVarDecl { bind, kind, .. } => {
|
||||
write!(f, "meta-variable `${bind}")?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue