diff options
| author | Christian Poveda <git@pvdrz.com> | 2022-04-25 22:55:15 +0200 |
|---|---|---|
| committer | Christian Poveda <git@pvdrz.com> | 2022-04-25 22:55:15 +0200 |
| commit | 519dd8e9de1a85e18b3033a007a3bf01c6e79560 (patch) | |
| tree | 9b384cc1fdf7ca794b51b6688671769a56278a2a /compiler/rustc_parse/src/parser | |
| parent | eb55cdce4bc1c03e1ce805af633dac611a948d43 (diff) | |
| download | rust-519dd8e9de1a85e18b3033a007a3bf01c6e79560.tar.gz rust-519dd8e9de1a85e18b3033a007a3bf01c6e79560.zip | |
migrate ambiguous plus diagnostic
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index ed264045170..d270f3606d7 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -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}; @@ -1170,16 +1171,29 @@ impl<'a> Parser<'a> { impl_dyn_multi: bool, 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 { - 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_with_parens: format!("({})", pprust::ty_to_string(&ty)), + span: ty.span, + }); + // 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(); } } |
