Skip to content

Commit d359307

Browse files
authored
Rollup merge of rust-lang#139834 - ChrisDenton:spf, r=WaffleLapkin
Don't canonicalize crate paths When printing paths in diagnostic we should favour printing the paths that were passed in rather than resolving all symlinks. This PR changes the form of the crate path but it should only really affect diagnostics as filesystem functions won't care which path is used. The uncanonicalized path was already used as a fallback for when canonicalization failed. This is a partial alternative to rust-lang#139823.
2 parents a1c3f0d + 52f35d0 commit d359307

File tree

6 files changed

+76
-6
lines changed

6 files changed

+76
-6
lines changed

Diff for: compiler/rustc_metadata/src/locator.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,21 @@ impl<'a> CrateLocator<'a> {
427427

428428
let (rlibs, rmetas, dylibs) =
429429
candidates.entry(hash.to_string()).or_default();
430-
let path =
431-
try_canonicalize(&spf.path).unwrap_or_else(|_| spf.path.to_path_buf());
432-
if seen_paths.contains(&path) {
433-
continue;
434-
};
435-
seen_paths.insert(path.clone());
430+
{
431+
// As a perforamnce optimisation we canonicalize the path and skip
432+
// ones we've already seeen. This allows us to ignore crates
433+
// we know are exactual equal to ones we've already found.
434+
// Going to the same crate through different symlinks does not change the result.
435+
let path = try_canonicalize(&spf.path)
436+
.unwrap_or_else(|_| spf.path.to_path_buf());
437+
if seen_paths.contains(&path) {
438+
continue;
439+
};
440+
seen_paths.insert(path);
441+
}
442+
// Use the original path (potentially with unresolved symlinks),
443+
// filesystem code should not care, but this is nicer for diagnostics.
444+
let path = spf.path.to_path_buf();
436445
match kind {
437446
CrateFlavor::Rlib => rlibs.insert(path, search_path.kind),
438447
CrateFlavor::Rmeta => rmetas.insert(path, search_path.kind),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_name = "crateresolve1"]
2+
#![crate_type = "lib"]
3+
4+
pub fn f() -> isize {
5+
10
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_name = "crateresolve1"]
2+
#![crate_type = "lib"]
3+
4+
pub fn f() -> isize {
5+
20
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern crate crateresolve1;
2+
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0464]: multiple candidates for `rlib` dependency `crateresolve1` found
2+
--> multiple-candidates.rs:1:1
3+
|
4+
LL | extern crate crateresolve1;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: candidate #1: ./mylibs/libcrateresolve1-1.rlib
8+
= note: candidate #2: ./mylibs/libcrateresolve1-2.rlib
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0464`.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ needs-symlink
2+
//@ ignore-cross-compile
3+
4+
// Tests that the multiple candidate dependencies diagnostic prints relative
5+
// paths if a relative library path was passed in.
6+
7+
use run_make_support::{bare_rustc, diff, rfs, rustc};
8+
9+
fn main() {
10+
// Check that relative paths are preserved in the diagnostic
11+
rfs::create_dir("mylibs");
12+
rustc().input("crateresolve1-1.rs").out_dir("mylibs").extra_filename("-1").run();
13+
rustc().input("crateresolve1-2.rs").out_dir("mylibs").extra_filename("-2").run();
14+
check("./mylibs");
15+
16+
// Check that symlinks aren't followed when printing the diagnostic
17+
rfs::rename("mylibs", "original");
18+
rfs::symlink_dir("original", "mylibs");
19+
check("./mylibs");
20+
}
21+
22+
fn check(library_path: &str) {
23+
let out = rustc()
24+
.input("multiple-candidates.rs")
25+
.library_search_path(library_path)
26+
.ui_testing()
27+
.run_fail()
28+
.stderr_utf8();
29+
diff()
30+
.expected_file("multiple-candidates.stderr")
31+
.normalize(r"\\", "/")
32+
.actual_text("(rustc)", &out)
33+
.run();
34+
}

0 commit comments

Comments
 (0)