about summary refs log tree commit diff
path: root/clippy_lints/src
diff options
context:
space:
mode:
authorllogiq <bogusandre@gmail.com>2024-12-16 15:48:56 +0000
committerGitHub <noreply@github.com>2024-12-16 15:48:56 +0000
commit063c5c17433ff058d7c899d2933f2c7d1162b3da (patch)
tree12317c4884bed6dd5ab6e2cf88a30197b604bad8 /clippy_lints/src
parent968669b00a224d6e97439d317e7443b8493e2f1c (diff)
parent1a23b5b51765a9f47e9afafbd9b611c5d11b5dfd (diff)
downloadrust-063c5c17433ff058d7c899d2933f2c7d1162b3da.tar.gz
rust-063c5c17433ff058d7c899d2933f2c7d1162b3da.zip
correct suggestion for `unnecessary_sort_by` in `no_std` (#13836)
fix #11524

In a `no_std` environment, we can use `core::cmp::Reverse` instead of
`std::cmp::Reverse`.

----

changelog: [`unnecessary_sort_by`]: correct suggestion in `no_std`
Diffstat (limited to 'clippy_lints/src')
-rw-r--r--clippy_lints/src/methods/unnecessary_sort_by.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/clippy_lints/src/methods/unnecessary_sort_by.rs b/clippy_lints/src/methods/unnecessary_sort_by.rs
index 8ba10938ce6..2732a89e07b 100644
--- a/clippy_lints/src/methods/unnecessary_sort_by.rs
+++ b/clippy_lints/src/methods/unnecessary_sort_by.rs
@@ -1,7 +1,7 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::is_trait_method;
 use clippy_utils::sugg::Sugg;
 use clippy_utils::ty::implements_trait;
+use clippy_utils::{is_trait_method, std_or_core};
 use rustc_errors::Applicability;
 use rustc_hir::{Closure, Expr, ExprKind, Mutability, Param, Pat, PatKind, Path, PathSegment, QPath};
 use rustc_lint::LateContext;
@@ -212,8 +212,10 @@ pub(super) fn check<'tcx>(
                 trigger.vec_name,
                 if is_unstable { "_unstable" } else { "" },
                 trigger.closure_arg,
-                if trigger.reverse {
-                    format!("std::cmp::Reverse({})", trigger.closure_body)
+                if let Some(std_or_core) = std_or_core(cx)
+                    && trigger.reverse
+                {
+                    format!("{}::cmp::Reverse({})", std_or_core, trigger.closure_body)
                 } else {
                     trigger.closure_body.to_string()
                 },