diff --git a/doc/po/tutorial-container.md.pot b/doc/po/tutorial-container.md.pot index 3435a51dbeff1..9c56b93f80b51 100644 --- a/doc/po/tutorial-container.md.pot +++ b/doc/po/tutorial-container.md.pot @@ -483,8 +483,8 @@ msgstr "" #, no-wrap msgid "" "~~~\n" -"impl> FromIterator for ~[A] {\n" -" pub fn from_iterator(iterator: &mut T) -> ~[A] {\n" +"impl FromIterator for ~[A] {\n" +" pub fn from_iterator>(iterator: &mut T) -> ~[A] {\n" " let (lower, _) = iterator.size_hint();\n" " let mut xs = with_capacity(lower);\n" " for x in iterator {\n" diff --git a/doc/tutorial-container.md b/doc/tutorial-container.md index 19cd58bd3b403..8d0e8e200d092 100644 --- a/doc/tutorial-container.md +++ b/doc/tutorial-container.md @@ -224,8 +224,8 @@ implementing the `FromIterator` trait. For example, the implementation for vectors is as follows: ~~~ -impl> FromIterator for ~[A] { - pub fn from_iterator(iterator: &mut T) -> ~[A] { +impl FromIterator for ~[A] { + pub fn from_iterator>(iterator: &mut T) -> ~[A] { let (lower, _) = iterator.size_hint(); let mut xs = with_capacity(lower); for x in iterator { diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 788ed726d0fc0..076e86dd5b040 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -573,16 +573,16 @@ impl DoubleEndedIterator for MoveIterator { fn next_back(&mut self) -> Option { self.list.pop_back() } } -impl> FromIterator for DList { - fn from_iterator(iterator: &mut T) -> DList { +impl FromIterator for DList { + fn from_iterator>(iterator: &mut T) -> DList { let mut ret = DList::new(); ret.extend(iterator); ret } } -impl> Extendable for DList { - fn extend(&mut self, iterator: &mut T) { +impl Extendable for DList { + fn extend>(&mut self, iterator: &mut T) { for elt in *iterator { self.push_back(elt); } } } @@ -1163,4 +1163,3 @@ mod tests { } } } - diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index 4b94219b30d53..4f0fed5fccf47 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -190,8 +190,8 @@ impl<'self, T> Iterator<&'self T> for PriorityQueueIterator<'self, T> { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -impl> FromIterator for PriorityQueue { - fn from_iterator(iter: &mut Iter) -> PriorityQueue { +impl FromIterator for PriorityQueue { + fn from_iterator>(iter: &mut Iter) -> PriorityQueue { let mut q = PriorityQueue::new(); q.extend(iter); @@ -199,8 +199,8 @@ impl> FromIterator for PriorityQueue { } } -impl> Extendable for PriorityQueue { - fn extend(&mut self, iter: &mut Iter) { +impl Extendable for PriorityQueue { + fn extend>(&mut self, iter: &mut Iter) { let (lower, _) = iter.size_hint(); let len = self.capacity(); diff --git a/src/libextra/ringbuf.rs b/src/libextra/ringbuf.rs index bb9ac74bc77ac..a38cb580c5057 100644 --- a/src/libextra/ringbuf.rs +++ b/src/libextra/ringbuf.rs @@ -322,8 +322,8 @@ impl Eq for RingBuf { } } -impl> FromIterator for RingBuf { - fn from_iterator(iterator: &mut T) -> RingBuf { +impl FromIterator for RingBuf { + fn from_iterator>(iterator: &mut T) -> RingBuf { let (lower, _) = iterator.size_hint(); let mut deq = RingBuf::with_capacity(lower); deq.extend(iterator); @@ -331,8 +331,8 @@ impl> FromIterator for RingBuf { } } -impl> Extendable for RingBuf { - fn extend(&mut self, iterator: &mut T) { +impl Extendable for RingBuf { + fn extend>(&mut self, iterator: &mut T) { for elt in *iterator { self.push_back(elt); } diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 486a7dab5c1bb..118754ec02830 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -835,34 +835,34 @@ fn remove(node: &mut Option<~TreeNode>, }; } -impl> FromIterator<(K, V), T> for TreeMap { - fn from_iterator(iter: &mut T) -> TreeMap { +impl FromIterator<(K, V)> for TreeMap { + fn from_iterator>(iter: &mut T) -> TreeMap { let mut map = TreeMap::new(); map.extend(iter); map } } -impl> Extendable<(K, V), T> for TreeMap { +impl Extendable<(K, V)> for TreeMap { #[inline] - fn extend(&mut self, iter: &mut T) { + fn extend>(&mut self, iter: &mut T) { for (k, v) in *iter { self.insert(k, v); } } } -impl> FromIterator for TreeSet { - fn from_iterator(iter: &mut Iter) -> TreeSet { +impl FromIterator for TreeSet { + fn from_iterator>(iter: &mut Iter) -> TreeSet { let mut set = TreeSet::new(); set.extend(iter); set } } -impl> Extendable for TreeSet { +impl Extendable for TreeSet { #[inline] - fn extend(&mut self, iter: &mut Iter) { + fn extend>(&mut self, iter: &mut Iter) { for elem in *iter { self.insert(elem); } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 37f45142a1107..9719460bbd33e 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -879,7 +879,9 @@ pub fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, let check_move: &fn(@pat, Option<@pat>) = |p, sub| { // check legality of moving out of the enum - if sub.is_some() { + + // x @ Foo(*) is legal, but x @ Foo(y) isn't. + if sub.map_move_default(false, |p| pat_contains_bindings(def_map, p)) { tcx.sess.span_err( p.span, "cannot bind by-move with sub-bindings"); diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 9bf14697d9ad7..a67a488ef30fc 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -88,3 +88,18 @@ pub fn pat_binding_ids(dm: resolve::DefMap, pat: @pat) -> ~[NodeId] { pat_bindings(dm, pat, |_bm, b_id, _sp, _pt| found.push(b_id) ); return found; } + +/// Checks if the pattern contains any patterns that bind something to +/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(*)`. +pub fn pat_contains_bindings(dm: resolve::DefMap, pat: @pat) -> bool { + let mut contains_bindings = false; + do walk_pat(pat) |p| { + if pat_is_binding(dm, p) { + contains_bindings = true; + false // there's at least one binding, can short circuit now. + } else { + true + } + }; + contains_bindings +} diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 201d469269465..50e59cf438d0c 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -605,8 +605,8 @@ impl Iterator for HashSetMoveIterator { } } -impl> FromIterator<(K, V), T> for HashMap { - fn from_iterator(iter: &mut T) -> HashMap { +impl FromIterator<(K, V)> for HashMap { + fn from_iterator>(iter: &mut T) -> HashMap { let (lower, _) = iter.size_hint(); let mut map = HashMap::with_capacity(lower); map.extend(iter); @@ -614,8 +614,8 @@ impl> FromIterator<(K, V), T> for HashMap> Extendable<(K, V), T> for HashMap { - fn extend(&mut self, iter: &mut T) { +impl Extendable<(K, V)> for HashMap { + fn extend>(&mut self, iter: &mut T) { for (k, v) in *iter { self.insert(k, v); } @@ -753,8 +753,8 @@ impl Clone for HashSet { } } -impl> FromIterator for HashSet { - fn from_iterator(iter: &mut T) -> HashSet { +impl FromIterator for HashSet { + fn from_iterator>(iter: &mut T) -> HashSet { let (lower, _) = iter.size_hint(); let mut set = HashSet::with_capacity(lower); set.extend(iter); @@ -762,8 +762,8 @@ impl> FromIterator for HashSet { } } -impl> Extendable for HashSet { - fn extend(&mut self, iter: &mut T) { +impl Extendable for HashSet { + fn extend>(&mut self, iter: &mut T) { for k in *iter { self.insert(k); } diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index bd89c271a36b0..1a5e364542b3e 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -26,15 +26,15 @@ use clone::Clone; use uint; /// Conversion from an `Iterator` -pub trait FromIterator> { +pub trait FromIterator { /// Build a container with elements from an external iterator. - fn from_iterator(iterator: &mut T) -> Self; + fn from_iterator>(iterator: &mut T) -> Self; } /// A type growable from an `Iterator` implementation -pub trait Extendable>: FromIterator { +pub trait Extendable: FromIterator { /// Extend a container with the elements yielded by an iterator - fn extend(&mut self, iterator: &mut T); + fn extend>(&mut self, iterator: &mut T); } /// An interface for dealing with "external iterators". These types of iterators @@ -353,7 +353,7 @@ pub trait Iterator { /// assert!(a == b); /// ~~~ #[inline] - fn collect>(&mut self) -> B { + fn collect>(&mut self) -> B { FromIterator::from_iterator(self) } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index b8e6153694121..bc9d427676c31 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -2111,9 +2111,9 @@ impl Clone for @str { } } -impl> FromIterator for ~str { +impl FromIterator for ~str { #[inline] - fn from_iterator(iterator: &mut T) -> ~str { + fn from_iterator>(iterator: &mut T) -> ~str { let (lower, _) = iterator.size_hint(); let mut buf = with_capacity(lower); buf.extend(iterator); @@ -2121,9 +2121,9 @@ impl> FromIterator for ~str { } } -impl> Extendable for ~str { +impl Extendable for ~str { #[inline] - fn extend(&mut self, iterator: &mut T) { + fn extend>(&mut self, iterator: &mut T) { let (lower, _) = iterator.size_hint(); let reserve = lower + self.len(); self.reserve_at_least(reserve); diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index da1fb9abaeeb6..f5c7b719c4f19 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -205,16 +205,16 @@ impl TrieMap { } } -impl> FromIterator<(uint, T), Iter> for TrieMap { - fn from_iterator(iter: &mut Iter) -> TrieMap { +impl FromIterator<(uint, T)> for TrieMap { + fn from_iterator>(iter: &mut Iter) -> TrieMap { let mut map = TrieMap::new(); map.extend(iter); map } } -impl> Extendable<(uint, T), Iter> for TrieMap { - fn extend(&mut self, iter: &mut Iter) { +impl Extendable<(uint, T)> for TrieMap { + fn extend>(&mut self, iter: &mut Iter) { for (k, v) in *iter { self.insert(k, v); } @@ -294,16 +294,16 @@ impl TrieSet { } } -impl> FromIterator for TrieSet { - fn from_iterator(iter: &mut Iter) -> TrieSet { +impl FromIterator for TrieSet { + fn from_iterator>(iter: &mut Iter) -> TrieSet { let mut set = TrieSet::new(); set.extend(iter); set } } -impl> Extendable for TrieSet { - fn extend(&mut self, iter: &mut Iter) { +impl Extendable for TrieSet { + fn extend>(&mut self, iter: &mut Iter) { for elem in *iter { self.insert(elem); } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 27e09d8547989..1996a9f970de4 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2316,8 +2316,8 @@ impl Iterator for MoveRevIterator { } } -impl> FromIterator for ~[A] { - fn from_iterator(iterator: &mut T) -> ~[A] { +impl FromIterator for ~[A] { + fn from_iterator>(iterator: &mut T) -> ~[A] { let (lower, _) = iterator.size_hint(); let mut xs = with_capacity(lower); for x in *iterator { @@ -2327,8 +2327,8 @@ impl> FromIterator for ~[A] { } } -impl> Extendable for ~[A] { - fn extend(&mut self, iterator: &mut T) { +impl Extendable for ~[A] { + fn extend>(&mut self, iterator: &mut T) { let (lower, _) = iterator.size_hint(); let len = self.len(); self.reserve(len + lower);