]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/types/rc_mutex.rs
Merge commit '57b3c4b90f4346b3990c1be387c3b3ca7b78412c' into clippyup
[rust.git] / clippy_lints / src / types / rc_mutex.rs
1 use clippy_utils::diagnostics::span_lint_and_help;
2 use clippy_utils::{path_def_id, qpath_generic_tys};
3 use if_chain::if_chain;
4 use rustc_hir::{self as hir, def_id::DefId, QPath};
5 use rustc_lint::LateContext;
6 use rustc_span::symbol::sym;
7
8 use super::RC_MUTEX;
9
10 pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
11     if_chain! {
12         if cx.tcx.is_diagnostic_item(sym::Rc, def_id) ;
13         if let Some(arg) = qpath_generic_tys(qpath).next();
14         if let Some(id) = path_def_id(cx, arg);
15         if cx.tcx.is_diagnostic_item(sym::Mutex, id);
16         then {
17             span_lint_and_help(
18                 cx,
19                 RC_MUTEX,
20                 hir_ty.span,
21                 "usage of `Rc<Mutex<_>>`",
22                 None,
23                 "consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead",
24             );
25             return true;
26         }
27     }
28
29     false
30 }