1
Fork 0

Rollup merge of #116162 - fmease:gate-n-validate-rustc_safe_intrinsic, r=Nilstrieb

Gate and validate `#[rustc_safe_intrinsic]`

Copied over from #116159:

> This was added as ungated in https://github.com/rust-lang/rust/pull/100719/files#diff-09c366d3ad3ec9a42125253b610ca83cad6b156aa2a723f6c7e83eddef7b1e8fR502, probably because the author looked at the surrounding attributes, which are ungated because they are gated specially behind the staged_api feature.
>
> I don't think we need to crater this, the attribute is entirely useless without the intrinsics feature, which is already unstable..

r? ``@Nilstrieb``
This commit is contained in:
Matthias Krüger 2023-09-26 15:57:26 +02:00 committed by GitHub
commit 6f4a0a1eb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,

View file

@ -620,6 +620,15 @@ pub struct RustcAllowConstFnUnstable {
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(passes_rustc_safe_intrinsic)]
pub struct RustcSafeIntrinsic {
#[primary_span]
pub attr_span: Span,
#[label]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(passes_rustc_std_internal_symbol)]
pub struct RustcStdInternalSymbol {