about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHirochika Matsumoto <matsujika@gmail.com>2020-10-18 19:24:11 +0900
committerHirochika Matsumoto <matsujika@gmail.com>2020-11-18 01:28:37 +0900
commit532d205218c7aa28c1718f9e9088eeced6e2c5ac (patch)
treef48e71d1a528c89ae50f4f4d8cee63a38b8d3c78
parent9d96311d7354d99b6f3b3956405b7defac81461c (diff)
downloadrust-532d205218c7aa28c1718f9e9088eeced6e2c5ac.tar.gz
rust-532d205218c7aa28c1718f9e9088eeced6e2c5ac.zip
Skip functions in PartialOrd
-rw-r--r--clippy_lints/src/unnecessary_wrap.rs12
-rw-r--r--clippy_lints/src/utils/paths.rs1
2 files changed, 11 insertions, 2 deletions
diff --git a/clippy_lints/src/unnecessary_wrap.rs b/clippy_lints/src/unnecessary_wrap.rs
index 7a9cf627059..ec6c823a4ec 100644
--- a/clippy_lints/src/unnecessary_wrap.rs
+++ b/clippy_lints/src/unnecessary_wrap.rs
@@ -1,6 +1,6 @@
 use crate::utils::{
-    in_macro, is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then,
-    visitors::find_all_ret_expressions,
+    in_macro, is_type_diagnostic_item, match_path, match_qpath, paths, return_ty, snippet, span_lint_and_then,
+    trait_ref_of_method, visitors::find_all_ret_expressions,
 };
 use if_chain::if_chain;
 use rustc_errors::Applicability;
@@ -63,6 +63,14 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
         span: Span,
         hir_id: HirId,
     ) {
+        if_chain! {
+            if let Some(trait_ref) = trait_ref_of_method(cx, hir_id);
+            if match_path(trait_ref.path, &paths::PARTIAL_ORD);
+            then {
+                return;
+            }
+        }
+
         match fn_kind {
             FnKind::ItemFn(.., visibility, _) | FnKind::Method(.., Some(visibility), _) => {
                 if visibility.node.is_pub() {
diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs
index 2be5ff93f86..97e01f445ff 100644
--- a/clippy_lints/src/utils/paths.rs
+++ b/clippy_lints/src/utils/paths.rs
@@ -81,6 +81,7 @@ pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to
 pub const PARKING_LOT_MUTEX_GUARD: [&str; 2] = ["parking_lot", "MutexGuard"];
 pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 2] = ["parking_lot", "RwLockReadGuard"];
 pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWriteGuard"];
+pub const PARTIAL_ORD: [&str; 3] = ["std", "cmp", "PartialOrd"];
 pub const PATH: [&str; 3] = ["std", "path", "Path"];
 pub const PATH_BUF: [&str; 3] = ["std", "path", "PathBuf"];
 pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"];