diff options
| author | bors <bors@rust-lang.org> | 2017-05-02 14:56:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-02 14:56:11 +0000 |
| commit | ed1f26ddda15b2bcf613a257e813e8b02ee14dff (patch) | |
| tree | 4bc9cd842d2113827d984404610e91f183dd62bd /src/librustc_data_structures | |
| parent | 96e2c34286099eea4f51daaadbb82a8fbe99e0f6 (diff) | |
| parent | e0bfd19add662c07eb102818ce579315ddc90094 (diff) | |
| download | rust-ed1f26ddda15b2bcf613a257e813e8b02ee14dff.tar.gz rust-ed1f26ddda15b2bcf613a257e813e8b02ee14dff.zip | |
Auto merge of #41702 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests - Successful merges: #41661, #41662, #41673, #41688, #41692, #41693 - Failed merges:
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/indexed_vec.rs | 2 | ||||
| -rw-r--r-- | src/librustc_data_structures/transitive_relation.rs | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/librustc_data_structures/indexed_vec.rs b/src/librustc_data_structures/indexed_vec.rs index 62c430dda32..0642ddc7162 100644 --- a/src/librustc_data_structures/indexed_vec.rs +++ b/src/librustc_data_structures/indexed_vec.rs @@ -24,7 +24,7 @@ use rustc_serialize as serialize; /// /// (purpose: avoid mixing indexes for different bitvector domains.) pub trait Idx: Copy + 'static + Eq + Debug { - fn new(usize) -> Self; + fn new(idx: usize) -> Self; fn index(self) -> usize; } diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index 2631108aeb5..b0fca5c0ff3 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -80,6 +80,27 @@ impl<T: Debug + PartialEq> TransitiveRelation<T> { } } + /// Applies the (partial) function to each edge and returns a new + /// relation. If `f` returns `None` for any end-point, returns + /// `None`. + pub fn maybe_map<F, U>(&self, mut f: F) -> Option<TransitiveRelation<U>> + where F: FnMut(&T) -> Option<U>, + U: Debug + PartialEq, + { + let mut result = TransitiveRelation::new(); + for edge in &self.edges { + let r = f(&self.elements[edge.source.0]).and_then(|source| { + f(&self.elements[edge.target.0]).and_then(|target| { + Some(result.add(source, target)) + }) + }); + if r.is_none() { + return None; + } + } + Some(result) + } + /// Indicate that `a < b` (where `<` is this relation) pub fn add(&mut self, a: T, b: T) { let a = self.add_index(a); |
