Skip to content

Commit

Permalink
Add #[rustc_significant_interior_mutable_type] attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Oct 26, 2024
1 parent 4d88de2 commit afcb09b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
EncodeCrossCrate::Yes,
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
),
rustc_attr!(
rustc_significant_interior_mutable_type, Normal, template!(Word), ErrorFollowing,
EncodeCrossCrate::Yes,
"#[rustc_significant_interior_mutable_type] is used to mark type that are significant interiormutable types."
),
rustc_attr!(
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
"#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
[sym::rustc_never_returns_null_ptr, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
}
[sym::rustc_significant_interior_mutable_type, ..] => {
self.check_rustc_significant_interior_mutable_type(attr, span, target)
}
[sym::rustc_legacy_const_generics, ..] => {
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
}
Expand Down Expand Up @@ -1631,6 +1634,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

/// Checks if `#[rustc_significant_interior_mutable_type]` is applied to a struct, enum, union, or trait.
fn check_rustc_significant_interior_mutable_type(
&self,
attr: &Attribute,
span: Span,
target: Target,
) {
match target {
Target::Struct | Target::Enum | Target::Union => {}
_ => {
self.dcx().emit_err(errors::AttrShouldBeAppliedToStructEnum {
attr_span: attr.span,
span,
});
}
}
}

/// Checks if the attribute is applied to a trait.
fn check_must_be_applied_to_trait(&self, attr: &Attribute, span: Span, target: Target) {
match target {
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ pub(crate) struct AttrShouldBeAppliedToFn {
pub on_crate: bool,
}

#[derive(Diagnostic)]
#[diag(passes_should_be_applied_to_struct_enum)]
pub(crate) struct AttrShouldBeAppliedToStructEnum {
#[primary_span]
pub attr_span: Span,
#[label]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(passes_should_be_applied_to_fn, code = E0739)]
pub(crate) struct TrackedCallerWrongLocation {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@ symbols! {
rustc_reservation_impl,
rustc_safe_intrinsic,
rustc_serialize,
rustc_significant_interior_mutable_type,
rustc_skip_during_method_dispatch,
rustc_specialization_trait,
rustc_std_internal_symbol,
Expand Down

0 comments on commit afcb09b

Please sign in to comment.