File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
compiler/rustc_errors/src Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -630,18 +630,27 @@ impl Diagnostic {
630630 style : SuggestionStyle ,
631631 ) -> & mut Self {
632632 assert ! ( !suggestion. is_empty( ) ) ;
633- debug_assert ! (
634- !( suggestion. iter( ) . any( |( sp, text) | sp. is_empty( ) && text. is_empty( ) ) ) ,
635- "Span must not be empty and have no suggestion"
633+
634+ let mut parts = suggestion
635+ . into_iter ( )
636+ . map ( |( span, snippet) | SubstitutionPart { snippet, span } )
637+ . collect :: < Vec < _ > > ( ) ;
638+
639+ parts. sort_unstable_by_key ( |part| part. span ) ;
640+
641+ debug_assert_eq ! (
642+ None ,
643+ parts. iter( ) . find( |part| part. span. is_empty( ) && part. snippet. is_empty( ) ) ,
644+ "Span must not be empty and have no suggestion" ,
645+ ) ;
646+ debug_assert_eq ! (
647+ None ,
648+ parts. array_windows( ) . find( |[ a, b] | a. span. overlaps( b. span) ) ,
649+ "suggestion must not have overlapping parts" ,
636650 ) ;
637651
638652 self . push_suggestion ( CodeSuggestion {
639- substitutions : vec ! [ Substitution {
640- parts: suggestion
641- . into_iter( )
642- . map( |( span, snippet) | SubstitutionPart { snippet, span } )
643- . collect( ) ,
644- } ] ,
653+ substitutions : vec ! [ Substitution { parts } ] ,
645654 msg : self . subdiagnostic_message_to_diagnostic_message ( msg) ,
646655 style,
647656 applicability,
Original file line number Diff line number Diff line change 33//! This module contains the code for creating and emitting diagnostics.
44
55#![ doc( html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/" ) ]
6+ #![ feature( array_windows) ]
67#![ feature( drain_filter) ]
78#![ feature( if_let_guard) ]
89#![ feature( is_terminal) ]
You can’t perform that action at this time.
0 commit comments