about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorbohan <bohan-zhang@foxmail.com>2023-11-21 02:42:09 +0800
committerbohan <bohan-zhang@foxmail.com>2023-12-04 10:43:10 +0800
commit199098b71b7495fbbc91d62e20b831f17761c95b (patch)
tree03ec9c519fa0fd5f93841689ae7724f8570ffe54 /compiler/rustc_errors/src
parentc9808f87028e16d134438787cab3d4cc16d05fe2 (diff)
downloadrust-199098b71b7495fbbc91d62e20b831f17761c95b.tar.gz
rust-199098b71b7495fbbc91d62e20b831f17761c95b.zip
dedup for duplicate suggestions
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/diagnostic.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index 0aaa8ae69e1..d222010901f 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -622,17 +622,18 @@ impl Diagnostic {
     pub fn multipart_suggestion_with_style(
         &mut self,
         msg: impl Into<SubdiagnosticMessage>,
-        suggestion: Vec<(Span, String)>,
+        mut suggestion: Vec<(Span, String)>,
         applicability: Applicability,
         style: SuggestionStyle,
     ) -> &mut Self {
-        let mut parts = suggestion
+        suggestion.sort_unstable();
+        suggestion.dedup();
+
+        let parts = suggestion
             .into_iter()
             .map(|(span, snippet)| SubstitutionPart { snippet, span })
             .collect::<Vec<_>>();
 
-        parts.sort_unstable_by_key(|part| part.span);
-
         assert!(!parts.is_empty());
         debug_assert_eq!(
             parts.iter().find(|part| part.span.is_empty() && part.snippet.is_empty()),