]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/types/rc_mutex.rs
Auto merge of #87954 - flip1995:clippyup, r=Manishearth
[rust.git] / clippy_lints / src / types / rc_mutex.rs
1 use clippy_utils::diagnostics::span_lint;
2 use clippy_utils::is_ty_param_diagnostic_item;
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(_) = is_ty_param_diagnostic_item(cx, qpath, sym!(mutex_type)) ;
14
15         then{
16             span_lint(
17                 cx,
18                 RC_MUTEX,
19                 hir_ty.span,
20                 "found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead",
21             );
22             return true;
23         }
24     }
25
26     false
27 }