Skip to content

Commit be30909

Browse files
committed
Add #[rustc_significant_interior_mutable_type] attribute
1 parent 5f3b84a commit be30909

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
@@ -896,6 +896,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
896896
EncodeCrossCrate::Yes,
897897
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
898898
),
899+
rustc_attr!(
900+
rustc_significant_interior_mutable_type, Normal, template!(Word), ErrorFollowing,
901+
EncodeCrossCrate::Yes,
902+
"#[rustc_significant_interior_mutable_type] is used to mark type that are significant interior mutable types."
903+
),
899904
rustc_attr!(
900905
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
901906
"#![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
@@ -179,6 +179,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
179179
[sym::rustc_as_ptr, ..] => {
180180
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
181181
}
182+
[sym::rustc_significant_interior_mutable_type, ..] => {
183+
self.check_rustc_significant_interior_mutable_type(attr, span, target)
184+
}
182185
[sym::rustc_never_returns_null_ptr, ..] => {
183186
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
184187
}
@@ -1766,6 +1769,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
17661769
}
17671770
}
17681771

1772+
/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
1773+
fn check_rustc_significant_interior_mutable_type(
1774+
&self,
1775+
attr: &Attribute,
1776+
span: Span,
1777+
target: Target,
1778+
) {
1779+
match target {
1780+
Target::Struct | Target::Enum | Target::Union => {}
1781+
_ => {
1782+
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
1783+
attr_span: attr.span(),
1784+
span,
1785+
});
1786+
}
1787+
}
1788+
}
1789+
17691790
/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
17701791
fn check_rustc_lint_opt_ty(&self, attr: &Attribute, span: Span, target: Target) {
17711792
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
@@ -1822,6 +1822,7 @@ symbols! {
18221822
rustc_regions,
18231823
rustc_reservation_impl,
18241824
rustc_serialize,
1825+
rustc_significant_interior_mutable_type,
18251826
rustc_skip_during_method_dispatch,
18261827
rustc_specialization_trait,
18271828
rustc_std_internal_symbol,

0 commit comments

Comments
 (0)