Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions compiler/rustc_lint/src/autorefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading