From 3f89ee825604569eef44a349074011b34034f69e Mon Sep 17 00:00:00 2001 From: xizheyin Date: Wed, 9 Jul 2025 20:29:06 +0800 Subject: [PATCH 1/3] Make `SearchPath::new` private Signed-off-by: xizheyin --- compiler/rustc_session/src/search_paths.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/search_paths.rs b/compiler/rustc_session/src/search_paths.rs index 00e12b45bafb1..95bd09f366775 100644 --- a/compiler/rustc_session/src/search_paths.rs +++ b/compiler/rustc_session/src/search_paths.rs @@ -131,7 +131,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 From 85ea5c3e1a2437d46a9395d15db9113aab3e7a91 Mon Sep 17 00:00:00 2001 From: xizheyin Date: Wed, 9 Jul 2025 21:24:01 +0800 Subject: [PATCH 2/3] Add ui test search-path-not-found.rs Signed-off-by: xizheyin --- tests/ui/link-native-libs/search-path-not-found.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/ui/link-native-libs/search-path-not-found.rs 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..91bb4f7919d16 --- /dev/null +++ b/tests/ui/link-native-libs/search-path-not-found.rs @@ -0,0 +1,4 @@ +//@ check-pass +//@ compile-flags: -L native=does-not-exist -Link-everything-statically + +fn main() {} From 04fbacce28270ad4e4ad6610b612f249be479b7f Mon Sep 17 00:00:00 2001 From: xizheyin Date: Wed, 9 Jul 2025 21:59:40 +0800 Subject: [PATCH 3/3] Emit warning when search path not found in `-L` Signed-off-by: xizheyin --- compiler/rustc_session/src/search_paths.rs | 5 +++++ tests/ui/link-native-libs/search-path-not-found.rs | 3 +++ tests/ui/link-native-libs/search-path-not-found.stderr | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 tests/ui/link-native-libs/search-path-not-found.stderr diff --git a/compiler/rustc_session/src/search_paths.rs b/compiler/rustc_session/src/search_paths.rs index 95bd09f366775..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) } diff --git a/tests/ui/link-native-libs/search-path-not-found.rs b/tests/ui/link-native-libs/search-path-not-found.rs index 91bb4f7919d16..eb94f642c16b8 100644 --- a/tests/ui/link-native-libs/search-path-not-found.rs +++ b/tests/ui/link-native-libs/search-path-not-found.rs @@ -2,3 +2,6 @@ //@ 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 +