Skip to content

Commit bc6efb3

Browse files
committed
Use the replacement source instead of the original source when generating -C metadata and -C extra-filename
This commit fixes an issue when replacing two different sources with the same local one (for example using `cargo vendor`), where `rustc` errs saying that two types "defined at the same place in the same file" are "different".
1 parent fbc8ba8 commit bc6efb3

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

src/cargo/core/compiler/build_runner/compilation_files.rs

+1
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ fn compute_metadata(
585585
// to pull crates from anywhere without worrying about conflicts.
586586
unit.pkg
587587
.package_id()
588+
.with_source_id(unit.replaced_source)
588589
.stable_hash(bcx.ws.root())
589590
.hash(&mut hasher);
590591

src/cargo/core/compiler/standard_lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub fn generate_std_roots(
162162
);
163163
list.push(interner.intern(
164164
pkg,
165+
pkg.package_id().source_id(),
165166
lib,
166167
profile,
167168
*kind,

src/cargo/core/compiler/unit.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::core::compiler::unit_dependencies::IsArtifact;
44
use crate::core::compiler::{CompileKind, CompileMode, CompileTarget, CrateType};
55
use crate::core::manifest::{Target, TargetKind};
66
use crate::core::profiles::Profile;
7-
use crate::core::Package;
7+
use crate::core::{Package, SourceId};
88
use crate::util::hex::short_hash;
99
use crate::util::interning::InternedString;
1010
use crate::util::GlobalContext;
@@ -42,6 +42,7 @@ pub struct UnitInner {
4242
/// Information about available targets, which files to include/exclude, etc. Basically stuff in
4343
/// `Cargo.toml`.
4444
pub pkg: Package,
45+
pub replaced_source: SourceId,
4546
/// Information about the specific target to build, out of the possible targets in `pkg`. Not
4647
/// to be confused with *target-triple* (or *target architecture* ...), the target arch for a
4748
/// build.
@@ -226,6 +227,7 @@ impl UnitInterner {
226227
pub fn intern(
227228
&self,
228229
pkg: &Package,
230+
replaced_source: SourceId,
229231
target: &Target,
230232
profile: Profile,
231233
kind: CompileKind,
@@ -262,6 +264,7 @@ impl UnitInterner {
262264
};
263265
let inner = self.intern_inner(&UnitInner {
264266
pkg: pkg.clone(),
267+
replaced_source,
265268
target,
266269
profile,
267270
kind,

src/cargo/core/compiler/unit_dependencies.rs

+4
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,12 @@ fn new_unit_dep_with_profile(
848848
_ => None,
849849
};
850850
let features = state.activated_features(pkg.package_id(), features_for);
851+
852+
let replaced_source = state.package_set.sources().get(pkg.package_id().source_id()).unwrap().replaced_source_id();
853+
851854
let unit = state.interner.intern(
852855
pkg,
856+
replaced_source,
853857
target,
854858
profile,
855859
kind,

src/cargo/ops/cargo_compile/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ fn traverse_and_share(
695695
canonical_profile.debuginfo = canonical_debuginfo;
696696
let unit_probe = interner.intern(
697697
&unit.pkg,
698+
unit.replaced_source,
698699
&unit.target,
699700
canonical_profile,
700701
to_host.unwrap(),
@@ -723,6 +724,7 @@ fn traverse_and_share(
723724

724725
let new_unit = interner.intern(
725726
&unit.pkg,
727+
unit.replaced_source,
726728
&unit.target,
727729
profile,
728730
canonical_kind,
@@ -887,6 +889,7 @@ fn override_rustc_crate_types(
887889
target.set_kind(f(crate_types));
888890
interner.intern(
889891
&unit.pkg,
892+
unit.replaced_source,
890893
&target,
891894
unit.profile.clone(),
892895
unit.kind,

src/cargo/ops/cargo_compile/unit_generator.rs

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl<'a> UnitGenerator<'a, '_> {
166166
let kind = kind.for_target(target);
167167
self.interner.intern(
168168
pkg,
169+
pkg.package_id().source_id(),
169170
target,
170171
profile,
171172
kind,
@@ -671,6 +672,7 @@ Rustdoc did not scrape the following examples because they require dev-dependenc
671672
}
672673
None => Vec::new(),
673674
};
675+
674676
if target.is_lib() || unavailable_features.is_empty() {
675677
units.extend(self.new_units(pkg, target, mode));
676678
} else if requires_features {

0 commit comments

Comments
 (0)