Skip to content

Commit bbda675

Browse files
committed
Port #[rustc_no_implicit_autorefs] to attribute parser
1 parent 68f11a1 commit bbda675

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcNeverReturnsNullPointerParser {
2727
]);
2828
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNeverReturnsNullPointer;
2929
}
30+
pub(crate) struct RustcNoImplicitAutorefsParser;
31+
32+
impl<S: Stage> NoArgsAttributeParser<S> for RustcNoImplicitAutorefsParser {
33+
const PATH: &[Symbol] = &[sym::rustc_no_implicit_autorefs];
34+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
35+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
36+
Allow(Target::Fn),
37+
Allow(Target::Method(MethodKind::Inherent)),
38+
Allow(Target::Method(MethodKind::Trait { body: false })),
39+
Allow(Target::Method(MethodKind::Trait { body: true })),
40+
Allow(Target::Method(MethodKind::TraitImpl)),
41+
]);
42+
43+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitAutorefs;
44+
}
3045

3146
pub(crate) struct RustcLayoutScalarValidRangeStartParser;
3247

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use crate::attributes::prototype::CustomMirParser;
6161
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
6262
use crate::attributes::rustc_internal::{
6363
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
64-
RustcLegacyConstGenericsParser, RustcMainParser, RustcNeverReturnsNullPointerParser,
64+
RustcLegacyConstGenericsParser, RustcMainParser, RustcNeverReturnsNullPointerParser, RustcNoImplicitAutorefsParser,
6565
RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
6666
RustcSimdMonomorphizeLaneLimitParser,
6767
};
@@ -257,6 +257,7 @@ attribute_parsers!(
257257
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
258258
Single<WithoutArgs<RustcMainParser>>,
259259
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
260+
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
260261
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
261262
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
262263
Single<WithoutArgs<SpecializationTraitParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,9 @@ pub enum AttributeKind {
881881
/// Represents `#[rustc_never_returns_null_ptr]`
882882
RustcNeverReturnsNullPointer,
883883

884+
/// Represents `#[rustc_no_implicit_autorefs]`
885+
RustcNoImplicitAutorefs,
886+
884887
/// Represents `#[rustc_object_lifetime_default]`.
885888
RustcObjectLifetimeDefault,
886889

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl AttributeKind {
9696
RustcLegacyConstGenerics { .. } => Yes,
9797
RustcMain => No,
9898
RustcNeverReturnsNullPointer => Yes,
99+
RustcNoImplicitAutorefs => Yes,
99100
RustcObjectLifetimeDefault => No,
100101
RustcPassIndirectlyInNonRusticAbis(..) => No,
101102
RustcScalableVector { .. } => Yes,

compiler/rustc_lint/src/autorefs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_ast::{BorrowKind, UnOp};
2-
use rustc_hir::{Expr, ExprKind, Mutability};
2+
use rustc_hir::attrs::AttributeKind;
3+
use rustc_hir::{Expr, ExprKind, Mutability, find_attr};
34
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, OverloadedDeref};
45
use rustc_session::{declare_lint, declare_lint_pass};
5-
use rustc_span::sym;
66

77
use crate::lints::{
88
ImplicitUnsafeAutorefsDiag, ImplicitUnsafeAutorefsMethodNote, ImplicitUnsafeAutorefsOrigin,
@@ -106,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitAutorefs {
106106
ExprKind::MethodCall(..) => cx.typeck_results().type_dependent_def_id(expr.hir_id),
107107
_ => None,
108108
}
109-
&& method_did.map(|did| cx.tcx.has_attr(did, sym::rustc_no_implicit_autorefs)).unwrap_or(true)
109+
&& method_did.map(|did| find_attr!(cx.tcx.get_all_attrs(did), AttributeKind::RustcNoImplicitAutorefs)).unwrap_or(true)
110110
{
111111
cx.emit_span_lint(
112112
DANGEROUS_IMPLICIT_AUTOREFS,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
255255
| AttributeKind::MacroUse { .. }
256256
| AttributeKind::MacroEscape( .. )
257257
| AttributeKind::NoLink
258+
| AttributeKind::RustcNoImplicitAutorefs
258259
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
259260
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
260261
| AttributeKind::RustcNeverReturnsNullPointer
@@ -305,9 +306,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
305306
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
306307
}
307308
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
308-
[sym::rustc_no_implicit_autorefs, ..] => {
309-
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
310-
}
311309
[sym::rustc_lint_query_instability, ..] => {
312310
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
313311
}

0 commit comments

Comments
 (0)