From 61600f68fa7124987692488870a4893cef6b45c5 Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Sun, 7 Jul 2019 16:50:46 -0700 Subject: [PATCH 1/6] Delegate Iterator::try_fold for Iterators taken by reference --- src/libcore/iter/traits/iterator.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index 7e941267ce824..d97610ff20c1f 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -2708,4 +2708,9 @@ impl Iterator for &mut I { fn nth(&mut self, n: usize) -> Option { (**self).nth(n) } + fn try_fold(&mut self, init: B, mut f: F) -> R where + I: Sized, F: FnMut(B, Self::Item) -> R, R: Try + { + (**self).try_fold(init, f) + } } From de20f53ebbc2e65c8aac3d52fd4073c32f27d778 Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Thu, 11 Jul 2019 19:48:51 -0700 Subject: [PATCH 2/6] Implement `Iterator` for `&mut I` where `I: Iterator + Sized`. --- src/libcore/iter/traits/iterator.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index d97610ff20c1f..2446492a1fe63 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -2708,6 +2708,16 @@ impl Iterator for &mut I { fn nth(&mut self, n: usize) -> Option { (**self).nth(n) } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Iterator for &mut I { + type Item = I::Item; + fn next(&mut self) -> Option { (**self).next() } + fn size_hint(&self) -> (usize, Option) { (**self).size_hint() } + fn nth(&mut self, n: usize) -> Option { + (**self).nth(n) + } fn try_fold(&mut self, init: B, mut f: F) -> R where I: Sized, F: FnMut(B, Self::Item) -> R, R: Try { From e55034b8ce36fca87ff8cf492c56c0fe58a8f431 Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Thu, 11 Jul 2019 19:52:38 -0700 Subject: [PATCH 3/6] Remove redundant sized clause --- src/libcore/iter/traits/iterator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index 2446492a1fe63..2a9a9225a8591 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -2719,7 +2719,7 @@ impl Iterator for &mut I { (**self).nth(n) } fn try_fold(&mut self, init: B, mut f: F) -> R where - I: Sized, F: FnMut(B, Self::Item) -> R, R: Try + F: FnMut(B, Self::Item) -> R, R: Try { (**self).try_fold(init, f) } From 5a8aae5b1e660ec63abc34d783709cf8f672114b Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Fri, 12 Jul 2019 19:59:34 -0700 Subject: [PATCH 4/6] Add default keyword --- src/libcore/iter/traits/iterator.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index 2a9a9225a8591..99827c5de7f14 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -2703,16 +2703,15 @@ fn select_fold1(mut it: I, mut f: F) -> Option #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for &mut I { type Item = I::Item; - fn next(&mut self) -> Option { (**self).next() } - fn size_hint(&self) -> (usize, Option) { (**self).size_hint() } - fn nth(&mut self, n: usize) -> Option { + default fn next(&mut self) -> Option { (**self).next() } + default fn size_hint(&self) -> (usize, Option) { (**self).size_hint() } + default fn nth(&mut self, n: usize) -> Option { (**self).nth(n) } } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for &mut I { - type Item = I::Item; +impl Iterator for &mut I { fn next(&mut self) -> Option { (**self).next() } fn size_hint(&self) -> (usize, Option) { (**self).size_hint() } fn nth(&mut self, n: usize) -> Option { From 7adff53861f59b4add29d1c0fdb4491c94c50e3f Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Fri, 12 Jul 2019 20:23:37 -0700 Subject: [PATCH 5/6] Remove extra mut --- src/libcore/iter/traits/iterator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index 99827c5de7f14..4bfebf107ef10 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -2717,7 +2717,7 @@ impl Iterator for &mut I { fn nth(&mut self, n: usize) -> Option { (**self).nth(n) } - fn try_fold(&mut self, init: B, mut f: F) -> R where + fn try_fold(&mut self, init: B, f: F) -> R where F: FnMut(B, Self::Item) -> R, R: Try { (**self).try_fold(init, f) From 0ecda3d0e3777cc65ad4a2c9c45b583d45cd5f8d Mon Sep 17 00:00:00 2001 From: Czipperz Date: Thu, 25 Jul 2019 23:32:30 -0700 Subject: [PATCH 6/6] Fix ui tests --- src/test/ui/issues/issue-31173.stderr | 1 - src/test/ui/methods/method-call-err-msg.stderr | 2 -- src/test/ui/mismatched_types/issue-36053-2.stderr | 1 - 3 files changed, 4 deletions(-) diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index 3ca8338882681..239c3da83d127 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -14,7 +14,6 @@ LL | .collect(); | ^^^^^^^ | = note: the method `collect` exists but the following trait bounds were not satisfied: - `&mut std::iter::Cloned, [closure@$DIR/issue-31173.rs:6:39: 9:6 found_e:_]>> : std::iter::Iterator` `std::iter::Cloned, [closure@$DIR/issue-31173.rs:6:39: 9:6 found_e:_]>> : std::iter::Iterator` error: aborting due to 2 previous errors diff --git a/src/test/ui/methods/method-call-err-msg.stderr b/src/test/ui/methods/method-call-err-msg.stderr index b8ae4c34dc155..26fbae7ec3e16 100644 --- a/src/test/ui/methods/method-call-err-msg.stderr +++ b/src/test/ui/methods/method-call-err-msg.stderr @@ -34,8 +34,6 @@ LL | pub struct Foo; LL | .take() | ^^^^ | - = note: the method `take` exists but the following trait bounds were not satisfied: - `&mut Foo : std::iter::Iterator` = help: items from traits can only be used if the trait is implemented and in scope = note: the following traits define an item `take`, perhaps you need to implement one of them: candidate #1: `std::io::Read` diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index 3f87ef74b8ea3..6e136037c02e5 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -5,7 +5,6 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); | ^^^^^ | = note: the method `count` exists but the following trait bounds were not satisfied: - `&mut std::iter::Filter>, [closure@$DIR/issue-36053-2.rs:7:39: 7:53]> : std::iter::Iterator` `std::iter::Filter>, [closure@$DIR/issue-36053-2.rs:7:39: 7:53]> : std::iter::Iterator` error[E0631]: type mismatch in closure arguments