Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcf4e29

Browse files
committedMar 11, 2025
Convert deref_addrof lint to late lint
This is necessary in order to use type analysis in later commits.
1 parent df74bd4 commit fcf4e29

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed
 

‎clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
760760
store.register_late_pass(move |_| Box::new(trait_bounds::TraitBounds::new(conf)));
761761
store.register_late_pass(|_| Box::new(comparison_chain::ComparisonChain));
762762
store.register_late_pass(move |tcx| Box::new(mut_key::MutableKeyType::new(tcx, conf)));
763-
store.register_early_pass(|| Box::new(reference::DerefAddrOf));
763+
store.register_late_pass(|_| Box::new(reference::DerefAddrOf));
764764
store.register_early_pass(|| Box::new(double_parens::DoubleParens));
765765
let format_args = format_args_storage.clone();
766766
store.register_late_pass(move |_| Box::new(format_impl::FormatImpl::new(format_args.clone())));

‎clippy_lints/src/reference.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::{SpanRangeExt, snippet_with_applicability};
3-
use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp};
43
use rustc_errors::Applicability;
5-
use rustc_lint::{EarlyContext, EarlyLintPass};
4+
use rustc_hir::{Expr, ExprKind, Mutability, UnOp};
5+
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
77
use rustc_span::{BytePos, Span};
88

@@ -37,17 +37,10 @@ declare_clippy_lint! {
3737

3838
declare_lint_pass!(DerefAddrOf => [DEREF_ADDROF]);
3939

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
5144
// NOTE(tesuji): `*&` forces rustc to const-promote the array to `.rodata` section.
5245
// See #12854 for details.
5346
&& !matches!(addrof_target.kind, ExprKind::Array(_))
@@ -79,7 +72,7 @@ impl EarlyLintPass for DerefAddrOf {
7972
})
8073
};
8174

82-
if *mutability == Mutability::Mut {
75+
if mutability == Mutability::Mut {
8376
generate_snippet("mut")
8477
} else {
8578
generate_snippet("&")

0 commit comments

Comments
 (0)
Please sign in to comment.