Add error if link_ordinal used without raw-dylib
This commit is contained in:
parent
6d3f1beae1
commit
fda5144ceb
@ -328,7 +328,31 @@ fn process_item(&mut self, id: rustc_hir::ItemId) {
|
||||
.map(|child_item| self.build_dll_import(abi, child_item))
|
||||
.collect()
|
||||
}
|
||||
_ => Vec::new(),
|
||||
_ => {
|
||||
for child_item in foreign_mod_items {
|
||||
if self.tcx.def_kind(child_item.id.def_id).has_codegen_attrs()
|
||||
&& self
|
||||
.tcx
|
||||
.codegen_fn_attrs(child_item.id.def_id)
|
||||
.link_ordinal
|
||||
.is_some()
|
||||
{
|
||||
let link_ordinal_attr = self
|
||||
.tcx
|
||||
.hir()
|
||||
.attrs(self.tcx.hir().local_def_id_to_hir_id(child_item.id.def_id))
|
||||
.iter()
|
||||
.find(|a| a.has_name(sym::link_ordinal))
|
||||
.unwrap();
|
||||
sess.span_err(
|
||||
link_ordinal_attr.span,
|
||||
"`#[link_ordinal]` is only supported if link kind is `raw-dylib`",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Vec::new()
|
||||
}
|
||||
};
|
||||
self.libs.push(NativeLib {
|
||||
name: name.map(|(name, _)| name),
|
||||
|
@ -0,0 +1,18 @@
|
||||
#![feature(raw_dylib)]
|
||||
//~^ WARN the feature `raw_dylib` is incomplete
|
||||
|
||||
#[link(name = "foo")]
|
||||
extern "C" {
|
||||
#[link_ordinal(3)]
|
||||
//~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
|
||||
fn foo();
|
||||
}
|
||||
|
||||
#[link(name = "bar", kind = "static")]
|
||||
extern "C" {
|
||||
#[link_ordinal(3)]
|
||||
//~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib`
|
||||
fn bar();
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,23 @@
|
||||
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/link-ordinal-unsupported-link-kind.rs:1:12
|
||||
|
|
||||
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: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
|
||||
--> $DIR/link-ordinal-unsupported-link-kind.rs:6:5
|
||||
|
|
||||
LL | #[link_ordinal(3)]
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: `#[link_ordinal]` is only supported if link kind is `raw-dylib`
|
||||
--> $DIR/link-ordinal-unsupported-link-kind.rs:13:5
|
||||
|
|
||||
LL | #[link_ordinal(3)]
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors; 1 warning emitted
|
||||
|
Loading…
Reference in New Issue
Block a user