Skip to content

Commit e614bbc

Browse files
committed
link_ordinal is available for foreign static
1 parent 4a5e83c commit e614bbc

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

Diff for: compiler/rustc_error_messages/locales/en-US/passes.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,5 @@ passes-rustc-lint-opt-ty = `#[rustc_lint_opt_ty]` should be applied to a struct
263263
passes-rustc-lint-opt-deny-field-access = `#[rustc_lint_opt_deny_field_access]` should be applied to a field
264264
.label = not a field
265265
266-
passes-link-ordinal = attribute should be applied to a foreign function
267-
.label = not a foreign function
266+
passes-link-ordinal = attribute should be applied to a foreign function or static
267+
.label = not a foreign function or static

Diff for: compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ impl CheckAttrVisitor<'_> {
18641864

18651865
fn check_link_ordinal(&self, attr: &Attribute, _span: Span, target: Target) -> bool {
18661866
match target {
1867-
Target::ForeignFn => true,
1867+
Target::ForeignFn | Target::ForeignStatic => true,
18681868
_ => {
18691869
self.tcx.sess.emit_err(errors::LinkOrdinal { attr_span: attr.span });
18701870
false

Diff for: src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22
//~^ WARN the feature `raw_dylib` is incomplete
33

44
#[link_ordinal(123)]
5-
//~^ ERROR attribute should be applied to a foreign function
5+
//~^ ERROR attribute should be applied to a foreign function or static
66
struct Foo {}
77

88
#[link_ordinal(123)]
9-
//~^ ERROR attribute should be applied to a foreign function
9+
//~^ ERROR attribute should be applied to a foreign function or static
1010
fn test() {}
1111

12+
#[link_ordinal(42)]
13+
//~^ ERROR attribute should be applied to a foreign function or static
14+
static mut imported_val: i32 = 123;
15+
1216
#[link(name = "exporter", kind = "raw-dylib")]
1317
extern {
1418
#[link_ordinal(13)]
1519
fn imported_function();
20+
21+
#[link_ordinal(42)]
22+
static mut imported_variable: i32;
1623
}
1724

1825
fn main() {}

Diff for: src/test/ui/rfc-2627-raw-dylib/link-ordinal-not-foreign-fn.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ LL | #![feature(raw_dylib)]
77
= note: `#[warn(incomplete_features)]` on by default
88
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
99

10-
error: attribute should be applied to a foreign function
10+
error: attribute should be applied to a foreign function or static
1111
--> $DIR/link-ordinal-not-foreign-fn.rs:4:1
1212
|
1313
LL | #[link_ordinal(123)]
1414
| ^^^^^^^^^^^^^^^^^^^^
1515

16-
error: attribute should be applied to a foreign function
16+
error: attribute should be applied to a foreign function or static
1717
--> $DIR/link-ordinal-not-foreign-fn.rs:8:1
1818
|
1919
LL | #[link_ordinal(123)]
2020
| ^^^^^^^^^^^^^^^^^^^^
2121

22-
error: aborting due to 2 previous errors; 1 warning emitted
22+
error: attribute should be applied to a foreign function or static
23+
--> $DIR/link-ordinal-not-foreign-fn.rs:12:1
24+
|
25+
LL | #[link_ordinal(42)]
26+
| ^^^^^^^^^^^^^^^^^^^
27+
28+
error: aborting due to 3 previous errors; 1 warning emitted
2329

0 commit comments

Comments
 (0)