diff --git a/compiler/rustc_session/src/search_paths.rs b/compiler/rustc_session/src/search_paths.rs index 00e12b45bafb1..7ca13d3d82919 100644 --- a/compiler/rustc_session/src/search_paths.rs +++ b/compiler/rustc_session/src/search_paths.rs @@ -124,6 +124,11 @@ impl SearchPath { early_dcx.early_fatal("empty search path given via `-L`"); } + if !dir.exists() { + #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable + early_dcx.early_warn(format!("search path `{}` does not exist", dir.display())); + } + Self::new(kind, dir) } @@ -131,7 +136,7 @@ impl SearchPath { Self::new(PathKind::All, make_target_lib_path(sysroot, triple)) } - pub fn new(kind: PathKind, dir: PathBuf) -> Self { + fn new(kind: PathKind, dir: PathBuf) -> Self { // Get the files within the directory. let mut files = match std::fs::read_dir(&dir) { Ok(files) => files diff --git a/tests/ui/link-native-libs/search-path-not-found.rs b/tests/ui/link-native-libs/search-path-not-found.rs new file mode 100644 index 0000000000000..eb94f642c16b8 --- /dev/null +++ b/tests/ui/link-native-libs/search-path-not-found.rs @@ -0,0 +1,7 @@ +//@ check-pass +//@ compile-flags: -L native=does-not-exist -Link-everything-statically + +fn main() {} + +//~? WARN search path `does-not-exist` does not exist +//~? WARN search path `ink-everything-statically` does not exist diff --git a/tests/ui/link-native-libs/search-path-not-found.stderr b/tests/ui/link-native-libs/search-path-not-found.stderr new file mode 100644 index 0000000000000..f882e0ac8d0b6 --- /dev/null +++ b/tests/ui/link-native-libs/search-path-not-found.stderr @@ -0,0 +1,4 @@ +warning: search path `does-not-exist` does not exist + +warning: search path `ink-everything-statically` does not exist +