-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Migrate ambiguous plus diagnostic to the new derive macro #96405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
eb55cdc
519dd8e
d6da5fb
5874b09
530f4dc
2e261a8
35b42cb
6c3e793
1e35bab
e7ae9eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
parser-struct-literal-body-without-path = | ||
struct literal body without path | ||
.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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,20 @@ impl<'a> Parser<'a> { | |
impl_dyn_multi: bool, | ||
ty: &Ty, | ||
) { | ||
#[derive(SessionDiagnostic)] | ||
#[error(slug = "parser-maybe-report-ambiguous-plus")] | ||
struct AmbiguousPlus { | ||
pvdrz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub sum_with_parens: String, | ||
#[primary_span] | ||
#[suggestion(code = "{sum_with_parens}")] | ||
pub span: Span, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't want to push more work on you, but this might be a good time to check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be happy to do it but I couldn't find any examples on how to use it. |
||
|
||
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)), | ||
pvdrz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
span: ty.span, | ||
}); | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.