From 53485b0ef996fce9d5989164dad8243cf1e2f9a1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 23 Mar 2018 12:20:01 +0300 Subject: [PATCH] Simplify `build_map` This doesn't change semantics, but helps us not to rebuild BuildScripts twice, and makes sure that we fail with assert if somehow we get cyclic deps --- src/cargo/ops/cargo_rustc/custom_build.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index 32fb3ef74..0457eecc1 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -1,4 +1,5 @@ -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::{BTreeSet, HashSet}; +use std::collections::hash_map::{Entry, HashMap}; use std::fs; use std::path::{Path, PathBuf}; use std::str; @@ -597,12 +598,10 @@ pub fn build_map<'b, 'cfg>(cx: &mut Context<'b, 'cfg>, units: &[Unit<'b>]) -> Ca } } - let prev = out.entry(*unit).or_insert_with(BuildScripts::default); - for (pkg, kind) in ret.to_link { - add_to_link(prev, &pkg, kind); + match out.entry(*unit) { + Entry::Vacant(entry) => Ok(entry.insert(ret)), + Entry::Occupied(_) => panic!("cyclic dependencies in `build_map`"), } - prev.plugins.extend(ret.plugins); - Ok(prev) } // When adding an entry to 'to_link' we only actually push it on if the -- 2.30.2