|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then;
|
2 |
| -use clippy_utils::get_trait_def_id; |
3 | 2 | use clippy_utils::higher::VecArgs;
|
4 | 3 | use clippy_utils::macros::root_macro_call_first_node;
|
5 | 4 | use clippy_utils::source::snippet_opt;
|
6 | 5 | use clippy_utils::ty::implements_trait;
|
| 6 | +use clippy_utils::{get_parent_node, get_trait_def_id, peel_blocks}; |
7 | 7 | use rustc_ast::{LitIntType, LitKind, UintTy};
|
8 | 8 | use rustc_errors::Applicability;
|
9 | 9 | use rustc_hir::{Expr, ExprKind, LangItem, Local, Node, QPath};
|
@@ -183,11 +183,17 @@ fn has_type_annotations(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
183 | 183 | peel_blocks(init).hir_id == expr.hir_id && local.ty.is_some()
|
184 | 184 | }
|
185 | 185 |
|
186 |
| -/// Returns whether `expr` is used as an argument to a function. We should not lint this. |
| 186 | +/// Returns whether `expr` is used as an argument to a function or initializing a struct/enum in any |
| 187 | +/// way. We should not lint this. |
187 | 188 | fn is_argument(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
188 |
| - let Some(parent) = get_parent_expr(cx, expr) else { |
| 189 | + let Some(parent) = get_parent_node(cx.tcx, expr.hir_id) else { |
189 | 190 | return false;
|
190 | 191 | };
|
191 | 192 |
|
192 |
| - matches!(parent.kind, ExprKind::Call(_, _) | ExprKind::MethodCall(..)) |
| 193 | + matches!( |
| 194 | + parent, |
| 195 | + Node::Expr(e) if matches!(e.kind, ExprKind::Call(_, _) | ExprKind::MethodCall(..))) |
| 196 | + // NOTE: This will ignore anything akin to `Vec<&dyn Any>` as well, which could ideally be |
| 197 | + // linted as well, but this should be fine due to the rarity of those circumstances |
| 198 | + || matches!(parent, Node::ExprField(_)) |
193 | 199 | }
|
0 commit comments