diff options
| author | bors <bors@rust-lang.org> | 2022-08-07 05:37:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-07 05:37:29 +0000 |
| commit | 5651759746e6eefa691f61522d19b46d07cf9244 (patch) | |
| tree | 233917bbb70baed4b3d3b1e2773568f5338d99ba /compiler | |
| parent | 24cf45a591481519cb0116bf2ce111ffb3e1111c (diff) | |
| parent | e614bbcd301eb4c3dbb65a4aa3147dc0b6ff197c (diff) | |
| download | rust-5651759746e6eefa691f61522d19b46d07cf9244.tar.gz rust-5651759746e6eefa691f61522d19b46d07cf9244.zip | |
Auto merge of #100091 - chenyukang:add-check-for-link-ordinal, r=michaelwoerister
Check link ordinal to make sure it is targetted for foreign function Fix #100009, when link ordinal is not target for foreign functions, emit an error. cc `@dpaoliello`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_error_messages/locales/en-US/passes.ftl | 3 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 7 |
3 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/passes.ftl b/compiler/rustc_error_messages/locales/en-US/passes.ftl index b17eb9c2d26..d8056c77f0f 100644 --- a/compiler/rustc_error_messages/locales/en-US/passes.ftl +++ b/compiler/rustc_error_messages/locales/en-US/passes.ftl @@ -262,3 +262,6 @@ passes-rustc-lint-opt-ty = `#[rustc_lint_opt_ty]` should be applied to a struct passes-rustc-lint-opt-deny-field-access = `#[rustc_lint_opt_deny_field_access]` should be applied to a field .label = not a field + +passes-link-ordinal = attribute should be applied to a foreign function or static + .label = not a foreign function or static \ No newline at end of file diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 2b213ac5c71..6fea68ce8b3 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -146,6 +146,7 @@ impl CheckAttrVisitor<'_> { | sym::stable | sym::rustc_allowed_through_unstable_modules | sym::rustc_promotable => self.check_stability_promotable(&attr, span, target), + sym::link_ordinal => self.check_link_ordinal(&attr, span, target), _ => true, }; is_valid &= attr_is_valid; @@ -1893,6 +1894,16 @@ impl CheckAttrVisitor<'_> { } } + fn check_link_ordinal(&self, attr: &Attribute, _span: Span, target: Target) -> bool { + match target { + Target::ForeignFn | Target::ForeignStatic => true, + _ => { + self.tcx.sess.emit_err(errors::LinkOrdinal { attr_span: attr.span }); + false + } + } + } + fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: Span, target: Target) { match target { Target::Closure | Target::Expression | Target::Statement | Target::Arm => { diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 5feb0e2956b..cd465380867 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -552,6 +552,13 @@ pub struct ConstTrait { } #[derive(SessionDiagnostic)] +#[error(passes::link_ordinal)] +pub struct LinkOrdinal { + #[primary_span] + pub attr_span: Span, +} + +#[derive(SessionDiagnostic)] #[error(passes::stability_promotable)] pub struct StabilityPromotable { #[primary_span] |
