mirror of
https://github.com/rust-lang/cargo
synced 2024-08-25 10:35:53 +00:00
Fix panic with build-std of a proc-macro.
This commit is contained in:
parent
835d5576e1
commit
00e925f61f
|
@ -142,6 +142,7 @@ fn attach_std_deps(
|
|||
std_unit_deps: UnitGraph,
|
||||
) {
|
||||
// Attach the standard library as a dependency of every target unit.
|
||||
let mut found = false;
|
||||
for (unit, deps) in state.unit_dependencies.iter_mut() {
|
||||
if !unit.kind.is_host() && !unit.mode.is_run_custom_build() {
|
||||
deps.extend(std_roots[&unit.kind].iter().map(|unit| UnitDep {
|
||||
|
@ -152,12 +153,16 @@ fn attach_std_deps(
|
|||
public: true,
|
||||
noprelude: true,
|
||||
}));
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
// And also include the dependencies of the standard library itself.
|
||||
for (unit, deps) in std_unit_deps.into_iter() {
|
||||
if let Some(other_unit) = state.unit_dependencies.insert(unit, deps) {
|
||||
panic!("std unit collision with existing unit: {:?}", other_unit);
|
||||
// And also include the dependencies of the standard library itself. Don't
|
||||
// include these if no units actually needed the standard library.
|
||||
if found {
|
||||
for (unit, deps) in std_unit_deps.into_iter() {
|
||||
if let Some(other_unit) = state.unit_dependencies.insert(unit, deps) {
|
||||
panic!("std unit collision with existing unit: {:?}", other_unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -662,3 +662,31 @@ fn no_roots() {
|
|||
.with_stderr_contains("[FINISHED] [..]")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn proc_macro_only() {
|
||||
// Checks for a bug where it would panic if building a proc-macro only
|
||||
let setup = match setup() {
|
||||
Some(s) => s,
|
||||
None => return,
|
||||
};
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "pm"
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.build();
|
||||
p.cargo("build")
|
||||
.build_std(&setup)
|
||||
.target_host()
|
||||
.with_stderr_contains("[FINISHED] [..]")
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue