diff options
| author | bors <bors@rust-lang.org> | 2025-05-02 17:35:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-05-02 17:35:50 +0000 |
| commit | 4824c2bb7445cb2478aab0190c268c939d77a0f6 (patch) | |
| tree | d9e98102e95f9361e6764d03bf2fbd692c48fb11 /compiler | |
| parent | 7c96085b64580af5c5f619384f0e3f082138ff13 (diff) | |
| parent | c519510c29eb6a46e2bebe4cb240f80785495583 (diff) | |
| download | rust-4824c2bb7445cb2478aab0190c268c939d77a0f6.tar.gz rust-4824c2bb7445cb2478aab0190c268c939d77a0f6.zip | |
Auto merge of #140406 - Urgau:autorefs-perf, r=nnethercote
perf: delay checking of `#[rustc_no_implicit_autorefs]` in autoref lint Try to address the regression seen in https://github.com/rust-lang/rust/pull/123239#issuecomment-2835418470 by delaying the checking of `#[rustc_no_implicit_autorefs]` on method call.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/src/autorefs.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/rustc_lint/src/autorefs.rs b/compiler/rustc_lint/src/autorefs.rs index 5dd26854c95..ddab13190be 100644 --- a/compiler/rustc_lint/src/autorefs.rs +++ b/compiler/rustc_lint/src/autorefs.rs @@ -75,10 +75,9 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs { _ => return, }, ExprKind::Index(base, _, _) => base, - ExprKind::MethodCall(_, inner, _, _) - if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) - && cx.tcx.has_attr(def_id, sym::rustc_no_implicit_autorefs) => - { + ExprKind::MethodCall(_, inner, _, _) => { + // PERF: Checking of `#[rustc_no_implicit_refs]` is deferred below + // because checking for attribute is a bit costly. inner } ExprKind::Field(inner, _) => inner, @@ -99,6 +98,14 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs { peel_place_mappers(inner).kind // 1. Deref of a raw pointer. && typeck.expr_ty(dereferenced).is_raw_ptr() + // PERF: 5. b. A method call annotated with `#[rustc_no_implicit_refs]` + && match expr.kind { + ExprKind::MethodCall(..) => matches!( + cx.typeck_results().type_dependent_def_id(expr.hir_id), + Some(def_id) if cx.tcx.has_attr(def_id, sym::rustc_no_implicit_autorefs) + ), + _ => true, + } { cx.emit_span_lint( DANGEROUS_IMPLICIT_AUTOREFS, |
