Use multispan suggestions more often
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
This commit is contained in:
parent
5fb3394cbd
commit
0b8f192cfe
61 changed files with 661 additions and 442 deletions
|
@ -444,6 +444,30 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
/// Prints out a message with multiple suggested edits of the code.
|
||||
/// See also [`Diagnostic::span_suggestion()`].
|
||||
pub fn multipart_suggestions(
|
||||
&mut self,
|
||||
msg: &str,
|
||||
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: suggestions
|
||||
.map(|sugg| Substitution {
|
||||
parts: sugg
|
||||
.into_iter()
|
||||
.map(|(span, snippet)| SubstitutionPart { snippet, span })
|
||||
.collect(),
|
||||
})
|
||||
.collect(),
|
||||
msg: msg.to_owned(),
|
||||
style: SuggestionStyle::ShowCode,
|
||||
applicability,
|
||||
tool_metadata: Default::default(),
|
||||
});
|
||||
self
|
||||
}
|
||||
/// Prints out a message with a suggested edit of the code. If the suggestion is presented
|
||||
/// inline, it will only show the message and not the suggestion.
|
||||
///
|
||||
|
|
|
@ -301,6 +301,20 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
/// See [`Diagnostic::multipart_suggestions()`].
|
||||
pub fn multipart_suggestions(
|
||||
&mut self,
|
||||
msg: &str,
|
||||
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
if !self.0.allow_suggestions {
|
||||
return self;
|
||||
}
|
||||
self.0.diagnostic.multipart_suggestions(msg, suggestions, applicability);
|
||||
self
|
||||
}
|
||||
|
||||
/// See [`Diagnostic::span_suggestion_short()`].
|
||||
pub fn span_suggestion_short(
|
||||
&mut self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue