1
Fork 0

When encountering struct fn call literal with private fields, suggest all builders

When encountering code like `Box(42)`, suggest `Box::new(42)` and *all*
other associated functions that return `-> Box<T>`.
This commit is contained in:
Esteban Küber 2023-11-07 19:32:48 +00:00
parent 27794f95fd
commit 42aa1273b0
9 changed files with 98 additions and 43 deletions

View file

@ -759,6 +759,9 @@ impl Diagnostic {
suggestions: impl IntoIterator<Item = String>,
applicability: Applicability,
) -> &mut Self {
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
suggestions.sort();
self.span_suggestions_with_style(
sp,
msg,
@ -768,7 +771,9 @@ impl Diagnostic {
)
}
/// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`].
/// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`]. This version
/// *doesn't* sort the suggestions, so the caller has control of the order in which they are
/// presented.
pub fn span_suggestions_with_style(
&mut self,
sp: Span,
@ -777,9 +782,7 @@ impl Diagnostic {
applicability: Applicability,
style: SuggestionStyle,
) -> &mut Self {
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
suggestions.sort();
let suggestions: Vec<_> = suggestions.into_iter().collect();
debug_assert!(
!(sp.is_empty() && suggestions.iter().any(|suggestion| suggestion.is_empty())),
"Span must not be empty and have no suggestion"