diff options
| author | bors <bors@rust-lang.org> | 2021-01-21 14:12:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-21 14:12:43 +0000 |
| commit | 16d13a5a4b77ea543850a216a0ad8453ebade3cd (patch) | |
| tree | 4ce7b181513f780ffed254734978beeaa60aa266 | |
| parent | d990c31990e72dfdff361c384da7550968e2822a (diff) | |
| parent | e42208f1b7befe316e32c66b6dc6d242a56f4d84 (diff) | |
| download | rust-16d13a5a4b77ea543850a216a0ad8453ebade3cd.tar.gz rust-16d13a5a4b77ea543850a216a0ad8453ebade3cd.zip | |
Auto merge of #6611 - pastchick3:master, r=flip1995
Fix the reversed suggestion message of `stable_sort_primitive`. Now Clippy emits `stable_sort_primitive` warning as follows: ``` warning: used sort instead of sort_unstable to sort primitive type `usize` --> src\asm.rs:41:13 | 41 | self.successors.sort(); | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `self.successors.sort_unstable()` | = note: `#[warn(clippy::stable_sort_primitive)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive ``` I think the position of `sort` and `sort_unstable` in the first line should be reversed. changelog: Fix the reversed suggestion message of `stable_sort_primitive`.
| -rw-r--r-- | clippy_lints/src/stable_sort_primitive.rs | 31 | ||||
| -rw-r--r-- | tests/ui/stable_sort_primitive.stderr | 27 |
2 files changed, 39 insertions, 19 deletions
diff --git a/clippy_lints/src/stable_sort_primitive.rs b/clippy_lints/src/stable_sort_primitive.rs index 99e4b293ac6..276a9338819 100644 --- a/clippy_lints/src/stable_sort_primitive.rs +++ b/clippy_lints/src/stable_sort_primitive.rs @@ -1,4 +1,4 @@ -use crate::utils::{is_slice_of_primitives, span_lint_and_sugg, sugg::Sugg}; +use crate::utils::{is_slice_of_primitives, span_lint_and_then, sugg::Sugg}; use if_chain::if_chain; @@ -107,25 +107,32 @@ fn detect_stable_sort_primitive(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option impl LateLintPass<'_> for StableSortPrimitive { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if let Some(detection) = detect_stable_sort_primitive(cx, expr) { - span_lint_and_sugg( + span_lint_and_then( cx, STABLE_SORT_PRIMITIVE, expr.span, format!( - "used {} instead of {} to sort primitive type `{}`", + "used `{}` on primitive type `{}`", detection.method.stable_name(), - detection.method.unstable_name(), detection.slice_type, ) .as_str(), - "try", - format!( - "{}.{}({})", - detection.slice_name, - detection.method.unstable_name(), - detection.method_args - ), - Applicability::MachineApplicable, + |diag| { + diag.span_suggestion( + expr.span, + "try", + format!( + "{}.{}({})", + detection.slice_name, + detection.method.unstable_name(), + detection.method_args, + ), + Applicability::MachineApplicable, + ); + diag.note( + "an unstable sort would perform faster without any observable difference for this data type", + ); + }, ); } } diff --git a/tests/ui/stable_sort_primitive.stderr b/tests/ui/stable_sort_primitive.stderr index 780389f32bc..b8d22ed2504 100644 --- a/tests/ui/stable_sort_primitive.stderr +++ b/tests/ui/stable_sort_primitive.stderr @@ -1,46 +1,59 @@ -error: used sort instead of sort_unstable to sort primitive type `i32` +error: used `sort` on primitive type `i32` --> $DIR/stable_sort_primitive.rs:7:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` | = note: `-D clippy::stable-sort-primitive` implied by `-D warnings` + = note: an unstable sort would perform faster without any observable difference for this data type -error: used sort instead of sort_unstable to sort primitive type `bool` +error: used `sort` on primitive type `bool` --> $DIR/stable_sort_primitive.rs:9:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` + | + = note: an unstable sort would perform faster without any observable difference for this data type -error: used sort instead of sort_unstable to sort primitive type `char` +error: used `sort` on primitive type `char` --> $DIR/stable_sort_primitive.rs:11:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` + | + = note: an unstable sort would perform faster without any observable difference for this data type -error: used sort instead of sort_unstable to sort primitive type `str` +error: used `sort` on primitive type `str` --> $DIR/stable_sort_primitive.rs:13:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` + | + = note: an unstable sort would perform faster without any observable difference for this data type -error: used sort instead of sort_unstable to sort primitive type `tuple` +error: used `sort` on primitive type `tuple` --> $DIR/stable_sort_primitive.rs:15:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` + | + = note: an unstable sort would perform faster without any observable difference for this data type -error: used sort instead of sort_unstable to sort primitive type `array` +error: used `sort` on primitive type `array` --> $DIR/stable_sort_primitive.rs:17:5 | LL | vec.sort(); | ^^^^^^^^^^ help: try: `vec.sort_unstable()` + | + = note: an unstable sort would perform faster without any observable difference for this data type -error: used sort instead of sort_unstable to sort primitive type `i32` +error: used `sort` on primitive type `i32` --> $DIR/stable_sort_primitive.rs:19:5 | LL | arr.sort(); | ^^^^^^^^^^ help: try: `arr.sort_unstable()` + | + = note: an unstable sort would perform faster without any observable difference for this data type error: aborting due to 7 previous errors |
