-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Remove usages of span_suggestion without Applicability #54241
Changes from 9 commits
b6fea32
2f5cb6d
4b05128
959fc61
3be24c6
f395072
6ebb916
0ad1c0e
c61f4a7
2b77760
0269e66
15982fe
d0790c4
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 |
---|---|---|
|
@@ -867,10 +867,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
}) = cmt.cat { | ||
db.note(fn_closure_msg); | ||
} else { | ||
db.span_suggestion(sp, msg, suggestion); | ||
db.span_suggestion_with_applicability( | ||
sp, | ||
msg, | ||
suggestion, | ||
Applicability::Unspecified, | ||
); | ||
} | ||
} else { | ||
db.span_suggestion(sp, msg, suggestion); | ||
db.span_suggestion_with_applicability( | ||
sp, | ||
msg, | ||
suggestion, | ||
Applicability::Unspecified, | ||
); | ||
} | ||
} | ||
_ => { | ||
|
@@ -1236,10 +1246,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
let let_span = self.tcx.hir.span(node_id); | ||
let suggestion = suggest_ref_mut(self.tcx, let_span); | ||
if let Some(replace_str) = suggestion { | ||
db.span_suggestion( | ||
db.span_suggestion_with_applicability( | ||
let_span, | ||
"use a mutable reference instead", | ||
replace_str, | ||
Applicability::Unspecified, | ||
vi marked this conversation as resolved.
Show resolved
Hide resolved
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.
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. @killercup Won't it cause the final code to be something along the lines of 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. rustfix works by replacing specific byte ranges. Once a part of the file has been replaced, rustfix will yell at you when you try to replace it against. cargo-fix will then try to resolve this in some ways (see link above) |
||
); | ||
} | ||
} | ||
|
@@ -1292,11 +1303,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
)) = ty.map(|t| &t.node) | ||
{ | ||
let borrow_expr_id = self.tcx.hir.get_parent_node(borrowed_node_id); | ||
db.span_suggestion( | ||
db.span_suggestion_with_applicability( | ||
self.tcx.hir.span(borrow_expr_id), | ||
"consider removing the `&mut`, as it is an \ | ||
immutable binding to a mutable reference", | ||
snippet | ||
snippet, | ||
Applicability::Unspecified, | ||
vi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} else { | ||
db.span_suggestion_with_applicability( | ||
|
@@ -1326,12 +1338,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { | |
&cmt_path_or_string, | ||
capture_span, | ||
Origin::Ast) | ||
.span_suggestion(err.span, | ||
&format!("to force the closure to take ownership of {} \ | ||
(and any other referenced variables), \ | ||
use the `move` keyword", | ||
cmt_path_or_string), | ||
suggestion) | ||
.span_suggestion_with_applicability( | ||
err.span, | ||
&format!("to force the closure to take ownership of {} \ | ||
(and any other referenced variables), \ | ||
use the `move` keyword", | ||
cmt_path_or_string), | ||
suggestion, | ||
Applicability::Unspecified, | ||
) | ||
vi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.emit(); | ||
self.signal_error(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`")] | ||
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. ❤️ 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 wonder how this affects other tools that might be using it. They will have to add 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've prepared a similar pull request for Clippy (with similar style/formatting mistakes), but it may intersect existing Applicability-assigning pull request there. |
||
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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,25 +39,28 @@ 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) => { | ||
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. What's the reason for this change? It seems to me that including the 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. Inside the macro call, it was requested to update it to new style (each argument on separate line). This looks better with trailing commas, but original macro didn't support trailing commas. Seeing no easy way to make it accept optional trailing comma, I just made it accept non-optional trailing comma. This cascaded into changing all invocations (and one-line invocations just got in the way). 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.
For me diff/merge-friendliness brought by trailing commas typically trumps niceness for eye. So if there can only be one, it should be with the commas. 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. Remembered that there's |
||
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 | ||
} | ||
}; | ||
|
||
// 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<S: Into<MultiSpan>>(&mut self, $($name: $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 | ||
} | ||
|
@@ -144,49 +147,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 note(&mut self, msg: &str,) -> &mut Self); | ||
vi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
forward!(pub fn span_note<S: Into<MultiSpan>>(&mut self, | ||
sp: S, | ||
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); | ||
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, | ||
|
@@ -240,8 +269,8 @@ impl<'a> DiagnosticBuilder<'a> { | |
); | ||
self | ||
} | ||
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self); | ||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self); | ||
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S,) -> &mut Self); | ||
forward!(pub fn code(&mut self, s: DiagnosticId,) -> &mut Self); | ||
|
||
pub fn allow_suggestions(&mut self, allow: bool) -> &mut Self { | ||
self.allow_suggestions = allow; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see what the formatting commits were about now: Please, for all the people who like split diffs, indent the arguments just one level and not visually :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vi the only thing left is the formatting here (and elsewhere) should have the arguments indented one level (four spaces):