diff --git a/clippy_lints/src/types/rc_mutex.rs b/clippy_lints/src/types/rc_mutex.rs index 122df01d1532..e8109f123245 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>`. Consider using `Rc>`", - "try", - format!( - "Rc>", - snippet_with_applicability(cx, inner_span, "..", &mut applicability) - ), - applicability, + "found `Rc>`. Consider using `Rc>` instead", ); return true; } diff --git a/tests/ui/rc_mutex.fixed b/tests/ui/rc_mutex.fixed deleted file mode 100644 index b36b1d0914bd..000000000000 --- 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 { - foo: T, -} - -pub enum MyEnum { - One, - Two, -} - -pub fn test1(foo: Rc>) {} - -pub fn test2(foo: Rc>) {} - -pub fn test3(foo: Rc>>) {} - -fn main() {} diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index e6ec4549de9f..922ffbf8da14 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 ad0340dcf556..efd8abacd38f 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>`. Consider using `Rc>` - --> $DIR/rc_mutex.rs:22:22 +error: Found `Rc>`. Consider using `Rc>` instead + --> $DIR/rc_mutex.rs:21:22 | LL | pub fn test1(foo: Rc>) {} - | ^^^^^^^^^^^^ help: try: `Rc>` + | ^^^^^^^^^^^^ | = note: `-D clippy::rc-mutex` implied by `-D warnings` -error: you seem to be trying to use `Rc>`. Consider using `Rc>` - --> $DIR/rc_mutex.rs:24:19 +error: Found `Rc>`. Consider using `Rc>` instead + --> $DIR/rc_mutex.rs:23:19 | LL | pub fn test2(foo: Rc>) {} - | ^^^^^^^^^^^^^^^^^ help: try: `Rc>` + | ^^^^^^^^^^^^^^^^^ -error: you seem to be trying to use `Rc>`. Consider using `Rc>` - --> $DIR/rc_mutex.rs:26:19 +error: Found `Rc>`. Consider using `Rc>` instead + --> $DIR/rc_mutex.rs:25:19 | LL | pub fn test3(foo: Rc>>) {} - | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc>>` + | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors