Skip to content

Commit 697df8f

Browse files
committed
Add #[rustc_significant_interior_mutable_type] attribute
1 parent 4b696e6 commit 697df8f

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 static 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
@@ -178,6 +178,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
178178
[sym::rustc_as_ptr, ..] => {
179179
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
180180
}
181+
[sym::rustc_significant_interior_mutable_type, ..] => {
182+
self.check_rustc_significant_interior_mutable_type(attr, span, target)
183+
}
181184
[sym::rustc_never_returns_null_ptr, ..] => {
182185
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
183186
}
@@ -1761,6 +1764,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
17611764
}
17621765
}
17631766

1767+
/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
1768+
fn check_rustc_significant_interior_mutable_type(
1769+
&self,
1770+
attr: &Attribute,
1771+
span: Span,
1772+
target: Target,
1773+
) {
1774+
match target {
1775+
Target::Struct | Target::Enum | Target::Union => {}
1776+
_ => {
1777+
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
1778+
attr_span: attr.span(),
1779+
span,
1780+
});
1781+
}
1782+
}
1783+
}
1784+
17641785
/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
17651786
fn check_rustc_lint_opt_ty(&self, attr: &Attribute, span: Span, target: Target) {
17661787
match target {

compiler/rustc_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ pub(crate) struct AttrShouldBeAppliedToFn {
108108
pub on_crate: bool,
109109
}
110110

111+
#[derive(Diagnostic)]
112+
#[diag(passes_should_be_applied_to_struct_enum)]
113+
pub(crate) struct AttrShouldBeAppliedToStructEnum {
114+
#[primary_span]
115+
pub attr_span: Span,
116+
#[label]
117+
pub span: Span,
118+
}
119+
111120
#[derive(Diagnostic)]
112121
#[diag(passes_should_be_applied_to_fn, code = E0739)]
113122
pub(crate) struct TrackedCallerWrongLocation {

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ symbols! {
18031803
rustc_regions,
18041804
rustc_reservation_impl,
18051805
rustc_serialize,
1806+
rustc_significant_interior_mutable_type,
18061807
rustc_skip_during_method_dispatch,
18071808
rustc_specialization_trait,
18081809
rustc_std_internal_symbol,

0 commit comments

Comments
 (0)