diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs
index 9f6079ecba4d6..c5e39507d7e4d 100644
--- a/compiler/rustc_metadata/src/native_libs.rs
+++ b/compiler/rustc_metadata/src/native_libs.rs
@@ -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),
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs
new file mode 100644
index 0000000000000..99f317399d768
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs
@@ -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() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr
new file mode 100644
index 0000000000000..f1eeb22da59c9
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr
@@ -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
+