Skip to content

Commit d1b55ad

Browse files
committed
Auto merge of #6962 - Eh2406:pub-dep-prop-tests, r=alexcrichton
add public & private prop tests. This is the code that checks that the resolver does not output a public & private conflict. We still do not have the gen of public dependencies do to 9b8b12c, because backtracking is to inefficient, but this checks that we are getting a correct answer. This was supposed to be in #6653, but was lost in the edits of history. Reconstructed from Eh2406@5522aba
2 parents e7b3b67 + a02f6a1 commit d1b55ad

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/testsuite/support/resolver.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cmp::PartialEq;
22
use std::cmp::{max, min};
3-
use std::collections::{BTreeMap, HashSet};
3+
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
44
use std::fmt;
55
use std::time::Instant;
66

@@ -54,6 +54,34 @@ pub fn resolve_and_validated(
5454
}
5555
let out = resolve.sort();
5656
assert_eq!(out.len(), used.len());
57+
58+
let mut pub_deps: HashMap<PackageId, HashSet<_>> = HashMap::new();
59+
for &p in out.iter() {
60+
// make the list of `p` public dependencies
61+
let mut self_pub_dep = HashSet::new();
62+
self_pub_dep.insert(p);
63+
for (dp, deps) in resolve.deps(p) {
64+
if deps.iter().any(|d| d.is_public()) {
65+
self_pub_dep.extend(pub_deps[&dp].iter().cloned())
66+
}
67+
}
68+
pub_deps.insert(p, self_pub_dep);
69+
70+
// check if `p` has a public dependencies conflicts
71+
let seen_dep: BTreeSet<_> = resolve
72+
.deps(p)
73+
.flat_map(|(dp, _)| pub_deps[&dp].iter().cloned())
74+
.collect();
75+
let seen_dep: Vec<_> = seen_dep.iter().collect();
76+
for a in seen_dep.windows(2) {
77+
if a[0].name() == a[1].name() {
78+
panic!(
79+
"the package {:?} can publicly see {:?} and {:?}",
80+
p, a[0], a[1]
81+
)
82+
}
83+
}
84+
}
5785
Ok(out)
5886
}
5987

0 commit comments

Comments
 (0)