Gate and validate #[rustc_safe_intrinsic]

This commit is contained in:
León Orell Valerian Liehr
2023-09-25 21:40:40 +02:00
parent aadb5718dd
commit f54db7c3a9
14 changed files with 79 additions and 11 deletions

View File

@@ -195,6 +195,9 @@ impl CheckAttrVisitor<'_> {
| sym::rustc_promotable => self.check_stability_promotable(&attr, span, target),
sym::link_ordinal => self.check_link_ordinal(&attr, span, target),
sym::rustc_confusables => self.check_confusables(&attr, target),
sym::rustc_safe_intrinsic => {
self.check_rustc_safe_intrinsic(hir_id, attr, span, target)
}
_ => true,
};
@@ -2042,6 +2045,29 @@ impl CheckAttrVisitor<'_> {
}
}
fn check_rustc_safe_intrinsic(
&self,
hir_id: HirId,
attr: &Attribute,
span: Span,
target: Target,
) -> bool {
let hir = self.tcx.hir();
if let Target::ForeignFn = target
&& let Some(parent) = hir.opt_parent_id(hir_id)
&& let hir::Node::Item(Item {
kind: ItemKind::ForeignMod { abi: Abi::RustIntrinsic | Abi::PlatformIntrinsic, .. },
..
}) = hir.get(parent)
{
return true;
}
self.tcx.sess.emit_err(errors::RustcSafeIntrinsic { attr_span: attr.span, span });
false
}
fn check_rustc_std_internal_symbol(
&self,
attr: &Attribute,