Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,31 @@ impl<'tcx> Collector<'tcx> {
.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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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