diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2023-11-26 18:11:50 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2023-11-26 18:40:50 +0100 |
| commit | 23d533264fd5a4b80cffcefa73a6ddb207c9f6e2 (patch) | |
| tree | 53aa4a5be471359573a4b4c97a4664fc6e101db2 /clippy_lints | |
| parent | 7af811b6c43a90ed61a97ce239f5020263e39c7e (diff) | |
Fix `box_default` behaviour with empty `vec![]` coming from macro arg
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/box_default.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/clippy_lints/src/box_default.rs b/clippy_lints/src/box_default.rs index b69dc5c1291..ef12fe344e4 100644 --- a/clippy_lints/src/box_default.rs +++ b/clippy_lints/src/box_default.rs @@ -45,7 +45,7 @@ impl LateLintPass<'_> for BoxDefault { && let ExprKind::Path(QPath::TypeRelative(ty, seg)) = box_new.kind && let ExprKind::Call(arg_path, ..) = arg.kind && !in_external_macro(cx.sess(), expr.span) - && (expr.span.eq_ctxt(arg.span) || is_vec_expn(cx, arg)) + && (expr.span.eq_ctxt(arg.span) || is_local_vec_expn(cx, arg, expr)) && seg.ident.name == sym::new && path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box()) && is_default_equivalent(cx, arg) @@ -81,10 +81,10 @@ fn is_plain_default(cx: &LateContext<'_>, arg_path: &Expr<'_>) -> bool { } } -fn is_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - macro_backtrace(expr.span) - .next() - .map_or(false, |call| cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id)) +fn is_local_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>, ref_expr: &Expr<'_>) -> bool { + macro_backtrace(expr.span).next().map_or(false, |call| { + cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id) && call.span.eq_ctxt(ref_expr.span) + }) } #[derive(Default)] |
