Skip to content

Commit 519dd8e

Browse files
committed
migrate ambiguous plus diagnostic
1 parent eb55cdc commit 519dd8e

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
parser-struct-literal-body-without-path =
22
struct literal body without path
33
.suggestion = you might have forgotten to add the struct literal inside the block
4+
parser-maybe-report-ambiguous-plus =
5+
ambiguous `+` in a type
6+
.suggestion = use parentheses to disambiguate

compiler/rustc_parse/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1313
rustc_data_structures = { path = "../rustc_data_structures" }
1414
rustc_feature = { path = "../rustc_feature" }
1515
rustc_lexer = { path = "../rustc_lexer" }
16+
rustc_macros = { path = "../rustc_macros" }
1617
rustc_errors = { path = "../rustc_errors" }
1718
rustc_session = { path = "../rustc_session" }
1819
rustc_span = { path = "../rustc_span" }

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, Er
2121
use rustc_errors::{
2222
Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
2323
};
24+
use rustc_macros::SessionDiagnostic;
2425
use rustc_span::source_map::Spanned;
2526
use rustc_span::symbol::{kw, Ident};
2627
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
@@ -1170,16 +1171,29 @@ impl<'a> Parser<'a> {
11701171
impl_dyn_multi: bool,
11711172
ty: &Ty,
11721173
) {
1174+
#[derive(SessionDiagnostic)]
1175+
#[error(slug = "parser-maybe-report-ambiguous-plus")]
1176+
struct AmbiguousPlus {
1177+
pub sum_with_parens: String,
1178+
#[primary_span]
1179+
#[suggestion(code = "{sum_with_parens}")]
1180+
pub span: Span,
1181+
}
1182+
11731183
if matches!(allow_plus, AllowPlus::No) && impl_dyn_multi {
1174-
let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
1175-
self.struct_span_err(ty.span, "ambiguous `+` in a type")
1176-
.span_suggestion(
1177-
ty.span,
1178-
"use parentheses to disambiguate",
1179-
sum_with_parens,
1180-
Applicability::MachineApplicable,
1181-
)
1182-
.emit();
1184+
self.sess.emit_err(AmbiguousPlus {
1185+
sum_with_parens: format!("({})", pprust::ty_to_string(&ty)),
1186+
span: ty.span,
1187+
});
1188+
// let sum_with_parens = format!("({})", pprust::ty_to_string(&ty));
1189+
// self.struct_span_err(ty.span, "ambiguous `+` in a type")
1190+
// .span_suggestion(
1191+
// ty.span,
1192+
// "use parentheses to disambiguate",
1193+
// sum_with_parens,
1194+
// Applicability::MachineApplicable,
1195+
// )
1196+
// .emit();
11831197
}
11841198
}
11851199

0 commit comments

Comments
 (0)