Skip to content

Commit de2543a

Browse files
committed
Add #[rustc_significant_interior_mutable_type] attribute
1 parent 62bb2ac commit de2543a

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
@@ -889,6 +889,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
889889
EncodeCrossCrate::Yes,
890890
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
891891
),
892+
rustc_attr!(
893+
rustc_significant_interior_mutable_type, Normal, template!(Word), ErrorFollowing,
894+
EncodeCrossCrate::Yes,
895+
"#[rustc_significant_interior_mutable_type] is used to mark type that are significant interior mutable types."
896+
),
892897
rustc_attr!(
893898
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
894899
"#![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
@@ -165,6 +165,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
165165
[sym::rustc_never_returns_null_ptr, ..] => {
166166
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
167167
}
168+
[sym::rustc_significant_interior_mutable_type, ..] => {
169+
self.check_rustc_significant_interior_mutable_type(attr, span, target)
170+
}
168171
[sym::rustc_legacy_const_generics, ..] => {
169172
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
170173
}
@@ -1629,6 +1632,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16291632
}
16301633
}
16311634

1635+
/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
1636+
fn check_rustc_significant_interior_mutable_type(
1637+
&self,
1638+
attr: &Attribute,
1639+
span: Span,
1640+
target: Target,
1641+
) {
1642+
match target {
1643+
Target::Struct | Target::Enum | Target::Union => {}
1644+
_ => {
1645+
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
1646+
attr_span: attr.span,
1647+
span,
1648+
});
1649+
}
1650+
}
1651+
}
1652+
16321653
/// Checks if the attribute is applied to a trait.
16331654
fn check_must_be_applied_to_trait(&self, attr: &Attribute, span: Span, target: Target) {
16341655
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
@@ -1734,6 +1734,7 @@ symbols! {
17341734
rustc_regions,
17351735
rustc_reservation_impl,
17361736
rustc_serialize,
1737+
rustc_significant_interior_mutable_type,
17371738
rustc_skip_during_method_dispatch,
17381739
rustc_specialization_trait,
17391740
rustc_std_internal_symbol,

0 commit comments

Comments
 (0)