@@ -762,7 +762,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
762
762
if let Some ( rib) = & self . last_block_rib
763
763
&& let RibKind :: Normal = rib. kind
764
764
{
765
- for ( ident, & res) in & rib. bindings {
765
+ // It is sorted before usage so ordering is not important here.
766
+ #[ allow( rustc:: potential_query_instability) ]
767
+ let mut bindings: Vec < _ > = rib. bindings . clone ( ) . into_iter ( ) . collect ( ) ;
768
+ bindings. sort_by_key ( |( ident, _) | ident. span ) ;
769
+
770
+ for ( ident, res) in & bindings {
766
771
if let Res :: Local ( _) = res
767
772
&& path. len ( ) == 1
768
773
&& ident. span . eq_ctxt ( path[ 0 ] . ident . span )
@@ -944,7 +949,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
944
949
if let Some ( err_code) = err. code {
945
950
if err_code == E0425 {
946
951
for label_rib in & self . label_ribs {
947
- for ( label_ident, node_id) in & label_rib. bindings {
952
+ // It is sorted before usage so ordering is not important here.
953
+ #[ allow( rustc:: potential_query_instability) ]
954
+ let mut bindings: Vec < _ > = label_rib. bindings . clone ( ) . into_iter ( ) . collect ( ) ;
955
+ bindings. sort_by_key ( |( ident, _) | ident. span ) ;
956
+
957
+ for ( label_ident, node_id) in & bindings {
948
958
let ident = path. last ( ) . unwrap ( ) . ident ;
949
959
if format ! ( "'{ident}" ) == label_ident. to_string ( ) {
950
960
err. span_label ( label_ident. span , "a label with a similar name exists" ) ;
@@ -2142,6 +2152,8 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
2142
2152
} ;
2143
2153
2144
2154
// Locals and type parameters
2155
+ // `names` is sorted below so ordering is not important here.
2156
+ #[ allow( rustc:: potential_query_instability) ]
2145
2157
for ( ident, & res) in & rib. bindings {
2146
2158
if filter_fn ( res) && ident. span . ctxt ( ) == rib_ctxt {
2147
2159
names. push ( TypoSuggestion :: typo_from_ident ( * ident, res) ) ;
@@ -2605,18 +2617,28 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
2605
2617
let within_scope = self . is_label_valid_from_rib ( rib_index) ;
2606
2618
2607
2619
let rib = & self . label_ribs [ rib_index] ;
2608
- let names = rib
2620
+ // `names` is sorted below so ordering is not important here.
2621
+ #[ allow( rustc:: potential_query_instability) ]
2622
+ let mut names = rib
2609
2623
. bindings
2610
2624
. iter ( )
2611
2625
. filter ( |( id, _) | id. span . eq_ctxt ( label. span ) )
2612
2626
. map ( |( id, _) | id. name )
2613
2627
. collect :: < Vec < Symbol > > ( ) ;
2614
2628
2629
+ // Make sure error reporting is deterministic.
2630
+ names. sort ( ) ;
2631
+
2615
2632
find_best_match_for_name ( & names, label. name , None ) . map ( |symbol| {
2633
+ // It is sorted before usage so ordering is not important here.
2634
+ #[ allow( rustc:: potential_query_instability) ]
2635
+ let mut bindings: Vec < _ > = rib. bindings . clone ( ) . into_iter ( ) . collect ( ) ;
2636
+ bindings. sort_by_key ( |( ident, _) | ident. span ) ;
2637
+
2616
2638
// Upon finding a similar name, get the ident that it was from - the span
2617
2639
// contained within helps make a useful diagnostic. In addition, determine
2618
2640
// whether this candidate is within scope.
2619
- let ( ident, _) = rib . bindings . iter ( ) . find ( |( ident, _) | ident. name == symbol) . unwrap ( ) ;
2641
+ let ( ident, _) = bindings. iter ( ) . find ( |( ident, _) | ident. name == symbol) . unwrap ( ) ;
2620
2642
( * ident, within_scope)
2621
2643
} )
2622
2644
}
0 commit comments