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
|
@ -165,13 +165,13 @@ parser_use_empty_block_not_semi = expected { "`{}`" }, found `;`
|
||||||
.suggestion = try using { "`{}`" } instead
|
.suggestion = try using { "`{}`" } instead
|
||||||
|
|
||||||
parser_comparison_interpreted_as_generic =
|
parser_comparison_interpreted_as_generic =
|
||||||
`<` is interpreted as a start of generic arguments for `{$typename}`, not a comparison
|
`<` is interpreted as a start of generic arguments for `{$type}`, not a comparison
|
||||||
.label_args = interpreted as generic arguments
|
.label_args = interpreted as generic arguments
|
||||||
.label_comparison = not interpreted as comparison
|
.label_comparison = not interpreted as comparison
|
||||||
.suggestion = try comparing the cast value
|
.suggestion = try comparing the cast value
|
||||||
|
|
||||||
parser_shift_interpreted_as_generic =
|
parser_shift_interpreted_as_generic =
|
||||||
`<<` is interpreted as a start of generic arguments for `{$typename}`, not a shift
|
`<<` is interpreted as a start of generic arguments for `{$type}`, not a shift
|
||||||
.label_args = interpreted as generic arguments
|
.label_args = interpreted as generic arguments
|
||||||
.label_comparison = not interpreted as shift
|
.label_comparison = not interpreted as shift
|
||||||
.suggestion = try shifting the cast value
|
.suggestion = try shifting the cast value
|
||||||
|
@ -184,8 +184,8 @@ parser_leading_plus_not_supported = leading `+` is not supported
|
||||||
.suggestion_remove_plus = try removing the `+`
|
.suggestion_remove_plus = try removing the `+`
|
||||||
|
|
||||||
parser_parentheses_with_struct_fields = invalid `struct` delimiters or `fn` call arguments
|
parser_parentheses_with_struct_fields = invalid `struct` delimiters or `fn` call arguments
|
||||||
.suggestion_braces_for_struct = if `{$name}` is a struct, use braces as delimiters
|
.suggestion_braces_for_struct = if `{$type}` is a struct, use braces as delimiters
|
||||||
.suggestion_no_fields_for_fn = if `{$name}` is a function, use the arguments directly
|
.suggestion_no_fields_for_fn = if `{$type}` is a function, use the arguments directly
|
||||||
|
|
||||||
parser_labeled_loop_in_break = parentheses are required around this expression to avoid confusion with a labeled break expression
|
parser_labeled_loop_in_break = parentheses are required around this expression to avoid confusion with a labeled break expression
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use rustc_ast::Path;
|
||||||
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
|
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
|
||||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||||
use rustc_session::errors::ExprParenthesesNeeded;
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
|
@ -536,7 +537,7 @@ pub(crate) struct ComparisonInterpretedAsGeneric {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label(parser::label_comparison)]
|
#[label(parser::label_comparison)]
|
||||||
pub comparison: Span,
|
pub comparison: Span,
|
||||||
pub typename: String,
|
pub r#type: Path,
|
||||||
#[label(parser::label_args)]
|
#[label(parser::label_args)]
|
||||||
pub args: Span,
|
pub args: Span,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
|
@ -549,7 +550,7 @@ pub(crate) struct ShiftInterpretedAsGeneric {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label(parser::label_comparison)]
|
#[label(parser::label_comparison)]
|
||||||
pub shift: Span,
|
pub shift: Span,
|
||||||
pub typename: String,
|
pub r#type: Path,
|
||||||
#[label(parser::label_args)]
|
#[label(parser::label_args)]
|
||||||
pub args: Span,
|
pub args: Span,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
|
@ -597,7 +598,7 @@ pub(crate) struct LeadingPlusNotSupported {
|
||||||
pub(crate) struct ParenthesesWithStructFields {
|
pub(crate) struct ParenthesesWithStructFields {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: String,
|
pub r#type: Path,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub braces_for_struct: BracesForStructLiteral,
|
pub braces_for_struct: BracesForStructLiteral,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
|
|
|
@ -756,11 +756,12 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
match self.parse_path(PathStyle::Expr) {
|
match self.parse_path(PathStyle::Expr) {
|
||||||
Ok(path) => {
|
Ok(path) => {
|
||||||
let typename = pprust::path_to_string(&path);
|
|
||||||
|
|
||||||
let span_after_type = parser_snapshot_after_type.token.span;
|
let span_after_type = parser_snapshot_after_type.token.span;
|
||||||
let expr =
|
let expr = mk_expr(
|
||||||
mk_expr(self, lhs, self.mk_ty(path.span, TyKind::Path(None, path)));
|
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 args_span = self.look_ahead(1, |t| t.span).to(span_after_type);
|
||||||
let suggestion = ComparisonOrShiftInterpretedAsGenericSugg {
|
let suggestion = ComparisonOrShiftInterpretedAsGenericSugg {
|
||||||
|
@ -771,14 +772,14 @@ impl<'a> Parser<'a> {
|
||||||
match self.token.kind {
|
match self.token.kind {
|
||||||
token::Lt => self.sess.emit_err(ComparisonInterpretedAsGeneric {
|
token::Lt => self.sess.emit_err(ComparisonInterpretedAsGeneric {
|
||||||
comparison: self.token.span,
|
comparison: self.token.span,
|
||||||
typename,
|
r#type: path,
|
||||||
args: args_span,
|
args: args_span,
|
||||||
suggestion,
|
suggestion,
|
||||||
}),
|
}),
|
||||||
token::BinOp(token::Shl) => {
|
token::BinOp(token::Shl) => {
|
||||||
self.sess.emit_err(ShiftInterpretedAsGeneric {
|
self.sess.emit_err(ShiftInterpretedAsGeneric {
|
||||||
shift: self.token.span,
|
shift: self.token.span,
|
||||||
typename,
|
r#type: path,
|
||||||
args: args_span,
|
args: args_span,
|
||||||
suggestion,
|
suggestion,
|
||||||
})
|
})
|
||||||
|
@ -1197,9 +1198,8 @@ impl<'a> Parser<'a> {
|
||||||
) -> Option<P<Expr>> {
|
) -> Option<P<Expr>> {
|
||||||
match (seq.as_mut(), snapshot) {
|
match (seq.as_mut(), snapshot) {
|
||||||
(Err(err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
|
(Err(err), Some((mut snapshot, ExprKind::Path(None, path)))) => {
|
||||||
let name = pprust::path_to_string(&path);
|
|
||||||
snapshot.bump(); // `(`
|
snapshot.bump(); // `(`
|
||||||
match snapshot.parse_struct_fields(path, false, Delimiter::Parenthesis) {
|
match snapshot.parse_struct_fields(path.clone(), false, Delimiter::Parenthesis) {
|
||||||
Ok((fields, ..))
|
Ok((fields, ..))
|
||||||
if snapshot.eat(&token::CloseDelim(Delimiter::Parenthesis)) =>
|
if snapshot.eat(&token::CloseDelim(Delimiter::Parenthesis)) =>
|
||||||
{
|
{
|
||||||
|
@ -1211,7 +1211,7 @@ impl<'a> Parser<'a> {
|
||||||
if !fields.is_empty() {
|
if !fields.is_empty() {
|
||||||
let mut replacement_err = ParenthesesWithStructFields {
|
let mut replacement_err = ParenthesesWithStructFields {
|
||||||
span,
|
span,
|
||||||
name,
|
r#type: path,
|
||||||
braces_for_struct: BracesForStructLiteral {
|
braces_for_struct: BracesForStructLiteral {
|
||||||
first: open_paren,
|
first: open_paren,
|
||||||
second: close_paren,
|
second: close_paren,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue