Skip to content

Commit afcb09b

Browse files
committed
Add #[rustc_significant_interior_mutable_type] attribute
1 parent 4d88de2 commit afcb09b

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
@@ -885,6 +885,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
885885
EncodeCrossCrate::Yes,
886886
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
887887
),
888+
rustc_attr!(
889+
rustc_significant_interior_mutable_type, Normal, template!(Word), ErrorFollowing,
890+
EncodeCrossCrate::Yes,
891+
"#[rustc_significant_interior_mutable_type] is used to mark type that are significant interiormutable types."
892+
),
888893
rustc_attr!(
889894
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
890895
"#![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
}
@@ -1631,6 +1634,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16311634
}
16321635
}
16331636

1637+
/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
1638+
fn check_rustc_significant_interior_mutable_type(
1639+
&self,
1640+
attr: &Attribute,
1641+
span: Span,
1642+
target: Target,
1643+
) {
1644+
match target {
1645+
Target::Struct | Target::Enum | Target::Union => {}
1646+
_ => {
1647+
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
1648+
attr_span: attr.span,
1649+
span,
1650+
});
1651+
}
1652+
}
1653+
}
1654+
16341655
/// Checks if the attribute is applied to a trait.
16351656
fn check_must_be_applied_to_trait(&self, attr: &Attribute, span: Span, target: Target) {
16361657
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
@@ -1732,6 +1732,7 @@ symbols! {
17321732
rustc_reservation_impl,
17331733
rustc_safe_intrinsic,
17341734
rustc_serialize,
1735+
rustc_significant_interior_mutable_type,
17351736
rustc_skip_during_method_dispatch,
17361737
rustc_specialization_trait,
17371738
rustc_std_internal_symbol,

0 commit comments

Comments
 (0)