From 3a6a29b4ecfdb7f641ca699fcd66a09b4baaae6a Mon Sep 17 00:00:00 2001 From: Ilija Tovilo <ilija.tovilo@me.com> Date: Wed, 31 Jul 2019 21:00:35 +0200 Subject: [PATCH 1/3] Use associated_type_bounds where applicable - closes #61738 --- src/liballoc/borrow.rs | 12 +- src/liballoc/lib.rs | 1 + src/liballoc/tests/str.rs | 10 +- src/libcore/convert.rs | 4 +- src/libcore/future/future.rs | 3 +- src/libcore/iter/adapters/flatten.rs | 61 +++++---- src/libcore/iter/traits/collect.rs | 4 +- src/libcore/lib.rs | 1 + src/libcore/pin.rs | 10 +- src/libcore/str/mod.rs | 116 +++++++++++------- src/librustc/lib.rs | 1 + src/librustc/traits/select.rs | 2 +- src/librustc/traits/structural_impls.rs | 6 +- src/librustc/ty/context.rs | 4 +- src/librustc/ty/layout.rs | 6 +- src/librustc/ty/query/on_disk_cache.rs | 3 +- src/librustc_codegen_ssa/back/command.rs | 4 +- src/librustc_codegen_ssa/lib.rs | 1 + src/librustc_data_structures/lib.rs | 1 + .../owning_ref/mod.rs | 8 +- src/librustc_mir/dataflow/mod.rs | 11 +- src/librustc_mir/lib.rs | 1 + src/libserialize/collection_impls.rs | 10 +- src/libserialize/lib.rs | 1 + src/libstd/sys/sgx/abi/usercalls/alloc.rs | 12 +- 25 files changed, 169 insertions(+), 124 deletions(-) diff --git a/src/liballoc/borrow.rs b/src/liballoc/borrow.rs index d5e15b3719c2..a9c5bce4c25f 100644 --- a/src/liballoc/borrow.rs +++ b/src/liballoc/borrow.rs @@ -329,8 +329,8 @@ impl<'a, B: ?Sized> PartialOrd for Cow<'a, B> #[stable(feature = "rust1", since = "1.0.0")] impl<B: ?Sized> fmt::Debug for Cow<'_, B> - where B: fmt::Debug + ToOwned, - <B as ToOwned>::Owned: fmt::Debug +where + B: fmt::Debug + ToOwned<Owned: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -342,8 +342,8 @@ impl<B: ?Sized> fmt::Debug for Cow<'_, B> #[stable(feature = "rust1", since = "1.0.0")] impl<B: ?Sized> fmt::Display for Cow<'_, B> - where B: fmt::Display + ToOwned, - <B as ToOwned>::Owned: fmt::Display +where + B: fmt::Display + ToOwned<Owned: fmt::Display>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -355,8 +355,8 @@ impl<B: ?Sized> fmt::Display for Cow<'_, B> #[stable(feature = "default", since = "1.11.0")] impl<B: ?Sized> Default for Cow<'_, B> - where B: ToOwned, - <B as ToOwned>::Owned: Default +where + B: ToOwned<Owned: Default>, { /// Creates an owned Cow<'a, B> with the default value for the contained owned value. fn default() -> Self { diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index deea74daa52d..a1936b36ac6b 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -122,6 +122,7 @@ #![feature(alloc_layout_extra)] #![feature(try_trait)] #![feature(mem_take)] +#![feature(associated_type_bounds)] // Allow testing this library diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index c5198ca39fed..4332b2e90fda 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -1638,10 +1638,12 @@ mod pattern { } } - fn cmp_search_to_vec<'a, P: Pattern<'a>>(rev: bool, pat: P, haystack: &'a str, - right: Vec<SearchStep>) - where P::Searcher: ReverseSearcher<'a> - { + fn cmp_search_to_vec<'a>( + rev: bool, + pat: impl Pattern<'a, Searcher: ReverseSearcher<'a>>, + haystack: &'a str, + right: Vec<SearchStep> + ) { let mut searcher = pat.into_searcher(haystack); let mut v = vec![]; loop { diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 624b13d96472..641621f492ba 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -513,7 +513,7 @@ impl<T: ?Sized, U: ?Sized> AsRef<U> for &mut T where T: AsRef<U> // FIXME (#45742): replace the above impls for &/&mut with the following more general one: // // As lifts over Deref -// impl<D: ?Sized + Deref, U: ?Sized> AsRef<U> for D where D::Target: AsRef<U> { +// impl<D: ?Sized + Deref<Target: AsRef<U>>, U: ?Sized> AsRef<U> for D { // fn as_ref(&self) -> &U { // self.deref().as_ref() // } @@ -530,7 +530,7 @@ impl<T: ?Sized, U: ?Sized> AsMut<U> for &mut T where T: AsMut<U> // FIXME (#45742): replace the above impl for &mut with the following more general one: // // AsMut lifts over DerefMut -// impl<D: ?Sized + Deref, U: ?Sized> AsMut<U> for D where D::Target: AsMut<U> { +// impl<D: ?Sized + Deref<Target: AsMut<U>>, U: ?Sized> AsMut<U> for D { // fn as_mut(&mut self) -> &mut U { // self.deref_mut().as_mut() // } diff --git a/src/libcore/future/future.rs b/src/libcore/future/future.rs index 593c01060ca4..f14ed38b9b0f 100644 --- a/src/libcore/future/future.rs +++ b/src/libcore/future/future.rs @@ -111,8 +111,7 @@ impl<F: ?Sized + Future + Unpin> Future for &mut F { #[stable(feature = "futures_api", since = "1.36.0")] impl<P> Future for Pin<P> where - P: Unpin + ops::DerefMut, - P::Target: Future, + P: Unpin + ops::DerefMut<Target: Future>, { type Output = <<P as ops::Deref>::Target as Future>::Output; diff --git a/src/libcore/iter/adapters/flatten.rs b/src/libcore/iter/adapters/flatten.rs index 8c2aae477bf2..d8d41a2a31ef 100644 --- a/src/libcore/iter/adapters/flatten.rs +++ b/src/libcore/iter/adapters/flatten.rs @@ -24,15 +24,17 @@ impl<I: Iterator, U: IntoIterator, F: FnMut(I::Item) -> U> FlatMap<I, U, F> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<I: Clone, U: Clone + IntoIterator, F: Clone> Clone for FlatMap<I, U, F> - where <U as IntoIterator>::IntoIter: Clone +impl<I: Clone, U, F: Clone> Clone for FlatMap<I, U, F> +where + U: Clone + IntoIterator<IntoIter: Clone>, { fn clone(&self) -> Self { FlatMap { inner: self.inner.clone() } } } #[stable(feature = "core_impl_debug", since = "1.9.0")] -impl<I: fmt::Debug, U: IntoIterator, F> fmt::Debug for FlatMap<I, U, F> - where U::IntoIter: fmt::Debug +impl<I: fmt::Debug, U, F> fmt::Debug for FlatMap<I, U, F> +where + U: IntoIterator<IntoIter: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("FlatMap").field("inner", &self.inner).finish() @@ -68,9 +70,10 @@ impl<I: Iterator, U: IntoIterator, F> Iterator for FlatMap<I, U, F> #[stable(feature = "rust1", since = "1.0.0")] impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F> - where F: FnMut(I::Item) -> U, - U: IntoIterator, - U::IntoIter: DoubleEndedIterator +where + F: FnMut(I::Item) -> U, + U: IntoIterator, + U::IntoIter: DoubleEndedIterator, { #[inline] fn next_back(&mut self) -> Option<U::Item> { self.inner.next_back() } @@ -105,11 +108,13 @@ impl<I, U, F> FusedIterator for FlatMap<I, U, F> #[must_use = "iterators are lazy and do nothing unless consumed"] #[stable(feature = "iterator_flatten", since = "1.29.0")] pub struct Flatten<I: Iterator> -where I::Item: IntoIterator { +where + I::Item: IntoIterator, +{ inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>, } -impl<I: Iterator> Flatten<I> -where I::Item: IntoIterator { + +impl<I: Iterator<Item: IntoIterator>> Flatten<I> { pub(in super::super) fn new(iter: I) -> Flatten<I> { Flatten { inner: FlattenCompat::new(iter) } } @@ -117,8 +122,9 @@ where I::Item: IntoIterator { #[stable(feature = "iterator_flatten", since = "1.29.0")] impl<I, U> fmt::Debug for Flatten<I> - where I: Iterator + fmt::Debug, U: Iterator + fmt::Debug, - I::Item: IntoIterator<IntoIter = U, Item = U::Item>, +where + I: fmt::Debug + Iterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>, + U: fmt::Debug + Iterator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Flatten").field("inner", &self.inner).finish() @@ -127,16 +133,18 @@ impl<I, U> fmt::Debug for Flatten<I> #[stable(feature = "iterator_flatten", since = "1.29.0")] impl<I, U> Clone for Flatten<I> - where I: Iterator + Clone, U: Iterator + Clone, - I::Item: IntoIterator<IntoIter = U, Item = U::Item>, +where + I: Clone + Iterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>, + U: Clone + Iterator, { fn clone(&self) -> Self { Flatten { inner: self.inner.clone() } } } #[stable(feature = "iterator_flatten", since = "1.29.0")] impl<I, U> Iterator for Flatten<I> - where I: Iterator, U: Iterator, - I::Item: IntoIterator<IntoIter = U, Item = U::Item> +where + I: Iterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>, + U: Iterator, { type Item = U::Item; @@ -163,8 +171,9 @@ impl<I, U> Iterator for Flatten<I> #[stable(feature = "iterator_flatten", since = "1.29.0")] impl<I, U> DoubleEndedIterator for Flatten<I> - where I: DoubleEndedIterator, U: DoubleEndedIterator, - I::Item: IntoIterator<IntoIter = U, Item = U::Item> +where + I: DoubleEndedIterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>, + U: DoubleEndedIterator, { #[inline] fn next_back(&mut self) -> Option<U::Item> { self.inner.next_back() } @@ -186,8 +195,10 @@ impl<I, U> DoubleEndedIterator for Flatten<I> #[stable(feature = "iterator_flatten", since = "1.29.0")] impl<I, U> FusedIterator for Flatten<I> - where I: FusedIterator, U: Iterator, - I::Item: IntoIterator<IntoIter = U, Item = U::Item> {} +where + I: FusedIterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>, + U: Iterator, +{} /// Real logic of both `Flatten` and `FlatMap` which simply delegate to /// this type. @@ -205,8 +216,9 @@ impl<I, U> FlattenCompat<I, U> { } impl<I, U> Iterator for FlattenCompat<I, U> - where I: Iterator, U: Iterator, - I::Item: IntoIterator<IntoIter = U, Item = U::Item> +where + I: Iterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>, + U: Iterator, { type Item = U::Item; @@ -274,8 +286,9 @@ impl<I, U> Iterator for FlattenCompat<I, U> } impl<I, U> DoubleEndedIterator for FlattenCompat<I, U> - where I: DoubleEndedIterator, U: DoubleEndedIterator, - I::Item: IntoIterator<IntoIter = U, Item = U::Item> +where + I: DoubleEndedIterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>, + U: DoubleEndedIterator, { #[inline] fn next_back(&mut self) -> Option<U::Item> { diff --git a/src/libcore/iter/traits/collect.rs b/src/libcore/iter/traits/collect.rs index 1865160bc3cf..9f15de33425f 100644 --- a/src/libcore/iter/traits/collect.rs +++ b/src/libcore/iter/traits/collect.rs @@ -195,8 +195,8 @@ pub trait FromIterator<A>: Sized { /// /// ```rust /// fn collect_as_strings<T>(collection: T) -> Vec<String> -/// where T: IntoIterator, -/// T::Item: std::fmt::Debug, +/// where +/// T: IntoIterator<Item: std::fmt::Debug>, /// { /// collection /// .into_iter() diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 4d627383fd7c..678ff7687921 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -132,6 +132,7 @@ #![feature(maybe_uninit_slice, maybe_uninit_array)] #![feature(external_doc)] #![feature(mem_take)] +#![feature(associated_type_bounds)] #[prelude_import] #[allow(unused)] diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index 88a56174629f..243209d022b4 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -439,10 +439,7 @@ where } } -impl<P: Deref> Pin<P> -where - P::Target: Unpin, -{ +impl<P: Deref<Target: Unpin>> Pin<P> { /// Construct a new `Pin<P>` around a pointer to some data of a type that /// implements [`Unpin`]. /// @@ -730,10 +727,7 @@ impl<P: Deref> Deref for Pin<P> { } #[stable(feature = "pin", since = "1.33.0")] -impl<P: DerefMut> DerefMut for Pin<P> -where - P::Target: Unpin -{ +impl<P: DerefMut<Target: Unpin>> DerefMut for Pin<P> { fn deref_mut(&mut self) -> &mut P::Target { Pin::get_mut(Pin::as_mut(self)) } diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4faf9ff4d2ee..f20cb7bfbc3b 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -851,8 +851,9 @@ unsafe impl TrustedRandomAccess for Bytes<'_> { /// wrapper types of the form X<'a, P> macro_rules! derive_pattern_clone { (clone $t:ident with |$s:ident| $e:expr) => { - impl<'a, P: Pattern<'a>> Clone for $t<'a, P> - where P::Searcher: Clone + impl<'a, P> Clone for $t<'a, P> + where + P: Pattern<'a, Searcher: Clone>, { fn clone(&self) -> Self { let $s = self; @@ -928,8 +929,9 @@ macro_rules! generate_pattern_iterators { pub struct $forward_iterator<'a, P: Pattern<'a>>($internal_iterator<'a, P>); $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> fmt::Debug for $forward_iterator<'a, P> - where P::Searcher: fmt::Debug + impl<'a, P> fmt::Debug for $forward_iterator<'a, P> + where + P: Pattern<'a, Searcher: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple(stringify!($forward_iterator)) @@ -949,8 +951,9 @@ macro_rules! generate_pattern_iterators { } $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> Clone for $forward_iterator<'a, P> - where P::Searcher: Clone + impl<'a, P> Clone for $forward_iterator<'a, P> + where + P: Pattern<'a, Searcher: Clone>, { fn clone(&self) -> Self { $forward_iterator(self.0.clone()) @@ -962,8 +965,9 @@ macro_rules! generate_pattern_iterators { pub struct $reverse_iterator<'a, P: Pattern<'a>>($internal_iterator<'a, P>); $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> fmt::Debug for $reverse_iterator<'a, P> - where P::Searcher: fmt::Debug + impl<'a, P> fmt::Debug for $reverse_iterator<'a, P> + where + P: Pattern<'a, Searcher: fmt::Debug>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple(stringify!($reverse_iterator)) @@ -973,8 +977,9 @@ macro_rules! generate_pattern_iterators { } $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> Iterator for $reverse_iterator<'a, P> - where P::Searcher: ReverseSearcher<'a> + impl<'a, P> Iterator for $reverse_iterator<'a, P> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { type Item = $iterty; @@ -985,8 +990,9 @@ macro_rules! generate_pattern_iterators { } $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> Clone for $reverse_iterator<'a, P> - where P::Searcher: Clone + impl<'a, P> Clone for $reverse_iterator<'a, P> + where + P: Pattern<'a, Searcher: Clone>, { fn clone(&self) -> Self { $reverse_iterator(self.0.clone()) @@ -997,8 +1003,10 @@ macro_rules! generate_pattern_iterators { impl<'a, P: Pattern<'a>> FusedIterator for $forward_iterator<'a, P> {} #[stable(feature = "fused", since = "1.26.0")] - impl<'a, P: Pattern<'a>> FusedIterator for $reverse_iterator<'a, P> - where P::Searcher: ReverseSearcher<'a> {} + impl<'a, P> FusedIterator for $reverse_iterator<'a, P> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, + {} generate_pattern_iterators!($($t)* with $(#[$common_stability_attribute])*, $forward_iterator, @@ -1010,8 +1018,9 @@ macro_rules! generate_pattern_iterators { $reverse_iterator:ident, $iterty:ty } => { $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> DoubleEndedIterator for $forward_iterator<'a, P> - where P::Searcher: DoubleEndedSearcher<'a> + impl<'a, P> DoubleEndedIterator for $forward_iterator<'a, P> + where + P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>, { #[inline] fn next_back(&mut self) -> Option<$iterty> { @@ -1020,8 +1029,9 @@ macro_rules! generate_pattern_iterators { } $(#[$common_stability_attribute])* - impl<'a, P: Pattern<'a>> DoubleEndedIterator for $reverse_iterator<'a, P> - where P::Searcher: DoubleEndedSearcher<'a> + impl<'a, P> DoubleEndedIterator for $reverse_iterator<'a, P> + where + P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>, { #[inline] fn next_back(&mut self) -> Option<$iterty> { @@ -1049,7 +1059,10 @@ struct SplitInternal<'a, P: Pattern<'a>> { finished: bool, } -impl<'a, P: Pattern<'a>> fmt::Debug for SplitInternal<'a, P> where P::Searcher: fmt::Debug { +impl<'a, P> fmt::Debug for SplitInternal<'a, P> +where + P: Pattern<'a, Searcher: fmt::Debug>, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SplitInternal") .field("start", &self.start) @@ -1166,7 +1179,10 @@ struct SplitNInternal<'a, P: Pattern<'a>> { count: usize, } -impl<'a, P: Pattern<'a>> fmt::Debug for SplitNInternal<'a, P> where P::Searcher: fmt::Debug { +impl<'a, P> fmt::Debug for SplitNInternal<'a, P> +where + P: Pattern<'a, Searcher: fmt::Debug>, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SplitNInternal") .field("iter", &self.iter) @@ -1222,7 +1238,10 @@ derive_pattern_clone!{ struct MatchIndicesInternal<'a, P: Pattern<'a>>(P::Searcher); -impl<'a, P: Pattern<'a>> fmt::Debug for MatchIndicesInternal<'a, P> where P::Searcher: fmt::Debug { +impl<'a, P> fmt::Debug for MatchIndicesInternal<'a, P> +where + P: Pattern<'a, Searcher: fmt::Debug>, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("MatchIndicesInternal") .field(&self.0) @@ -1273,7 +1292,10 @@ derive_pattern_clone!{ struct MatchesInternal<'a, P: Pattern<'a>>(P::Searcher); -impl<'a, P: Pattern<'a>> fmt::Debug for MatchesInternal<'a, P> where P::Searcher: fmt::Debug { +impl<'a, P> fmt::Debug for MatchesInternal<'a, P> +where + P: Pattern<'a, Searcher: fmt::Debug>, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("MatchesInternal") .field(&self.0) @@ -2882,8 +2904,9 @@ impl str { /// assert!(!bananas.ends_with("nana")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn ends_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool - where P::Searcher: ReverseSearcher<'a> + pub fn ends_with<'a, P>(&'a self, pat: P) -> bool + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { pat.is_suffix_of(self) } @@ -2975,8 +2998,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rfind<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize> - where P::Searcher: ReverseSearcher<'a> + pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { pat.into_searcher(self).next_match_back().map(|(i, _)| i) } @@ -3142,8 +3166,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rsplit<'a, P: Pattern<'a>>(&'a self, pat: P) -> RSplit<'a, P> - where P::Searcher: ReverseSearcher<'a> + pub fn rsplit<'a, P>(&'a self, pat: P) -> RSplit<'a, P> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { RSplit(self.split(pat).0) } @@ -3233,8 +3258,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rsplit_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> RSplitTerminator<'a, P> - where P::Searcher: ReverseSearcher<'a> + pub fn rsplit_terminator<'a, P>(&'a self, pat: P) -> RSplitTerminator<'a, P> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { RSplitTerminator(self.split_terminator(pat).0) } @@ -3333,8 +3359,9 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn rsplitn<'a, P: Pattern<'a>>(&'a self, n: usize, pat: P) -> RSplitN<'a, P> - where P::Searcher: ReverseSearcher<'a> + pub fn rsplitn<'a, P>(&'a self, n: usize, pat: P) -> RSplitN<'a, P> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { RSplitN(self.splitn(n, pat).0) } @@ -3406,8 +3433,9 @@ impl str { /// ``` #[stable(feature = "str_matches", since = "1.2.0")] #[inline] - pub fn rmatches<'a, P: Pattern<'a>>(&'a self, pat: P) -> RMatches<'a, P> - where P::Searcher: ReverseSearcher<'a> + pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { RMatches(self.matches(pat).0) } @@ -3491,8 +3519,9 @@ impl str { /// ``` #[stable(feature = "str_match_indices", since = "1.5.0")] #[inline] - pub fn rmatch_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> RMatchIndices<'a, P> - where P::Searcher: ReverseSearcher<'a> + pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { RMatchIndices(self.match_indices(pat).0) } @@ -3700,8 +3729,9 @@ impl str { #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "rust1", since = "1.0.0")] - pub fn trim_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str - where P::Searcher: DoubleEndedSearcher<'a> + pub fn trim_matches<'a, P>(&'a self, pat: P) -> &'a str + where + P: Pattern<'a, Searcher: DoubleEndedSearcher<'a>>, { let mut i = 0; let mut j = 0; @@ -3792,8 +3822,9 @@ impl str { #[must_use = "this returns the trimmed string as a new slice, \ without modifying the original"] #[stable(feature = "trim_direction", since = "1.30.0")] - pub fn trim_end_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str - where P::Searcher: ReverseSearcher<'a> + pub fn trim_end_matches<'a, P>(&'a self, pat: P) -> &'a str + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { let mut j = 0; let mut matcher = pat.into_searcher(self); @@ -3880,8 +3911,9 @@ impl str { reason = "superseded by `trim_end_matches`", suggestion = "trim_end_matches", )] - pub fn trim_right_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str - where P::Searcher: ReverseSearcher<'a> + pub fn trim_right_matches<'a, P>(&'a self, pat: P) -> &'a str + where + P: Pattern<'a, Searcher: ReverseSearcher<'a>>, { self.trim_end_matches(pat) } diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 8e0581b41ef7..8d4cd51e4608 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -61,6 +61,7 @@ #![feature(proc_macro_hygiene)] #![feature(log_syntax)] #![feature(mem_take)] +#![feature(associated_type_bounds)] #![recursion_limit="512"] diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index da582c015e4e..d4ae366262cb 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -3901,7 +3901,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // each predicate must be preceded by the obligations required // to normalize it. // for example, if we have: - // impl<U: Iterator, V: Iterator<Item=U>> Foo for V where U::Item: Copy + // impl<U: Iterator<Item: Copy>, V: Iterator<Item = U>> Foo for V // the impl will have the following predicates: // <V as Iterator>::Item = U, // U: Iterator, U: Sized, diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index 129a400d28f4..05b698eb4c4e 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -980,8 +980,7 @@ EnumTypeFoldableImpl! { (chalk_engine::DelayedLiteral::Negative)(a), (chalk_engine::DelayedLiteral::Positive)(a, b), } where - C: chalk_engine::context::Context + Clone, - C::CanonicalConstrainedSubst: TypeFoldable<'tcx>, + C: chalk_engine::context::Context<CanonicalConstrainedSubst: TypeFoldable<'tcx>> + Clone, } EnumTypeFoldableImpl! { @@ -989,8 +988,7 @@ EnumTypeFoldableImpl! { (chalk_engine::Literal::Negative)(a), (chalk_engine::Literal::Positive)(a), } where - C: chalk_engine::context::Context + Clone, - C::GoalInEnvironment: Clone + TypeFoldable<'tcx>, + C: chalk_engine::context::Context<GoalInEnvironment: Clone + TypeFoldable<'tcx>> + Clone, } CloneTypeFoldableAndLiftImpls! { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index dadc126eba48..ef74d9e5b289 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2663,8 +2663,8 @@ impl<'tcx> TyCtxt<'tcx> { unsafety: hir::Unsafety, abi: abi::Abi) -> <I::Item as InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>>::Output - where I: Iterator, - I::Item: InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>> + where + I: Iterator<Item: InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>>, { inputs.chain(iter::once(output)).intern_with(|xs| ty::FnSig { inputs_and_output: self.intern_type_list(xs), diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 1c9a5ad62185..a9d1fd1fffc9 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -2027,9 +2027,9 @@ impl ty::query::TyCtxtAt<'tcx> { impl<'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> where - C: LayoutOf<Ty = Ty<'tcx>> + HasTyCtxt<'tcx>, - C::TyLayout: MaybeResult<TyLayout<'tcx>>, - C: HasParamEnv<'tcx>, + C: LayoutOf<Ty = Ty<'tcx>, TyLayout: MaybeResult<TyLayout<'tcx>>> + + HasTyCtxt<'tcx> + + HasParamEnv<'tcx>, { fn for_variant(this: TyLayout<'tcx>, cx: &C, variant_index: VariantIdx) -> TyLayout<'tcx> { let details = match this.variants { diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 45bc89f5a84a..40bcd028db58 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -1055,9 +1055,8 @@ fn encode_query_results<'a, 'tcx, Q, E>( query_result_index: &mut EncodedQueryResultIndex, ) -> Result<(), E::Error> where - Q: super::config::QueryDescription<'tcx>, + Q: super::config::QueryDescription<'tcx, Value: Encodable>, E: 'a + TyEncoder, - Q::Value: Encodable, { let desc = &format!("encode_query_results for {}", ::std::any::type_name::<Q>()); diff --git a/src/librustc_codegen_ssa/back/command.rs b/src/librustc_codegen_ssa/back/command.rs index d610805b5bbd..340cc772e5f0 100644 --- a/src/librustc_codegen_ssa/back/command.rs +++ b/src/librustc_codegen_ssa/back/command.rs @@ -50,8 +50,8 @@ impl Command { } pub fn args<I>(&mut self, args: I) -> &mut Command - where I: IntoIterator, - I::Item: AsRef<OsStr>, + where + I: IntoIterator<Item: AsRef<OsStr>>, { for arg in args { self._arg(arg.as_ref()); diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index 73ef16e00914..0e3c3a77b28f 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -11,6 +11,7 @@ #![feature(nll)] #![feature(trusted_len)] #![feature(mem_take)] +#![feature(associated_type_bounds)] #![recursion_limit="256"] diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 8fb0ea0271b9..9f103437d368 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -23,6 +23,7 @@ #![feature(core_intrinsics)] #![feature(integer_atomics)] #![feature(test)] +#![feature(associated_type_bounds)] #![cfg_attr(unix, feature(libc))] diff --git a/src/librustc_data_structures/owning_ref/mod.rs b/src/librustc_data_structures/owning_ref/mod.rs index ea9c5283aee7..b835b1706b85 100644 --- a/src/librustc_data_structures/owning_ref/mod.rs +++ b/src/librustc_data_structures/owning_ref/mod.rs @@ -847,7 +847,9 @@ pub trait ToHandleMut { } impl<O, H> OwningHandle<O, H> - where O: StableAddress, O::Target: ToHandle<Handle = H>, H: Deref, +where + O: StableAddress<Target: ToHandle<Handle = H>>, + H: Deref, { /// Creates a new `OwningHandle` for a type that implements `ToHandle`. For types /// that don't implement `ToHandle`, callers may invoke `new_with_fn`, which accepts @@ -858,7 +860,9 @@ impl<O, H> OwningHandle<O, H> } impl<O, H> OwningHandle<O, H> - where O: StableAddress, O::Target: ToHandleMut<HandleMut = H>, H: DerefMut, +where + O: StableAddress<Target: ToHandleMut<HandleMut = H>>, + H: DerefMut, { /// Creates a new mutable `OwningHandle` for a type that implements `ToHandleMut`. pub fn new_mut(o: O) -> Self { diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index 3bdd3e3da048..7fe2a890a537 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -589,10 +589,8 @@ impl<E:Idx> GenKillSet<E> { self.gen_set.insert(e); self.kill_set.remove(e); } - fn gen_all<I>(&mut self, i: I) - where I: IntoIterator, - I::Item: Borrow<E> - { + + fn gen_all(&mut self, i: impl IntoIterator<Item: Borrow<E>>) { for j in i { self.gen(*j.borrow()); } @@ -603,10 +601,7 @@ impl<E:Idx> GenKillSet<E> { self.kill_set.insert(e); } - fn kill_all<I>(&mut self, i: I) - where I: IntoIterator, - I::Item: Borrow<E> - { + fn kill_all(&mut self, i: impl IntoIterator<Item: Borrow<E>>) { for j in i { self.kill(*j.borrow()); } diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 20d5e54d2ce4..cccf7b9545bd 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -23,6 +23,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(trusted_len)] #![feature(try_blocks)] #![feature(mem_take)] +#![feature(associated_type_bounds)] #![recursion_limit="256"] diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index 80aeecb84d72..d981740780e6 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -9,10 +9,7 @@ use std::sync::Arc; use smallvec::{Array, SmallVec}; -impl<A> Encodable for SmallVec<A> - where A: Array, - A::Item: Encodable -{ +impl<A: Array<Item: Encodable>> Encodable for SmallVec<A> { fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { @@ -23,10 +20,7 @@ impl<A> Encodable for SmallVec<A> } } -impl<A> Decodable for SmallVec<A> - where A: Array, - A::Item: Decodable -{ +impl<A: Array<Item: Decodable>> Decodable for SmallVec<A> { fn decode<D: Decoder>(d: &mut D) -> Result<SmallVec<A>, D::Error> { d.read_seq(|d, len| { let mut vec = SmallVec::with_capacity(len); diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 2ad85c603d1e..67a48ca4af90 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -13,6 +13,7 @@ Core encoding and decoding interfaces. #![feature(specialization)] #![feature(never_type)] #![feature(nll)] +#![feature(associated_type_bounds)] #![cfg_attr(test, feature(test))] pub use self::serialize::{Decoder, Encoder, Decodable, Encodable}; diff --git a/src/libstd/sys/sgx/abi/usercalls/alloc.rs b/src/libstd/sys/sgx/abi/usercalls/alloc.rs index c9ff53d0a4fd..75dd0d429c21 100644 --- a/src/libstd/sys/sgx/abi/usercalls/alloc.rs +++ b/src/libstd/sys/sgx/abi/usercalls/alloc.rs @@ -522,7 +522,11 @@ impl<T: ?Sized> Drop for User<T> where T: UserSafe { impl<T: CoerceUnsized<U>, U> CoerceUnsized<UserRef<U>> for UserRef<T> {} #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T, I: SliceIndex<[T]>> Index<I> for UserRef<[T]> where [T]: UserSafe, I::Output: UserSafe { +impl<T, I> Index<I> for UserRef<[T]> +where + [T]: UserSafe, + I: SliceIndex<[T], Output: UserSafe>, +{ type Output = UserRef<I::Output>; #[inline] @@ -538,7 +542,11 @@ impl<T, I: SliceIndex<[T]>> Index<I> for UserRef<[T]> where [T]: UserSafe, I::Ou } #[unstable(feature = "sgx_platform", issue = "56975")] -impl<T, I: SliceIndex<[T]>> IndexMut<I> for UserRef<[T]> where [T]: UserSafe, I::Output: UserSafe { +impl<T, I> IndexMut<I> for UserRef<[T]> +where + [T]: UserSafe, + I: SliceIndex<[T], Output: UserSafe>, +{ #[inline] fn index_mut(&mut self, index: I) -> &mut UserRef<I::Output> { unsafe { From 3d231acceeb6a1af8108577b65bd60745f7dcf17 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo <ilija.tovilo@me.com> Date: Fri, 9 Aug 2019 00:33:57 +0200 Subject: [PATCH 2/3] Add missing #![feature(associated_type_bounds)] --- src/liballoc/tests/lib.rs | 1 + src/libcore/iter/traits/collect.rs | 2 ++ src/libstd/lib.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 6d774f3fecd9..5723a30c0f34 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -8,6 +8,7 @@ #![feature(trusted_len)] #![feature(try_reserve)] #![feature(unboxed_closures)] +#![feature(associated_type_bounds)] use std::hash::{Hash, Hasher}; use std::collections::hash_map::DefaultHasher; diff --git a/src/libcore/iter/traits/collect.rs b/src/libcore/iter/traits/collect.rs index 9f15de33425f..015184cbba25 100644 --- a/src/libcore/iter/traits/collect.rs +++ b/src/libcore/iter/traits/collect.rs @@ -194,6 +194,8 @@ pub trait FromIterator<A>: Sized { /// `Item`: /// /// ```rust +/// #![feature(associated_type_bounds)] +/// /// fn collect_as_strings<T>(collection: T) -> Vec<String> /// where /// T: IntoIterator<Item: std::fmt::Debug>, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index cfee49a7b555..10e3c3450631 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -238,6 +238,7 @@ #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] +#![feature(associated_type_bounds)] #![feature(bind_by_move_pattern_guards)] #![feature(box_syntax)] #![feature(c_variadic)] From 77bfd7fd1a939638a19ca30efad767c81bdd3d8b Mon Sep 17 00:00:00 2001 From: Ilija Tovilo <ilija.tovilo@me.com> Date: Fri, 9 Aug 2019 13:40:54 +0200 Subject: [PATCH 3/3] Don't use associated type bounds in docs until it is stable --- src/libcore/iter/traits/collect.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libcore/iter/traits/collect.rs b/src/libcore/iter/traits/collect.rs index 015184cbba25..25439136b853 100644 --- a/src/libcore/iter/traits/collect.rs +++ b/src/libcore/iter/traits/collect.rs @@ -194,11 +194,10 @@ pub trait FromIterator<A>: Sized { /// `Item`: /// /// ```rust -/// #![feature(associated_type_bounds)] -/// /// fn collect_as_strings<T>(collection: T) -> Vec<String> /// where -/// T: IntoIterator<Item: std::fmt::Debug>, +/// T: IntoIterator, +/// T::Item: std::fmt::Debug, /// { /// collection /// .into_iter()