Skip to content

Commit 83bfc83

Browse files
committed
Add #[rustc_must_not_call_on_interior_mutable_consts] attribute
1 parent bc1d727 commit 83bfc83

File tree

7 files changed

+26
-1
lines changed

7 files changed

+26
-1
lines changed

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ impl<S: Stage> NoArgsAttributeParser<S> for PassByValueParser {
3838
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PassByValue;
3939
}
4040

41+
pub(crate) struct RustcMustNotCallOnInteriorMutableConsts;
42+
impl<S: Stage> NoArgsAttributeParser<S> for RustcMustNotCallOnInteriorMutableConsts {
43+
const PATH: &[Symbol] = &[sym::rustc_must_not_call_on_interior_mutable_consts];
44+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
45+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
46+
Allow(Target::Method(MethodKind::Inherent)),
47+
Allow(Target::Method(MethodKind::TraitImpl)),
48+
]);
49+
const CREATE: fn(Span) -> AttributeKind =
50+
AttributeKind::RustcMustNotCallOnInteriorMutableConsts;
51+
}
52+
4153
pub(crate) struct AutomaticallyDerivedParser;
4254
impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
4355
const PATH: &[Symbol] = &[sym::automatically_derived];

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::attributes::link_attrs::{
3838
};
3939
use crate::attributes::lint_helpers::{
4040
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
41+
RustcMustNotCallOnInteriorMutableConsts,
4142
};
4243
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
4344
use crate::attributes::macro_attrs::{
@@ -239,6 +240,7 @@ attribute_parsers!(
239240
Single<WithoutArgs<PubTransparentParser>>,
240241
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
241242
Single<WithoutArgs<RustcMainParser>>,
243+
Single<WithoutArgs<RustcMustNotCallOnInteriorMutableConsts>>,
242244
Single<WithoutArgs<SpecializationTraitParser>>,
243245
Single<WithoutArgs<StdInternalSymbolParser>>,
244246
Single<WithoutArgs<TrackCallerParser>>,

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
12431243
EncodeCrossCrate::Yes,
12441244
"`#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations."
12451245
),
1246+
rustc_attr!(
1247+
rustc_must_not_call_on_interior_mutable_consts, Normal, template!(Word), ErrorFollowing,
1248+
EncodeCrossCrate::Yes,
1249+
"`#[rustc_must_not_call_on_interior_mutable_consts]` is used to mark methods that don't make sense to be called on interior mutable consts."
1250+
),
12461251
rustc_attr!(
12471252
rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
12481253
EncodeCrossCrate::Yes,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,9 @@ pub enum AttributeKind {
673673
/// Represents `#[rustc_main]`.
674674
RustcMain,
675675

676+
/// Represents `#[rustc_must_not_call_on_interior_mutable_consts]`
677+
RustcMustNotCallOnInteriorMutableConsts(Span),
678+
676679
/// Represents `#[rustc_object_lifetime_default]`.
677680
RustcObjectLifetimeDefault,
678681

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl AttributeKind {
8989
RustcLayoutScalarValidRangeEnd(..) => Yes,
9090
RustcLayoutScalarValidRangeStart(..) => Yes,
9191
RustcMain => No,
92+
RustcMustNotCallOnInteriorMutableConsts(..) => Yes,
9293
RustcObjectLifetimeDefault => No,
9394
RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
9495
Sanitize { .. } => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
283283
| AttributeKind::ObjcSelector { .. }
284284
| AttributeKind::RustcCoherenceIsCore(..)
285285
| AttributeKind::DebuggerVisualizer(..)
286-
| AttributeKind::RustcMain,
286+
| AttributeKind::RustcMain
287+
| AttributeKind::RustcMustNotCallOnInteriorMutableConsts(..)
287288
) => { /* do nothing */ }
288289
Attribute::Unparsed(attr_item) => {
289290
style = Some(attr_item.style);

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,7 @@ symbols! {
19261926
rustc_main,
19271927
rustc_mir,
19281928
rustc_must_implement_one_of,
1929+
rustc_must_not_call_on_interior_mutable_consts,
19291930
rustc_never_returns_null_ptr,
19301931
rustc_never_type_options,
19311932
rustc_no_implicit_autorefs,

0 commit comments

Comments
 (0)