]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/stable_sort_primitive.rs
Merge remote-tracking branch 'upstream/master' into rustup
[rust.git] / clippy_lints / src / stable_sort_primitive.rs
index 99e4b293ac6809b40e74b2a33b62db8fa41e72ca..276a9338819d9303c544411021dd419f2d4daa19 100644 (file)
@@ -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",
+                    );
+                },
             );
         }
     }