Skip to content

Commit a5ced1f

Browse files
committed
rc_mutex use span_lint instead of span_lint_and_sugg
1 parent c0f3c2f commit a5ced1f

File tree

4 files changed

+15
-60
lines changed

4 files changed

+15
-60
lines changed

clippy_lints/src/types/rc_mutex.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::source::snippet_with_applicability;
3-
use clippy_utils::{get_qpath_generic_tys, is_ty_param_diagnostic_item};
1+
use clippy_utils::diagnostics::span_lint;
2+
use clippy_utils::is_ty_param_diagnostic_item;
43
use if_chain::if_chain;
5-
use rustc_errors::Applicability;
6-
use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind};
4+
use rustc_hir::{self as hir, def_id::DefId, QPath};
75
use rustc_lint::LateContext;
86
use rustc_span::symbol::sym;
97

@@ -12,28 +10,14 @@ use super::RC_MUTEX;
1210
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
1311
if_chain! {
1412
if cx.tcx.is_diagnostic_item(sym::Rc, def_id) ;
15-
if let Some(ty) = is_ty_param_diagnostic_item(cx, qpath, sym!(mutex_type)) ;
16-
if let TyKind::Path(ref qpath_inner)=ty.kind;
13+
if let Some(_) = is_ty_param_diagnostic_item(cx, qpath, sym!(mutex_type)) ;
1714

1815
then{
19-
let mut applicability = Applicability::MachineApplicable;
20-
21-
let inner_span = match get_qpath_generic_tys(qpath_inner).next() {
22-
Some(ty) => ty.span,
23-
None => return false,
24-
};
25-
26-
span_lint_and_sugg(
16+
span_lint(
2717
cx,
2818
RC_MUTEX,
2919
hir_ty.span,
30-
"you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`",
31-
"try",
32-
format!(
33-
"Rc<RefCell<{}>>",
34-
snippet_with_applicability(cx, inner_span, "..", &mut applicability)
35-
),
36-
applicability,
20+
"found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead",
3721
);
3822
return true;
3923
}

tests/ui/rc_mutex.fixed

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/ui/rc_mutex.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-rustfix
21
#![warn(clippy::rc_mutex)]
32
#![allow(unused_imports)]
43
#![allow(clippy::boxed_local, clippy::needless_pass_by_value)]

tests/ui/rc_mutex.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
error: you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`
2-
--> $DIR/rc_mutex.rs:22:22
1+
error: Found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
2+
--> $DIR/rc_mutex.rs:21:22
33
|
44
LL | pub fn test1<T>(foo: Rc<Mutex<T>>) {}
5-
| ^^^^^^^^^^^^ help: try: `Rc<RefCell<T>>`
5+
| ^^^^^^^^^^^^
66
|
77
= note: `-D clippy::rc-mutex` implied by `-D warnings`
88

9-
error: you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`
10-
--> $DIR/rc_mutex.rs:24:19
9+
error: Found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
10+
--> $DIR/rc_mutex.rs:23:19
1111
|
1212
LL | pub fn test2(foo: Rc<Mutex<MyEnum>>) {}
13-
| ^^^^^^^^^^^^^^^^^ help: try: `Rc<RefCell<MyEnum>>`
13+
| ^^^^^^^^^^^^^^^^^
1414

15-
error: you seem to be trying to use `Rc<Mutex<T>>`. Consider using `Rc<RefCell<T>>`
16-
--> $DIR/rc_mutex.rs:26:19
15+
error: Found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` instead
16+
--> $DIR/rc_mutex.rs:25:19
1717
|
1818
LL | pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {}
19-
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `Rc<RefCell<SubT<usize>>>`
19+
| ^^^^^^^^^^^^^^^^^^^^^^
2020

2121
error: aborting due to 3 previous errors
2222

0 commit comments

Comments
 (0)