@@ -26,21 +26,18 @@ declare_clippy_lint! {
2626 /// let v = vec![data; 100];
2727 /// ```
2828 #[ clippy:: version = "1.62.0" ]
29- pub ARC_NEW_IN_VEC_FROM_SLICE ,
29+ pub ARC_NEW_IN_VEC_FROM_ELEM ,
3030 suspicious,
3131 "calling `Arc::new` in `vec![elem; len]`"
3232}
33- declare_lint_pass ! ( ArcNewInVecFromSlice => [ ARC_NEW_IN_VEC_FROM_SLICE ] ) ;
33+ declare_lint_pass ! ( ArcNewInVecFromSlice => [ ARC_NEW_IN_VEC_FROM_ELEM ] ) ;
3434
3535impl LateLintPass < ' _ > for ArcNewInVecFromSlice {
3636 fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
3737 let Some ( macro_call) = root_macro_call_first_node ( cx, expr) else { return ; } ;
38- if !macro_is_vec ( cx, & macro_call) {
39- return ;
40- }
4138
4239 if let Some ( VecArgs :: Repeat ( elem, _) ) = VecArgs :: hir ( cx, expr) {
43- if !is_arc_new ( elem) {
40+ if !is_arc_new ( cx , elem) {
4441 return ;
4542 }
4643
@@ -52,25 +49,22 @@ impl LateLintPass<'_> for ArcNewInVecFromSlice {
5249fn yield_lint ( cx : & LateContext < ' _ > , macro_call : & MacroCall ) {
5350 span_lint_and_help (
5451 cx,
55- ARC_NEW_IN_VEC_FROM_SLICE ,
52+ ARC_NEW_IN_VEC_FROM_ELEM ,
5653 macro_call. span ,
5754 "calling `Arc::new` in `vec![elem; len]`" ,
5855 None ,
5956 "consider extracting `Arc` initialization to a variable" ,
6057 ) ;
6158}
6259
63- fn macro_is_vec ( cx : & LateContext < ' _ > , macro_call : & MacroCall ) -> bool {
64- cx. tcx . is_diagnostic_item ( sym:: vec_macro, macro_call. def_id )
65- }
66-
6760/// Checks whether the given `expr` is a call to `Arc::new`
68- fn is_arc_new ( expr : & Expr < ' _ > ) -> bool {
61+ fn is_arc_new ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
6962 if_chain ! {
7063 if let ExprKind :: Call ( func, _args) = expr. kind;
71- if let ExprKind :: Path ( ref func_path) = func. kind;
72- if let ExprKind :: Path ( QPath :: TypeRelative ( ty, _) ) = func. kind;
64+ if let ExprKind :: Path ( ref func_path @ QPath :: TypeRelative ( ty, _) ) = func. kind;
7365 if let TyKind :: Path ( ref ty_path) = ty. kind;
66+ if let Some ( def_id) = cx. qpath_res( ty_path, ty. hir_id) . opt_def_id( ) ;
67+ if cx. tcx. is_diagnostic_item( sym:: Arc , def_id) ;
7468
7569 then {
7670 let ty_segment = last_path_segment( ty_path) ;
0 commit comments