mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
migrate ambiguous plus diagnostic
This commit is contained in:
parent
eb55cdce4b
commit
519dd8e9de
@ -1,3 +1,6 @@
|
|||||||
parser-struct-literal-body-without-path =
|
parser-struct-literal-body-without-path =
|
||||||
struct literal body without path
|
struct literal body without path
|
||||||
.suggestion = you might have forgotten to add the struct literal inside the block
|
.suggestion = you might have forgotten to add the struct literal inside the block
|
||||||
|
parser-maybe-report-ambiguous-plus =
|
||||||
|
ambiguous `+` in a type
|
||||||
|
.suggestion = use parentheses to disambiguate
|
||||||
|
@ -13,6 +13,7 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" }
|
|||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
rustc_feature = { path = "../rustc_feature" }
|
rustc_feature = { path = "../rustc_feature" }
|
||||||
rustc_lexer = { path = "../rustc_lexer" }
|
rustc_lexer = { path = "../rustc_lexer" }
|
||||||
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc_errors = { path = "../rustc_errors" }
|
rustc_errors = { path = "../rustc_errors" }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
|
@ -21,6 +21,7 @@ use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, Er
|
|||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
|
Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
|
||||||
};
|
};
|
||||||
|
use rustc_macros::SessionDiagnostic;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, Ident};
|
use rustc_span::symbol::{kw, Ident};
|
||||||
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
||||||
@ -1170,16 +1171,29 @@ impl<'a> Parser<'a> {
|
|||||||
impl_dyn_multi: bool,
|
impl_dyn_multi: bool,
|
||||||
ty: &Ty,
|
ty: &Ty,
|
||||||
) {
|
) {
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[error(slug = "parser-maybe-report-ambiguous-plus")]
|
||||||
|
struct AmbiguousPlus {
|
||||||
|
pub sum_with_parens: String,
|
||||||
|
#[primary_span]
|
||||||
|
#[suggestion(code = "{sum_with_parens}")]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
if matches!(allow_plus, AllowPlus::No) && impl_dyn_multi {
|
if matches!(allow_plus, AllowPlus::No) && impl_dyn_multi {
|
||||||
let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
|
self.sess.emit_err(AmbiguousPlus {
|
||||||
self.struct_span_err(ty.span, "ambiguous `+` in a type")
|
sum_with_parens: format!("({})", pprust::ty_to_string(&ty)),
|
||||||
.span_suggestion(
|
span: ty.span,
|
||||||
ty.span,
|
});
|
||||||
"use parentheses to disambiguate",
|
// let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
|
||||||
sum_with_parens,
|
// self.struct_span_err(ty.span, "ambiguous `+` in a type")
|
||||||
Applicability::MachineApplicable,
|
// .span_suggestion(
|
||||||
)
|
// ty.span,
|
||||||
.emit();
|
// "use parentheses to disambiguate",
|
||||||
|
// sum_with_parens,
|
||||||
|
// Applicability::MachineApplicable,
|
||||||
|
// )
|
||||||
|
// .emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user