Don't unnecessarily stringify paths in diagnostics
This commit is contained in:
parent
caefac034e
commit
37fdcb4b36
3 changed files with 17 additions and 16 deletions
|
@ -1,3 +1,4 @@
|
|||
use rustc_ast::Path;
|
||||
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_session::errors::ExprParenthesesNeeded;
|
||||
|
@ -536,7 +537,7 @@ pub(crate) struct ComparisonInterpretedAsGeneric {
|
|||
#[primary_span]
|
||||
#[label(parser::label_comparison)]
|
||||
pub comparison: Span,
|
||||
pub typename: String,
|
||||
pub r#type: Path,
|
||||
#[label(parser::label_args)]
|
||||
pub args: Span,
|
||||
#[subdiagnostic]
|
||||
|
@ -549,7 +550,7 @@ pub(crate) struct ShiftInterpretedAsGeneric {
|
|||
#[primary_span]
|
||||
#[label(parser::label_comparison)]
|
||||
pub shift: Span,
|
||||
pub typename: String,
|
||||
pub r#type: Path,
|
||||
#[label(parser::label_args)]
|
||||
pub args: Span,
|
||||
#[subdiagnostic]
|
||||
|
@ -597,7 +598,7 @@ pub(crate) struct LeadingPlusNotSupported {
|
|||
pub(crate) struct ParenthesesWithStructFields {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub name: String,
|
||||
pub r#type: Path,
|
||||
#[subdiagnostic]
|
||||
pub braces_for_struct: BracesForStructLiteral,
|
||||
#[subdiagnostic]
|
||||
|
|
|
@ -756,11 +756,12 @@ impl<'a> Parser<'a> {
|
|||
|
||||
match self.parse_path(PathStyle::Expr) {
|
||||
Ok(path) => {
|
||||
let typename = pprust::path_to_string(&path);
|
||||
|
||||
let span_after_type = parser_snapshot_after_type.token.span;
|
||||
let expr =
|
||||
mk_expr(self, lhs, self.mk_ty(path.span, TyKind::Path(None, path)));
|
||||
let expr = mk_expr(
|
||||
self,
|
||||
lhs,
|
||||
self.mk_ty(path.span, TyKind::Path(None, path.clone())),
|
||||
);
|
||||
|
||||
let args_span = self.look_ahead(1, |t| t.span).to(span_after_type);
|
||||
let suggestion = ComparisonOrShiftInterpretedAsGenericSugg {
|
||||
|
@ -771,14 +772,14 @@ impl<'a> Parser<'a> {
|
|||
match self.token.kind {
|
||||
token::Lt => self.sess.emit_err(ComparisonInterpretedAsGeneric {
|
||||
comparison: self.token.span,
|
||||
typename,
|
||||
r#type: path,
|
||||
args: args_span,
|
||||
suggestion,
|
||||
}),
|
||||
token::BinOp(token::Shl) => {
|
||||
self.sess.emit_err(ShiftInterpretedAsGeneric {
|
||||
shift: self.token.span,
|
||||
typename,
|
||||
r#type: path,
|
||||
args: args_span,
|
||||
suggestion,
|
||||
})
|
||||
|
@ -1197,9 +1198,8 @@ impl<'a> Parser<'a> {
|
|||
) -> Option<P<Expr>> {
|
||||
match (seq.as_mut(), snapshot) {
|
||||
(Err(err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
|
||||
let name = pprust::path_to_string(&path);
|
||||
snapshot.bump(); // `(`
|
||||
match snapshot.parse_struct_fields(path, false, Delimiter::Parenthesis) {
|
||||
match snapshot.parse_struct_fields(path.clone(), false, Delimiter::Parenthesis) {
|
||||
Ok((fields, ..))
|
||||
if snapshot.eat(&token::CloseDelim(Delimiter::Parenthesis)) =>
|
||||
{
|
||||
|
@ -1211,7 +1211,7 @@ impl<'a> Parser<'a> {
|
|||
if !fields.is_empty() {
|
||||
let mut replacement_err = ParenthesesWithStructFields {
|
||||
span,
|
||||
name,
|
||||
r#type: path,
|
||||
braces_for_struct: BracesForStructLiteral {
|
||||
first: open_paren,
|
||||
second: close_paren,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue