Rollup merge of #96405 - pvdrz:ambiguous-plus-diagnostic, r=davidtwco
Migrate ambiguous plus diagnostic to the new derive macro r? ````@davidtwco```` ````@jyn514````
This commit is contained in:
commit
b3329f84f4
7 changed files with 44 additions and 15 deletions
|
@ -21,6 +21,7 @@ use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, Er
|
|||
use rustc_errors::{
|
||||
Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
|
||||
};
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
||||
|
@ -241,6 +242,16 @@ impl MultiSugg {
|
|||
err.multipart_suggestions(msg, suggestions.map(|s| s.patches), applicability);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(slug = "parser-maybe-report-ambiguous-plus")]
|
||||
struct AmbiguousPlus {
|
||||
pub sum_ty: String,
|
||||
#[primary_span]
|
||||
#[suggestion(code = "({sum_ty})")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
// SnapshotParser is used to create a snapshot of the parser
|
||||
// without causing duplicate errors being emitted when the `Parser`
|
||||
// is dropped.
|
||||
|
@ -1196,15 +1207,7 @@ impl<'a> Parser<'a> {
|
|||
ty: &Ty,
|
||||
) {
|
||||
if matches!(allow_plus, AllowPlus::No) && impl_dyn_multi {
|
||||
let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
|
||||
self.struct_span_err(ty.span, "ambiguous `+` in a type")
|
||||
.span_suggestion(
|
||||
ty.span,
|
||||
"use parentheses to disambiguate",
|
||||
sum_with_parens,
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
self.sess.emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(&ty), span: ty.span });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue