]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/stable_sort_primitive.fixed
Rollup merge of #102454 - chenyukang:fix-102396-missing-parentheses, r=lcnr
[rust.git] / src / tools / clippy / tests / ui / stable_sort_primitive.fixed
1 // run-rustfix
2 #![warn(clippy::stable_sort_primitive)]
3
4 fn main() {
5     // positive examples
6     let mut vec = vec![1, 3, 2];
7     vec.sort_unstable();
8     let mut vec = vec![false, false, true];
9     vec.sort_unstable();
10     let mut vec = vec!['a', 'A', 'c'];
11     vec.sort_unstable();
12     let mut vec = vec!["ab", "cd", "ab", "bc"];
13     vec.sort_unstable();
14     let mut vec = vec![(2, 1), (1, 2), (2, 5)];
15     vec.sort_unstable();
16     let mut vec = vec![[2, 1], [1, 2], [2, 5]];
17     vec.sort_unstable();
18     let mut arr = [1, 3, 2];
19     arr.sort_unstable();
20     // Negative examples: behavior changes if made unstable
21     let mut vec = vec![1, 3, 2];
22     vec.sort_by_key(|i| i / 2);
23     vec.sort_by(|&a, &b| (a + b).cmp(&b));
24     // negative examples - Not of a primitive type
25     let mut vec_of_complex = vec![String::from("hello"), String::from("world!")];
26     vec_of_complex.sort();
27     vec_of_complex.sort_by_key(String::len);
28     let mut vec = vec![(String::from("hello"), String::from("world"))];
29     vec.sort();
30     let mut vec = vec![[String::from("hello"), String::from("world")]];
31     vec.sort();
32 }