about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2022-08-04 09:28:59 +0800
committeryukang <moorekang@gmail.com>2022-08-04 09:28:59 +0800
commite614bbcd301eb4c3dbb65a4aa3147dc0b6ff197c (patch)
tree12f0e4177eb3d94506cb555f3b8725811ac78ceb
parent4a5e83c939706e208d09eda477f3e4785ed6de02 (diff)
downloadrust-e614bbcd301eb4c3dbb65a4aa3147dc0b6ff197c.tar.gz
rust-e614bbcd301eb4c3dbb65a4aa3147dc0b6ff197c.zip
link_ordinal is available for foreign static
-rw-r--r--compiler/rustc_error_messages/locales/en-US/passes.ftl4
-rw-r--r--compiler/rustc_passes/src/check_attr.rs2
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.rs11
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.stderr12
4 files changed, 21 insertions, 8 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/passes.ftl b/compiler/rustc_error_messages/locales/en-US/passes.ftl
index 2802a0d2c64..d8056c77f0f 100644
--- a/compiler/rustc_error_messages/locales/en-US/passes.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/passes.ftl
@@ -263,5 +263,5 @@ 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
-    .label = not a foreign function
\ No newline at end of file
+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 9fee28a4035..8a8d88d7bf4 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -1864,7 +1864,7 @@ impl CheckAttrVisitor<'_> {
 
     fn check_link_ordinal(&self, attr: &Attribute, _span: Span, target: Target) -> bool {
         match target {
-            Target::ForeignFn => true,
+            Target::ForeignFn | Target::ForeignStatic => true,
             _ => {
                 self.tcx.sess.emit_err(errors::LinkOrdinal { attr_span: attr.span });
                 false
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.rs
index c86756be4f6..5d273d52a92 100644
--- a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.rs
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.rs
@@ -2,17 +2,24 @@
 //~^ WARN the feature `raw_dylib` is incomplete
 
 #[link_ordinal(123)]
-//~^ ERROR attribute should be applied to a foreign function
+//~^ ERROR attribute should be applied to a foreign function or static
 struct Foo {}
 
 #[link_ordinal(123)]
-//~^ ERROR attribute should be applied to a foreign function
+//~^ ERROR attribute should be applied to a foreign function or static
 fn test() {}
 
+#[link_ordinal(42)]
+//~^ ERROR attribute should be applied to a foreign function or static
+static mut imported_val: i32 = 123;
+
 #[link(name = "exporter", kind = "raw-dylib")]
 extern {
     #[link_ordinal(13)]
     fn imported_function();
+
+    #[link_ordinal(42)]
+    static mut imported_variable: i32;
 }
 
 fn main() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.stderr
index c3c399d5759..8fa2f16f44d 100644
--- a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.stderr
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.stderr
@@ -7,17 +7,23 @@ LL | #![feature(raw_dylib)]
    = note: `#[warn(incomplete_features)]` on by default
    = note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
 
-error: attribute should be applied to a foreign function
+error: attribute should be applied to a foreign function or static
   --> $DIR/link-ordinal-not-foreign-fn.rs:4:1
    |
 LL | #[link_ordinal(123)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: attribute should be applied to a foreign function
+error: attribute should be applied to a foreign function or static
   --> $DIR/link-ordinal-not-foreign-fn.rs:8:1
    |
 LL | #[link_ordinal(123)]
    | ^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 2 previous errors; 1 warning emitted
+error: attribute should be applied to a foreign function or static
+  --> $DIR/link-ordinal-not-foreign-fn.rs:12:1
+   |
+LL | #[link_ordinal(42)]
+   | ^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors; 1 warning emitted