|
| 1 | +// The --extern flag can override the default crate search of |
| 2 | +// the compiler and directly fetch a given path. There are a few rules |
| 3 | +// to follow: for example, there can't be more than one rlib, the crates must |
| 4 | +// be valid ("no-exist" in this test), and private crates can't be loaded |
| 5 | +// as non-private. This test checks that these rules are enforced. |
| 6 | +// See https://github.com/rust-lang/rust/pull/15319 |
| 7 | + |
| 8 | +//@ ignore-cross-compile |
| 9 | + |
| 10 | +use run_make_support::{rust_lib_name, rustc}; |
| 11 | + |
| 12 | +fn main() { |
| 13 | + rustc().input("bar.rs").crate_type("rlib").run(); |
| 14 | + rustc().input("bar.rs").crate_type("rlib").extra_filename("-a").run(); |
| 15 | + rustc().input("bar-alt.rs").crate_type("rlib").run(); |
| 16 | + rustc().input("foo.rs").extern_("bar", "no-exist").run_fail(); |
| 17 | + rustc().input("foo.rs").extern_("bar", "foo.rs").run_fail(); |
| 18 | + rustc() |
| 19 | + .input("foo.rs") |
| 20 | + .extern_("bar", rust_lib_name("bar")) |
| 21 | + .extern_("bar", rust_lib_name("bar-alt")) |
| 22 | + .run_fail(); |
| 23 | + rustc() |
| 24 | + .input("foo.rs") |
| 25 | + .extern_("bar", rust_lib_name("bar")) |
| 26 | + .extern_("bar", rust_lib_name("bar-a")) |
| 27 | + .run(); |
| 28 | + rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).run(); |
| 29 | + // Try to be sneaky and load a private crate from with a non-private name. |
| 30 | + rustc().input("rustc.rs").arg("-Zforce-unstable-if-unmarked").crate_type("rlib").run(); |
| 31 | + rustc() |
| 32 | + .input("gated_unstable.rs") |
| 33 | + .extern_("alloc", rust_lib_name("rustc")) |
| 34 | + .run_fail() |
| 35 | + .assert_stderr_contains("rustc_private"); |
| 36 | +} |
0 commit comments