Auto merge of #54241 - vi:suggest_with_applicability, r=estebank
Remove usages of span_suggestion without Applicability Use `Applicability::Unspecified` for all of them instead. Shall deprecations for the non-`_with_applicability` functions be added? Shall clippy be addressed somehow? r? @estebank
This commit is contained in:
commit
992d1e4d3d
22 changed files with 258 additions and 96 deletions
|
@ -232,6 +232,7 @@ impl Diagnostic {
|
|||
/// inline it will only show the text message and not the text.
|
||||
///
|
||||
/// See `CodeSuggestion` for more information.
|
||||
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
|
||||
pub fn span_suggestion_short(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: vec![Substitution {
|
||||
|
@ -263,6 +264,7 @@ impl Diagnostic {
|
|||
/// * may contain a name of a function, variable or type, but not whole expressions
|
||||
///
|
||||
/// See `CodeSuggestion` for more information.
|
||||
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
|
||||
pub fn span_suggestion(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: vec![Substitution {
|
||||
|
@ -278,10 +280,11 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn multipart_suggestion(
|
||||
pub fn multipart_suggestion_with_applicability(
|
||||
&mut self,
|
||||
msg: &str,
|
||||
suggestion: Vec<(Span, String)>,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: vec![Substitution {
|
||||
|
@ -292,12 +295,26 @@ impl Diagnostic {
|
|||
}],
|
||||
msg: msg.to_owned(),
|
||||
show_code_when_inline: true,
|
||||
applicability: Applicability::Unspecified,
|
||||
applicability,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
|
||||
pub fn multipart_suggestion(
|
||||
&mut self,
|
||||
msg: &str,
|
||||
suggestion: Vec<(Span, String)>,
|
||||
) -> &mut Self {
|
||||
self.multipart_suggestion_with_applicability(
|
||||
msg,
|
||||
suggestion,
|
||||
Applicability::Unspecified,
|
||||
)
|
||||
}
|
||||
|
||||
/// Prints out a message with multiple suggested edits of the code.
|
||||
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
|
||||
pub fn span_suggestions(&mut self, sp: Span, msg: &str, suggestions: Vec<String>) -> &mut Self {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: suggestions.into_iter().map(|snippet| Substitution {
|
||||
|
|
|
@ -43,16 +43,18 @@ pub struct DiagnosticBuilder<'a> {
|
|||
/// it easy to declare such methods on the builder.
|
||||
macro_rules! forward {
|
||||
// Forward pattern for &self -> &Self
|
||||
(pub fn $n:ident(&self, $($name:ident: $ty:ty),*) -> &Self) => {
|
||||
(pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self) => {
|
||||
pub fn $n(&self, $($name: $ty),*) -> &Self {
|
||||
#[allow(deprecated)]
|
||||
self.diagnostic.$n($($name),*);
|
||||
self
|
||||
}
|
||||
};
|
||||
|
||||
// Forward pattern for &mut self -> &mut Self
|
||||
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty),*) -> &mut Self) => {
|
||||
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self) => {
|
||||
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
|
||||
#[allow(deprecated)]
|
||||
self.diagnostic.$n($($name),*);
|
||||
self
|
||||
}
|
||||
|
@ -60,8 +62,12 @@ macro_rules! forward {
|
|||
|
||||
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
|
||||
// type parameter. No obvious way to make this more generic.
|
||||
(pub fn $n:ident<S: Into<MultiSpan>>(&mut self, $($name:ident: $ty:ty),*) -> &mut Self) => {
|
||||
(pub fn $n:ident<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
$($name:ident: $ty:ty),*
|
||||
$(,)*) -> &mut Self) => {
|
||||
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
|
||||
#[allow(deprecated)]
|
||||
self.diagnostic.$n($($name),*);
|
||||
self
|
||||
}
|
||||
|
@ -157,49 +163,75 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
forward!(pub fn note_expected_found(&mut self,
|
||||
label: &dyn fmt::Display,
|
||||
expected: DiagnosticStyledString,
|
||||
found: DiagnosticStyledString)
|
||||
-> &mut Self);
|
||||
found: DiagnosticStyledString,
|
||||
) -> &mut Self);
|
||||
|
||||
forward!(pub fn note_expected_found_extra(&mut self,
|
||||
label: &dyn fmt::Display,
|
||||
expected: DiagnosticStyledString,
|
||||
found: DiagnosticStyledString,
|
||||
expected_extra: &dyn fmt::Display,
|
||||
found_extra: &dyn fmt::Display)
|
||||
-> &mut Self);
|
||||
found_extra: &dyn fmt::Display,
|
||||
) -> &mut Self);
|
||||
|
||||
forward!(pub fn note(&mut self, msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_note<S: Into<MultiSpan>>(&mut self,
|
||||
sp: S,
|
||||
msg: &str)
|
||||
-> &mut Self);
|
||||
msg: &str,
|
||||
) -> &mut Self);
|
||||
forward!(pub fn warn(&mut self, msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_warn<S: Into<MultiSpan>>(&mut self, sp: S, msg: &str) -> &mut Self);
|
||||
forward!(pub fn help(&mut self , msg: &str) -> &mut Self);
|
||||
forward!(pub fn span_help<S: Into<MultiSpan>>(&mut self,
|
||||
sp: S,
|
||||
msg: &str)
|
||||
-> &mut Self);
|
||||
forward!(pub fn span_suggestion_short(&mut self,
|
||||
sp: Span,
|
||||
msg: &str,
|
||||
suggestion: String)
|
||||
-> &mut Self);
|
||||
msg: &str,
|
||||
) -> &mut Self);
|
||||
|
||||
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
|
||||
forward!(pub fn span_suggestion_short(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
msg: &str,
|
||||
suggestion: String,
|
||||
) -> &mut Self);
|
||||
|
||||
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
|
||||
forward!(pub fn multipart_suggestion(
|
||||
&mut self,
|
||||
msg: &str,
|
||||
suggestion: Vec<(Span, String)>
|
||||
suggestion: Vec<(Span, String)>,
|
||||
) -> &mut Self);
|
||||
|
||||
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
|
||||
forward!(pub fn span_suggestion(&mut self,
|
||||
sp: Span,
|
||||
msg: &str,
|
||||
suggestion: String)
|
||||
-> &mut Self);
|
||||
suggestion: String,
|
||||
) -> &mut Self);
|
||||
|
||||
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
|
||||
forward!(pub fn span_suggestions(&mut self,
|
||||
sp: Span,
|
||||
msg: &str,
|
||||
suggestions: Vec<String>)
|
||||
-> &mut Self);
|
||||
suggestions: Vec<String>,
|
||||
) -> &mut Self);
|
||||
|
||||
pub fn multipart_suggestion_with_applicability(&mut self,
|
||||
msg: &str,
|
||||
suggestion: Vec<(Span, String)>,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
if !self.allow_suggestions {
|
||||
return self
|
||||
}
|
||||
self.diagnostic.multipart_suggestion_with_applicability(
|
||||
msg,
|
||||
suggestion,
|
||||
applicability,
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn span_suggestion_with_applicability(&mut self,
|
||||
sp: Span,
|
||||
msg: &str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue