Skip to content

Commit c219daa

Browse files
committed
Auto merge of rust-lang#140406 - Urgau:autorefs-perf, r=<try>
perf: delay checking of `#[rustc_no_implicit_autorefs]` in autoref lint Try to address the regression seen in rust-lang#123239 (comment) by delaying the checking of `#[rustc_no_implicit_autorefs]` on method call.
2 parents 7d65abf + 3664fd9 commit c219daa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

compiler/rustc_lint/src/autorefs.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs {
7575
_ => return,
7676
},
7777
ExprKind::Index(base, _, _) => base,
78-
ExprKind::MethodCall(_, inner, _, _)
79-
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
80-
&& cx.tcx.has_attr(def_id, sym::rustc_no_implicit_autorefs) =>
81-
{
78+
ExprKind::MethodCall(_, inner, _, _) => {
79+
// PERF: Checking of `#[rustc_no_implicit_refs]` is defered below
80+
// as checking for attribute is a bit costly.
8281
inner
8382
}
8483
ExprKind::Field(inner, _) => inner,
@@ -99,6 +98,14 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs {
9998
peel_place_mappers(inner).kind
10099
// 1. Deref of a raw pointer.
101100
&& typeck.expr_ty(dereferenced).is_raw_ptr()
101+
// PERF: 5. b. A method call annotated with `#[rustc_no_implicit_refs]`
102+
&& match expr.kind {
103+
ExprKind::MethodCall(..) => matches!(
104+
cx.typeck_results().type_dependent_def_id(expr.hir_id),
105+
Some(def_id) if cx.tcx.has_attr(def_id, sym::rustc_no_implicit_autorefs)
106+
),
107+
_ => true,
108+
}
102109
{
103110
cx.emit_span_lint(
104111
DANGEROUS_IMPLICIT_AUTOREFS,

0 commit comments

Comments
 (0)