Skip to content

Commit 7c96be4

Browse files
committed
Add #[rustc_must_not_call_on_interior_mutable_consts] attribute
1 parent 6a884ad commit 7c96be4

File tree

7 files changed

+25
-0
lines changed

7 files changed

+25
-0
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::{
@@ -241,6 +242,7 @@ attribute_parsers!(
241242
Single<WithoutArgs<PubTransparentParser>>,
242243
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
243244
Single<WithoutArgs<RustcMainParser>>,
245+
Single<WithoutArgs<RustcMustNotCallOnInteriorMutableConsts>>,
244246
Single<WithoutArgs<SpecializationTraitParser>>,
245247
Single<WithoutArgs<StdInternalSymbolParser>>,
246248
Single<WithoutArgs<TrackCallerParser>>,

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
12521252
EncodeCrossCrate::Yes,
12531253
"`#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations."
12541254
),
1255+
rustc_attr!(
1256+
rustc_must_not_call_on_interior_mutable_consts, Normal, template!(Word), ErrorFollowing,
1257+
EncodeCrossCrate::Yes,
1258+
"`#[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."
1259+
),
12551260
rustc_attr!(
12561261
rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
12571262
EncodeCrossCrate::Yes,

compiler/rustc_hir/src/attrs/data_structures.rs

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

679+
/// Represents `#[rustc_must_not_call_on_interior_mutable_consts]`
680+
RustcMustNotCallOnInteriorMutableConsts(Span),
681+
679682
/// Represents `#[rustc_object_lifetime_default]`.
680683
RustcObjectLifetimeDefault,
681684

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

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

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
257257
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
258258
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
259259
| AttributeKind::RustcSimdMonomorphizeLaneLimit(..)
260+
| AttributeKind::RustcMustNotCallOnInteriorMutableConsts(..)
260261
| AttributeKind::ExportStable
261262
| AttributeKind::FfiConst(..)
262263
| AttributeKind::UnstableFeatureBound(..)

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,7 @@ symbols! {
19281928
rustc_main,
19291929
rustc_mir,
19301930
rustc_must_implement_one_of,
1931+
rustc_must_not_call_on_interior_mutable_consts,
19311932
rustc_never_returns_null_ptr,
19321933
rustc_never_type_options,
19331934
rustc_no_implicit_autorefs,

0 commit comments

Comments
 (0)