@@ -21,6 +21,7 @@ use rustc_errors::{pluralize, struct_span_err, Diagnostic, EmissionGuarantee, Er
2121use rustc_errors:: {
2222 Applicability , DiagnosticBuilder , DiagnosticMessage , Handler , MultiSpan , PResult ,
2323} ;
24+ use rustc_macros:: SessionDiagnostic ;
2425use rustc_span:: source_map:: Spanned ;
2526use rustc_span:: symbol:: { kw, Ident } ;
2627use 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