]> git.lizzy.rs Git - rust.git/commitdiff
rc_mutex use span_lint instead of span_lint_and_sugg
authorlyj <sjtu5140809011@gmail.com>
Sat, 5 Jun 2021 12:53:24 +0000 (20:53 +0800)
committerlyj <sjtu5140809011@gmail.com>
Sat, 5 Jun 2021 13:19:05 +0000 (21:19 +0800)
clippy_lints/src/types/rc_mutex.rs
tests/ui/rc_mutex.fixed [deleted file]
tests/ui/rc_mutex.rs
tests/ui/rc_mutex.stderr

index 122df01d15321c9b0c622398143720fea6e2bdb4..e8109f123245ca2c00917d6fb400a893b7c2ab30 100644 (file)
@@ -1,9 +1,7 @@
-use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item};
+use clippy_utils::diagnostics::span_lint;
+use clippy_utils::is_ty_param_diagnostic_item;
 use if_chain::if_chain;
-use rustc_errors::Applicability;
-use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind};
+use rustc_hir::{self as hir, def_id::DefId, QPath};
 use rustc_lint::LateContext;
 use rustc_span::symbol::sym;
 
 pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
     if_chain! {
         if cx.tcx.is_diagnostic_item(sym::Rc, def_id) ;
-        if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym!(mutex_type)) ;
-        if let TyKind::Path(ref qpath_inner)=ty.kind;
+        if let Some(_) = is_ty_param_diagnostic_item(cx, qpath, sym!(mutex_type)) ;
 
         then{
-            let mut applicability = Applicability::MachineApplicable;
-
-            let inner_span = match get_qpath_generic_tys(qpath_inner).next() {
-                Some(ty) => ty.span,
-                None => return false,
-            };
-
-            span_lint_and_sugg(
+            span_lint(
                 cx,
                 RC_MUTEX,
                 hir_ty.span,
-                "you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`",
-                "try",
-                format!(
-                    "Rc<RefCell<{}>>",
-                    snippet_with_applicability(cx, inner_span, "..", &mut applicability)
-                ),
-                applicability,
+                "found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead",
             );
             return true;
         }
diff --git a/tests/ui/rc_mutex.fixed b/tests/ui/rc_mutex.fixed
deleted file mode 100644 (file)
index b36b1d0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// run-rustfix
-#![warn(clippy::rc_mutex)]
-#![allow(unused_imports)]
-#![allow(clippy::boxed_local, clippy::needless_pass_by_value)]
-#![allow(clippy::blacklisted_name, unused_variables, dead_code)]
-
-use std::cell::RefCell;
-use std::rc::Rc;
-use std::sync::Mutex;
-
-pub struct MyStruct {}
-
-pub struct SubT<T> {
-    foo: T,
-}
-
-pub enum MyEnum {
-    One,
-    Two,
-}
-
-pub fn test1<T>(foo: Rc<RefCell<T>>) {}
-
-pub fn test2(foo: Rc<RefCell<MyEnum>>) {}
-
-pub fn test3(foo: Rc<RefCell<SubT<usize>>>) {}
-
-fn main() {}
index e6ec4549de9fab021c92fb98be7c9317a38638e4..922ffbf8da1454b127a8f3b38fc1ee67e460f74c 100644 (file)
@@ -1,4 +1,3 @@
-// run-rustfix
 #![warn(clippy::rc_mutex)]
 #![allow(unused_imports)]
 #![allow(clippy::boxed_local, clippy::needless_pass_by_value)]
index ad0340dcf55627cb78c3a999d72613119c37791f..efd8abacd38f9d90645333db0b863dfe3937b101 100644 (file)
@@ -1,22 +1,22 @@
-error: you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`
-  --> $DIR/rc_mutex.rs:22:22
+error: Found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
+  --> $DIR/rc_mutex.rs:21:22
    |
 LL | pub fn test1<T>(foo: Rc<Mutex<T>>) {}
-   |                      ^^^^^^^^^^^^ help: try: `Rc<RefCell<T>>`
+   |                      ^^^^^^^^^^^^
    |
    = note: `-D clippy::rc-mutex` implied by `-D warnings`
 
-error: you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`
-  --> $DIR/rc_mutex.rs:24:19
+error: Found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
+  --> $DIR/rc_mutex.rs:23:19
    |
 LL | pub fn test2(foo: Rc<Mutex<MyEnum>>) {}
-   |                   ^^^^^^^^^^^^^^^^^ help: try: `Rc<RefCell<MyEnum>>`
+   |                   ^^^^^^^^^^^^^^^^^
 
-error: you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`
-  --> $DIR/rc_mutex.rs:26:19
+error: Found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
+  --> $DIR/rc_mutex.rs:25:19
    |
 LL | pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {}
-   |                   ^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc<RefCell<SubT<usize>>>`
+   |                   ^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 3 previous errors