Skip to content

Commit 642449a

Browse files
committed
Add #[rustc_significant_interior_mutable_type] attribute
1 parent 7d65abf commit 642449a

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
@@ -922,6 +922,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
922922
rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
923923
"`#[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."
924924
),
925+
rustc_attr!(
926+
rustc_significant_interior_mutable_type, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
927+
"#[rustc_significant_interior_mutable_type] is used to mark type that are significant interior mutable types."
928+
),
925929
rustc_attr!(
926930
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
927931
"#![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
}
@@ -1823,6 +1826,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18231826
}
18241827
}
18251828

1829+
/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
1830+
fn check_rustc_significant_interior_mutable_type(
1831+
&self,
1832+
attr: &Attribute,
1833+
span: Span,
1834+
target: Target,
1835+
) {
1836+
match target {
1837+
Target::Struct | Target::Enum | Target::Union => {}
1838+
_ => {
1839+
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
1840+
attr_span: attr.span(),
1841+
span,
1842+
});
1843+
}
1844+
}
1845+
}
1846+
18261847
/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
18271848
fn check_rustc_lint_opt_ty(&self, attr: &Attribute, span: Span, target: Target) {
18281849
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
@@ -1849,6 +1849,7 @@ symbols! {
18491849
rustc_regions,
18501850
rustc_reservation_impl,
18511851
rustc_serialize,
1852+
rustc_significant_interior_mutable_type,
18521853
rustc_skip_during_method_dispatch,
18531854
rustc_specialization_trait,
18541855
rustc_std_internal_symbol,

0 commit comments

Comments
 (0)