diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index e7cccc818f8..9940db7d57f 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -1581,8 +1581,11 @@ pub fn translate_dep_info( for file in deps { // The path may be absolute or relative, canonical or not. Make sure // it is canonicalized so we are comparing the same kinds of paths. - let canon_file = rustc_cwd.join(file).canonicalize()?; let abs_file = rustc_cwd.join(file); + // If canonicalization fails, just use the abs path. There is currently + // a bug where --remap-path-prefix is affecting .d files, causing them + // to point to non-existent paths. + let canon_file = abs_file.canonicalize().unwrap_or_else(|_| abs_file.clone()); let (ty, path) = if let Ok(stripped) = canon_file.strip_prefix(&target_root) { (DepInfoPathType::TargetRootRelative, stripped) diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index 008bee0f45a..0589b49accc 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1,8 +1,10 @@ use std::fs::{self, File}; use std::io::Write; -use crate::support::rustc_host; -use crate::support::{basic_lib_manifest, basic_manifest, paths, project, project_in_home}; +use crate::support::registry::Package; +use crate::support::{ + basic_lib_manifest, basic_manifest, paths, project, project_in_home, rustc_host, +}; #[cargo_test] fn env_rustflags_normal_source() { @@ -1393,3 +1395,41 @@ fn remap_path_prefix_ignored() { .run(); check_metadata_same(); } + +#[cargo_test] +fn remap_path_prefix_works() { + // Check that remap-path-prefix works. + Package::new("bar", "0.1.0") + .file("src/lib.rs", "pub fn f() -> &'static str { file!() }") + .publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + bar = "0.1" + "#, + ) + .file( + "src/main.rs", + r#" + fn main() { + println!("{}", bar::f()); + } + "#, + ) + .build(); + + p.cargo("run") + .env( + "RUSTFLAGS", + format!("--remap-path-prefix={}=/foo", paths::root().display()), + ) + .with_stdout("/foo/home/.cargo/registry/src/[..]/bar-0.1.0/src/lib.rs") + .run(); +}