Skip to content

Commit dd9e8c8

Browse files
committed
Refactor arc_with_non_send_sync
* Check HIR beffore type checking * Only lint when `Arc::new` is called
1 parent 885f97e commit dd9e8c8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

clippy_lints/src/arc_with_non_send_sync.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2+
use clippy_utils::is_from_proc_macro;
23
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
3-
use clippy_utils::{is_from_proc_macro, last_path_segment};
4-
use rustc_hir::{Expr, ExprKind};
4+
use rustc_hir::{Expr, ExprKind, QPath};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::ty;
77
use rustc_middle::ty::print::with_forced_trimmed_paths;
@@ -42,12 +42,11 @@ declare_lint_pass!(ArcWithNonSendSync => [ARC_WITH_NON_SEND_SYNC]);
4242

4343
impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync {
4444
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
45-
if !expr.span.from_expansion()
46-
&& let ty = cx.typeck_results().expr_ty(expr)
47-
&& is_type_diagnostic_item(cx, ty, sym::Arc)
48-
&& let ExprKind::Call(func, [arg]) = expr.kind
49-
&& let ExprKind::Path(func_path) = func.kind
50-
&& last_path_segment(&func_path).ident.name == sym::new
45+
if let ExprKind::Call(func, [arg]) = expr.kind
46+
&& let ExprKind::Path(QPath::TypeRelative(func_ty, func_name)) = func.kind
47+
&& func_name.ident.name == sym::new
48+
&& !expr.span.from_expansion()
49+
&& is_type_diagnostic_item(cx, cx.typeck_results().node_type(func_ty.hir_id), sym::Arc)
5150
&& let arg_ty = cx.typeck_results().expr_ty(arg)
5251
// make sure that the type is not and does not contain any type parameters
5352
&& arg_ty.walk().all(|arg| {

0 commit comments

Comments
 (0)