Skip to content

Commit 5a3fef5

Browse files
committed
Add #[rustc_significant_interior_mutable_type] attribute
1 parent 3ec4308 commit 5a3fef5

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
887887
EncodeCrossCrate::Yes,
888888
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
889889
),
890+
rustc_attr!(
891+
rustc_significant_interior_mutable_type, Normal, template!(Word), ErrorFollowing,
892+
EncodeCrossCrate::Yes,
893+
"#[rustc_significant_interior_mutable_type] is used to mark type that are significant interiormutable types."
894+
),
890895
rustc_attr!(
891896
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
892897
"#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."

compiler/rustc_passes/src/check_attr.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
164164
[sym::rustc_never_returns_null_ptr, ..] => {
165165
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
166166
}
167+
[sym::rustc_significant_interior_mutable_type, ..] => {
168+
self.check_rustc_significant_interior_mutable_type(attr, span, target)
169+
}
167170
[sym::rustc_legacy_const_generics, ..] => {
168171
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
169172
}
@@ -1628,6 +1631,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16281631
}
16291632
}
16301633

1634+
/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
1635+
fn check_rustc_significant_interior_mutable_type(
1636+
&self,
1637+
attr: &Attribute,
1638+
span: Span,
1639+
target: Target,
1640+
) {
1641+
match target {
1642+
Target::Struct | Target::Enum | Target::Union => {}
1643+
_ => {
1644+
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
1645+
attr_span: attr.span,
1646+
span,
1647+
});
1648+
}
1649+
}
1650+
}
1651+
16311652
/// Checks if the attribute is applied to a trait.
16321653
fn check_must_be_applied_to_trait(&self, attr: &Attribute, span: Span, target: Target) {
16331654
match target {

compiler/rustc_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ pub(crate) struct AttrShouldBeAppliedToFn {
9696
pub on_crate: bool,
9797
}
9898

99+
#[derive(Diagnostic)]
100+
#[diag(passes_should_be_applied_to_struct_enum)]
101+
pub(crate) struct AttrShouldBeAppliedToStructEnum {
102+
#[primary_span]
103+
pub attr_span: Span,
104+
#[label]
105+
pub span: Span,
106+
}
107+
99108
#[derive(Diagnostic)]
100109
#[diag(passes_should_be_applied_to_fn, code = E0739)]
101110
pub(crate) struct TrackedCallerWrongLocation {

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,7 @@ symbols! {
17401740
rustc_runtime,
17411741
rustc_safe_intrinsic,
17421742
rustc_serialize,
1743+
rustc_significant_interior_mutable_type,
17431744
rustc_skip_during_method_dispatch,
17441745
rustc_specialization_trait,
17451746
rustc_std_internal_symbol,

0 commit comments

Comments
 (0)