Skip to content

Commit a0c7262

Browse files
committed
Port #[rustc_no_implicit_autorefs] to attribute parser
1 parent 58b270b commit a0c7262

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcMainParser {
1313
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcMain;
1414
}
1515

16+
pub(crate) struct RustcNoImplicitAutorefsParser;
17+
18+
impl<S: Stage> NoArgsAttributeParser<S> for RustcNoImplicitAutorefsParser {
19+
const PATH: &[Symbol] = &[sym::rustc_no_implicit_autorefs];
20+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
21+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
22+
Allow(Target::Fn),
23+
Allow(Target::Method(MethodKind::Inherent)),
24+
Allow(Target::Method(MethodKind::Trait { body: false })),
25+
Allow(Target::Method(MethodKind::Trait { body: true })),
26+
Allow(Target::Method(MethodKind::TraitImpl)),
27+
]);
28+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitAutorefs;
29+
}
1630
pub(crate) struct RustcLayoutScalarValidRangeStartParser;
1731

1832
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStartParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ 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, RustcObjectLifetimeDefaultParser,
65-
RustcScalableVectorParser, RustcSimdMonomorphizeLaneLimitParser,
64+
RustcLegacyConstGenericsParser, RustcMainParser, RustcNoImplicitAutorefsParser,
65+
RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
66+
RustcSimdMonomorphizeLaneLimitParser,
6667
};
6768
use crate::attributes::semantics::MayDangleParser;
6869
use crate::attributes::stability::{
@@ -255,6 +256,7 @@ attribute_parsers!(
255256
Single<WithoutArgs<PubTransparentParser>>,
256257
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
257258
Single<WithoutArgs<RustcMainParser>>,
259+
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
258260
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
259261
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
260262
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
@@ -878,6 +878,9 @@ pub enum AttributeKind {
878878
/// Represents `#[rustc_main]`.
879879
RustcMain,
880880

881+
/// Represents `#[rustc_no_implicit_autorefs]`
882+
RustcNoImplicitAutorefs,
883+
881884
/// Represents `#[rustc_object_lifetime_default]`.
882885
RustcObjectLifetimeDefault,
883886

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl AttributeKind {
9595
RustcLayoutScalarValidRangeStart(..) => Yes,
9696
RustcLegacyConstGenerics { .. } => Yes,
9797
RustcMain => No,
98+
RustcNoImplicitAutorefs => Yes,
9899
RustcObjectLifetimeDefault => No,
99100
RustcPassIndirectlyInNonRusticAbis(..) => No,
100101
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::RustcScalableVector { .. }
@@ -304,9 +305,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
304305
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
305306
}
306307
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
307-
[sym::rustc_no_implicit_autorefs, ..] => {
308-
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
309-
}
310308
[sym::rustc_never_returns_null_ptr, ..] => {
311309
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
312310
}

0 commit comments

Comments
 (0)