Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4824c2b

Browse files
committed
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 #123239 (comment) by delaying the checking of `#[rustc_no_implicit_autorefs]` on method call.
2 parents 7c96085 + c519510 commit 4824c2b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

‎compiler/rustc_lint/src/autorefs.rs

Lines changed: 11 additions & 4 deletions
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 deferred below
80+
// because 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)

AltStyle によって変換されたページ (->オリジナル) /