Skip to content

Commit 9b41541

Browse files
committed
Auto merge of #76541 - matthiaskrgr:unstable_sort, r=davidtwco
use sort_unstable to sort primitive types It's not important to retain original order if we have &[1, 1, 2, 3] for example. clippy::stable_sort_primitive
2 parents 41dc394 + b4935e0 commit 9b41541

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

compiler/rustc_ast/src/util/lev_distance.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ fn find_match_by_sorted_words<'a>(iter_names: Vec<&'a Symbol>, lookup: &str) ->
103103

104104
fn sort_by_words(name: &str) -> String {
105105
let mut split_words: Vec<&str> = name.split('_').collect();
106-
split_words.sort();
106+
// We are sorting primitive &strs and can use unstable sort here
107+
split_words.sort_unstable();
107108
split_words.join("_")
108109
}

compiler/rustc_ast_lowering/src/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11211121
// features. We check that at least one type is available for
11221122
// the current target.
11231123
let reg_class = reg.reg_class();
1124-
let mut required_features = vec![];
1124+
let mut required_features: Vec<&str> = vec![];
11251125
for &(_, feature) in reg_class.supported_types(asm_arch) {
11261126
if let Some(feature) = feature {
11271127
if self.sess.target_features.contains(&Symbol::intern(feature)) {
@@ -1135,7 +1135,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11351135
break;
11361136
}
11371137
}
1138-
required_features.sort();
1138+
// We are sorting primitive strs here and can use unstable sort here
1139+
required_features.sort_unstable();
11391140
required_features.dedup();
11401141
match &required_features[..] {
11411142
[] => {}

compiler/rustc_lint/src/non_ascii_idents.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ impl EarlyLintPass for NonAsciiIdents {
341341
}
342342
}
343343

344-
ch_list.sort();
344+
// We sort primitive chars here and can use unstable sort
345+
ch_list.sort_unstable();
345346
ch_list.dedup();
346347
lint_reports.insert((sp, ch_list), augment_script_set);
347348
}

compiler/rustc_mir/src/monomorphize/partitioning/merging.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ pub fn merge_codegen_units<'tcx>(
7474

7575
// Sort the names, so things are deterministic and easy to
7676
// predict.
77-
cgu_contents.sort();
77+
78+
// We are sorting primitive &strs here so we can use unstable sort
79+
cgu_contents.sort_unstable();
7880

7981
(current_cgu_name, cgu_contents.join("--"))
8082
})

compiler/rustc_mir/src/transform/simplify_try.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ fn get_arm_identity_info<'a, 'tcx>(
230230
}
231231
}
232232
}
233-
234-
nop_stmts.sort();
233+
// We sort primitive usize here so we can use unstable sort
234+
nop_stmts.sort_unstable();
235235

236236
// Use one of the statements we're going to discard between the point
237237
// where the storage location for the variant field becomes live and

compiler/rustc_typeck/src/check/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4285,11 +4285,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
42854285
None
42864286
}
42874287
})
4288-
.collect::<Vec<_>>();
4288+
.collect::<Vec<usize>>();
42894289

42904290
// Both checked and coerced types could have matched, thus we need to remove
42914291
// duplicates.
4292-
referenced_in.sort();
4292+
4293+
// We sort primitive type usize here and can use unstable sort
4294+
referenced_in.sort_unstable();
42934295
referenced_in.dedup();
42944296

42954297
if let (Some(ref_in), None) = (referenced_in.pop(), referenced_in.pop()) {

0 commit comments

Comments
 (0)