Skip to content

Commit 4a66f2a

Browse files
committed
Add #[rustc_significant_interior_mutable_type] attribute
1 parent b5eb989 commit 4a66f2a

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
948948
rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
949949
"`#[rustc_no_implicit_autorefs]` is used to mark functions for which an autoref to the dereference of a raw pointer should not be used as an argument."
950950
),
951+
rustc_attr!(
952+
rustc_significant_interior_mutable_type, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
953+
"#[rustc_significant_interior_mutable_type] is used to mark type that are significant interior mutable types."
954+
),
951955
rustc_attr!(
952956
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
953957
"#![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
@@ -182,6 +182,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
182182
[sym::rustc_no_implicit_autorefs, ..] => {
183183
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
184184
}
185+
[sym::rustc_significant_interior_mutable_type, ..] => {
186+
self.check_rustc_significant_interior_mutable_type(attr, span, target)
187+
}
185188
[sym::rustc_never_returns_null_ptr, ..] => {
186189
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
187190
}
@@ -1827,6 +1830,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18271830
}
18281831
}
18291832

1833+
/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
1834+
fn check_rustc_significant_interior_mutable_type(
1835+
&self,
1836+
attr: &Attribute,
1837+
span: Span,
1838+
target: Target,
1839+
) {
1840+
match target {
1841+
Target::Struct | Target::Enum | Target::Union => {}
1842+
_ => {
1843+
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
1844+
attr_span: attr.span(),
1845+
span,
1846+
});
1847+
}
1848+
}
1849+
}
1850+
18301851
/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
18311852
fn check_rustc_lint_opt_ty(&self, attr: &Attribute, span: Span, target: Target) {
18321853
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
@@ -1862,6 +1862,7 @@ symbols! {
18621862
rustc_regions,
18631863
rustc_reservation_impl,
18641864
rustc_serialize,
1865+
rustc_significant_interior_mutable_type,
18651866
rustc_skip_during_method_dispatch,
18661867
rustc_specialization_trait,
18671868
rustc_std_internal_symbol,

0 commit comments

Comments
 (0)