diff options
| author | lyj <sjtu5140809011@gmail.com> | 2021-06-05 20:53:24 +0800 |
|---|---|---|
| committer | lyj <sjtu5140809011@gmail.com> | 2021-06-05 21:19:05 +0800 |
| commit | a5ced1fc2bab6c23888a85b339f93dd4c6b40dac (patch) | |
| tree | 4f405cffcd7f0e2da8c97ad1ec83b739988e6885 | |
| parent | c0f3c2fe277102f22efc21ce64dc3e3423b777d4 (diff) | |
| download | rust-a5ced1fc2bab6c23888a85b339f93dd4c6b40dac.tar.gz rust-a5ced1fc2bab6c23888a85b339f93dd4c6b40dac.zip | |
rc_mutex use span_lint instead of span_lint_and_sugg
| -rw-r--r-- | clippy_lints/src/types/rc_mutex.rs | 28 | ||||
| -rw-r--r-- | tests/ui/rc_mutex.fixed | 28 | ||||
| -rw-r--r-- | tests/ui/rc_mutex.rs | 1 | ||||
| -rw-r--r-- | tests/ui/rc_mutex.stderr | 18 |
4 files changed, 15 insertions, 60 deletions
diff --git a/clippy_lints/src/types/rc_mutex.rs b/clippy_lints/src/types/rc_mutex.rs index 122df01d153..e8109f12324 100644 --- a/clippy_lints/src/types/rc_mutex.rs +++ b/clippy_lints/src/types/rc_mutex.rs @@ -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; @@ -12,28 +10,14 @@ use super::RC_MUTEX; 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 index b36b1d0914b..00000000000 --- a/tests/ui/rc_mutex.fixed +++ /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() {} diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index e6ec4549de9..922ffbf8da1 100644 --- a/tests/ui/rc_mutex.rs +++ b/tests/ui/rc_mutex.rs @@ -1,4 +1,3 @@ -// run-rustfix #![warn(clippy::rc_mutex)] #![allow(unused_imports)] #![allow(clippy::boxed_local, clippy::needless_pass_by_value)] diff --git a/tests/ui/rc_mutex.stderr b/tests/ui/rc_mutex.stderr index ad0340dcf55..efd8abacd38 100644 --- a/tests/ui/rc_mutex.stderr +++ b/tests/ui/rc_mutex.stderr @@ -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 |
