Auto deref does not apply on union field

This commit is contained in:
Samuel Tardieu 2023-09-10 18:15:18 +02:00
parent 8c48b936cc
commit c548d11041
3 changed files with 51 additions and 0 deletions

View file

@ -1399,6 +1399,13 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
return;
}
if let ExprKind::Field(parent_expr, _) = expr.kind
&& let ty::Adt(adt, _) = cx.typeck_results().expr_ty(parent_expr).kind()
&& adt.is_union()
{
// Auto deref does not apply on union field
return;
}
span_lint_hir_and_then(
cx,
EXPLICIT_AUTO_DEREF,