|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_sugg;
|
2 | 2 | use clippy_utils::source::{SpanRangeExt, snippet_with_applicability};
|
3 |
| -use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp}; |
4 | 3 | use rustc_errors::Applicability;
|
5 |
| -use rustc_lint::{EarlyContext, EarlyLintPass}; |
| 4 | +use rustc_hir::{Expr, ExprKind, Mutability, UnOp}; |
| 5 | +use rustc_lint::{LateContext, LateLintPass}; |
6 | 6 | use rustc_session::declare_lint_pass;
|
7 | 7 | use rustc_span::{BytePos, Span};
|
8 | 8 |
|
@@ -37,17 +37,10 @@ declare_clippy_lint! {
|
37 | 37 |
|
38 | 38 | declare_lint_pass!(DerefAddrOf => [DEREF_ADDROF]);
|
39 | 39 |
|
40 |
| -fn without_parens(mut e: &Expr) -> &Expr { |
41 |
| - while let ExprKind::Paren(ref child_e) = e.kind { |
42 |
| - e = child_e; |
43 |
| - } |
44 |
| - e |
45 |
| -} |
46 |
| - |
47 |
| -impl EarlyLintPass for DerefAddrOf { |
48 |
| - fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { |
49 |
| - if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind |
50 |
| - && let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind |
| 40 | +impl LateLintPass<'_> for DerefAddrOf { |
| 41 | + fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) { |
| 42 | + if let ExprKind::Unary(UnOp::Deref, deref_target) = e.kind |
| 43 | + && let ExprKind::AddrOf(_, mutability, addrof_target) = deref_target.kind |
51 | 44 | // NOTE(tesuji): `*&` forces rustc to const-promote the array to `.rodata` section.
|
52 | 45 | // See #12854 for details.
|
53 | 46 | && !matches!(addrof_target.kind, ExprKind::Array(_))
|
@@ -79,7 +72,7 @@ impl EarlyLintPass for DerefAddrOf {
|
79 | 72 | })
|
80 | 73 | };
|
81 | 74 |
|
82 |
| - if *mutability == Mutability::Mut { |
| 75 | + if mutability == Mutability::Mut { |
83 | 76 | generate_snippet("mut")
|
84 | 77 | } else {
|
85 | 78 | generate_snippet("&")
|
|
0 commit comments