Skip to content

Commit 4c25880

Browse files
committed
Auto merge of #8716 - binggh:stable-sort-message-update, r=giraffate
Less authoritative stable_sort_primitive message fixes #8241 Hey all - first contribution here so I'm deciding to start with something small. Updated the linked message to be less authoritative as well as moved the lint grouping from `perf` to `pedantic` as suggested by `@camsteffen` under the issue. changelog: [`stable_sort_primitive`]: emit less authoritative message and move to `pedantic`
2 parents f99ad82 + 1b6b802 commit 4c25880

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

clippy_lints/src/lib.register_all.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
280280
LintId::of(single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS),
281281
LintId::of(size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT),
282282
LintId::of(slow_vector_initialization::SLOW_VECTOR_INITIALIZATION),
283-
LintId::of(stable_sort_primitive::STABLE_SORT_PRIMITIVE),
284283
LintId::of(strings::STRING_FROM_UTF8_AS_BYTES),
285284
LintId::of(strlen_on_c_strings::STRLEN_ON_C_STRINGS),
286285
LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),

clippy_lints/src/lib.register_pedantic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
8282
LintId::of(ref_option_ref::REF_OPTION_REF),
8383
LintId::of(return_self_not_must_use::RETURN_SELF_NOT_MUST_USE),
8484
LintId::of(semicolon_if_nothing_returned::SEMICOLON_IF_NOTHING_RETURNED),
85+
LintId::of(stable_sort_primitive::STABLE_SORT_PRIMITIVE),
8586
LintId::of(strings::STRING_ADD_ASSIGN),
8687
LintId::of(trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS),
8788
LintId::of(trait_bounds::TYPE_REPETITION_IN_BOUNDS),

clippy_lints/src/lib.register_perf.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ store.register_group(true, "clippy::perf", Some("clippy_perf"), vec![
2424
LintId::of(misc::CMP_OWNED),
2525
LintId::of(redundant_clone::REDUNDANT_CLONE),
2626
LintId::of(slow_vector_initialization::SLOW_VECTOR_INITIALIZATION),
27-
LintId::of(stable_sort_primitive::STABLE_SORT_PRIMITIVE),
2827
LintId::of(types::BOX_COLLECTION),
2928
LintId::of(types::REDUNDANT_ALLOCATION),
3029
LintId::of(vec::USELESS_VEC),

clippy_lints/src/stable_sort_primitive.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
99
declare_clippy_lint! {
1010
/// ### What it does
1111
/// When sorting primitive values (integers, bools, chars, as well
12-
/// as arrays, slices, and tuples of such items), it is better to
12+
/// as arrays, slices, and tuples of such items), it is typically better to
1313
/// use an unstable sort than a stable sort.
1414
///
1515
/// ### Why is this bad?
16-
/// Using a stable sort consumes more memory and cpu cycles. Because
17-
/// values which compare equal are identical, preserving their
16+
/// Typically, using a stable sort consumes more memory and cpu cycles.
17+
/// Because values which compare equal are identical, preserving their
1818
/// relative order (the guarantee that a stable sort provides) means
1919
/// nothing, while the extra costs still apply.
2020
///
21+
/// ### Known problems
22+
///
23+
/// As pointed out in
24+
/// [issue #8241](https://github.com/rust-lang/rust-clippy/issues/8241),
25+
/// a stable sort can instead be significantly faster for certain scenarios
26+
/// (eg. when a sorted vector is extended with new data and resorted).
27+
///
28+
/// For more information and benchmarking results, please refer to the
29+
/// issue linked above.
30+
///
2131
/// ### Example
2232
/// ```rust
2333
/// let mut vec = vec![2, 1, 3];
@@ -30,7 +40,7 @@ declare_clippy_lint! {
3040
/// ```
3141
#[clippy::version = "1.47.0"]
3242
pub STABLE_SORT_PRIMITIVE,
33-
perf,
43+
pedantic,
3444
"use of sort() when sort_unstable() is equivalent"
3545
}
3646

@@ -126,7 +136,7 @@ impl LateLintPass<'_> for StableSortPrimitive {
126136
Applicability::MachineApplicable,
127137
);
128138
diag.note(
129-
"an unstable sort would perform faster without any observable difference for this data type",
139+
"an unstable sort typically performs faster without any observable difference for this data type",
130140
);
131141
},
132142
);

tests/ui/stable_sort_primitive.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,55 @@ LL | vec.sort();
55
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
66
|
77
= note: `-D clippy::stable-sort-primitive` implied by `-D warnings`
8-
= note: an unstable sort would perform faster without any observable difference for this data type
8+
= note: an unstable sort typically performs faster without any observable difference for this data type
99

1010
error: used `sort` on primitive type `bool`
1111
--> $DIR/stable_sort_primitive.rs:9:5
1212
|
1313
LL | vec.sort();
1414
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
1515
|
16-
= note: an unstable sort would perform faster without any observable difference for this data type
16+
= note: an unstable sort typically performs faster without any observable difference for this data type
1717

1818
error: used `sort` on primitive type `char`
1919
--> $DIR/stable_sort_primitive.rs:11:5
2020
|
2121
LL | vec.sort();
2222
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
2323
|
24-
= note: an unstable sort would perform faster without any observable difference for this data type
24+
= note: an unstable sort typically performs faster without any observable difference for this data type
2525

2626
error: used `sort` on primitive type `str`
2727
--> $DIR/stable_sort_primitive.rs:13:5
2828
|
2929
LL | vec.sort();
3030
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
3131
|
32-
= note: an unstable sort would perform faster without any observable difference for this data type
32+
= note: an unstable sort typically performs faster without any observable difference for this data type
3333

3434
error: used `sort` on primitive type `tuple`
3535
--> $DIR/stable_sort_primitive.rs:15:5
3636
|
3737
LL | vec.sort();
3838
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
3939
|
40-
= note: an unstable sort would perform faster without any observable difference for this data type
40+
= note: an unstable sort typically performs faster without any observable difference for this data type
4141

4242
error: used `sort` on primitive type `array`
4343
--> $DIR/stable_sort_primitive.rs:17:5
4444
|
4545
LL | vec.sort();
4646
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
4747
|
48-
= note: an unstable sort would perform faster without any observable difference for this data type
48+
= note: an unstable sort typically performs faster without any observable difference for this data type
4949

5050
error: used `sort` on primitive type `i32`
5151
--> $DIR/stable_sort_primitive.rs:19:5
5252
|
5353
LL | arr.sort();
5454
| ^^^^^^^^^^ help: try: `arr.sort_unstable()`
5555
|
56-
= note: an unstable sort would perform faster without any observable difference for this data type
56+
= note: an unstable sort typically performs faster without any observable difference for this data type
5757

5858
error: aborting due to 7 previous errors
5959

0 commit comments

Comments
 (0)