From 42aa1273b0dd317c4aafdcf649f40cbad4499b60 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Tue, 7 Nov 2023 19:32:48 +0000 Subject: 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`. --- compiler/rustc_errors/src/diagnostic.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_errors') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 470f318eb33..b379d17dc22 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -759,6 +759,9 @@ impl Diagnostic { suggestions: impl IntoIterator, 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" -- cgit 1.4.1-3-g733a5