From c10eec3a1ca0a328f406f6b752eb0fd3a90dca91 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 14 Apr 2021 16:40:23 -0700 Subject: Bootstrapping preparation for the library Since just `ops::Try` will need to change meaning. --- library/alloc/src/collections/vec_deque/iter.rs | 6 +++--- library/alloc/src/lib.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/collections/vec_deque/iter.rs b/library/alloc/src/collections/vec_deque/iter.rs index e4cfb3acdfd..793adfb0c0f 100644 --- a/library/alloc/src/collections/vec_deque/iter.rs +++ b/library/alloc/src/collections/vec_deque/iter.rs @@ -1,6 +1,6 @@ use core::fmt; use core::iter::{FusedIterator, TrustedLen, TrustedRandomAccess}; -use core::ops::Try; +use core::ops::TryWhereOutputEquals; use super::{count, wrap_index, RingSlices}; @@ -66,7 +66,7 @@ impl<'a, T> Iterator for Iter<'a, T> { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: Try, + R: TryWhereOutputEquals, { let (mut iter, final_res); if self.tail <= self.head { @@ -140,7 +140,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: Try, + R: TryWhereOutputEquals, { let (mut iter, final_res); if self.tail <= self.head { diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 66b1036f2ab..af973c29bde 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -141,6 +141,7 @@ #![feature(alloc_layout_extra)] #![feature(trusted_random_access)] #![feature(try_trait)] +#![feature(try_trait_transition)] #![feature(min_type_alias_impl_trait)] #![feature(associated_type_bounds)] #![feature(slice_group_by)] -- cgit 1.4.1-3-g733a5 From b7a6c4a905e9e4b13785a6544434f6ffe859329c Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 5 May 2021 22:47:02 -0700 Subject: Perf Experiment: Wait, what if I just skip the trait alias --- library/alloc/src/collections/vec_deque/iter.rs | 6 +++--- library/alloc/src/lib.rs | 2 +- library/core/src/iter/adapters/chain.rs | 6 +++--- library/core/src/iter/adapters/cloned.rs | 6 +++--- library/core/src/iter/adapters/copied.rs | 6 +++--- library/core/src/iter/adapters/cycle.rs | 4 ++-- library/core/src/iter/adapters/enumerate.rs | 6 +++--- library/core/src/iter/adapters/filter.rs | 8 ++++---- library/core/src/iter/adapters/filter_map.rs | 8 ++++---- library/core/src/iter/adapters/flatten.rs | 18 +++++++++--------- library/core/src/iter/adapters/fuse.rs | 18 +++++++++--------- library/core/src/iter/adapters/inspect.rs | 6 +++--- library/core/src/iter/adapters/map.rs | 6 +++--- library/core/src/iter/adapters/map_while.rs | 4 ++-- library/core/src/iter/adapters/mod.rs | 4 ++-- library/core/src/iter/adapters/peekable.rs | 8 ++++---- library/core/src/iter/adapters/rev.rs | 6 +++--- library/core/src/iter/adapters/scan.rs | 6 +++--- library/core/src/iter/adapters/skip.rs | 8 ++++---- library/core/src/iter/adapters/skip_while.rs | 4 ++-- library/core/src/iter/adapters/step_by.rs | 6 +++--- library/core/src/iter/adapters/take.rs | 8 ++++---- library/core/src/iter/adapters/take_while.rs | 6 +++--- library/core/src/iter/range.rs | 6 +++--- library/core/src/iter/traits/double_ended.rs | 4 ++-- library/core/src/iter/traits/iterator.rs | 14 +++++++------- library/core/src/ops/control_flow.rs | 8 ++++---- library/core/src/ops/mod.rs | 21 --------------------- library/core/src/ops/try.rs | 6 +++--- library/core/src/option.rs | 2 +- library/core/src/result.rs | 2 +- library/core/src/slice/ascii.rs | 2 +- library/core/src/str/iter.rs | 4 ++-- library/core/src/task/poll.rs | 12 ++++++------ 34 files changed, 110 insertions(+), 131 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/collections/vec_deque/iter.rs b/library/alloc/src/collections/vec_deque/iter.rs index 793adfb0c0f..f3eb228c9e3 100644 --- a/library/alloc/src/collections/vec_deque/iter.rs +++ b/library/alloc/src/collections/vec_deque/iter.rs @@ -1,6 +1,6 @@ use core::fmt; use core::iter::{FusedIterator, TrustedLen, TrustedRandomAccess}; -use core::ops::TryWhereOutputEquals; +use core::ops::Try; use super::{count, wrap_index, RingSlices}; @@ -66,7 +66,7 @@ impl<'a, T> Iterator for Iter<'a, T> { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let (mut iter, final_res); if self.tail <= self.head { @@ -140,7 +140,7 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let (mut iter, final_res); if self.tail <= self.head { diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index af973c29bde..a635d6ffe99 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -141,7 +141,7 @@ #![feature(alloc_layout_extra)] #![feature(trusted_random_access)] #![feature(try_trait)] -#![feature(try_trait_transition)] +#![feature(try_trait_v2)] #![feature(min_type_alias_impl_trait)] #![feature(associated_type_bounds)] #![feature(slice_group_by)] diff --git a/library/core/src/iter/adapters/chain.rs b/library/core/src/iter/adapters/chain.rs index 19bc44776c9..53e48500e3b 100644 --- a/library/core/src/iter/adapters/chain.rs +++ b/library/core/src/iter/adapters/chain.rs @@ -1,5 +1,5 @@ use crate::iter::{DoubleEndedIterator, FusedIterator, Iterator, TrustedLen}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that links two iterators together, in a chain. /// @@ -98,7 +98,7 @@ where where Self: Sized, F: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { if let Some(ref mut a) = self.a { acc = a.try_fold(acc, &mut f)?; @@ -281,7 +281,7 @@ where where Self: Sized, F: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { if let Some(ref mut b) = self.b { acc = b.try_rfold(acc, &mut f)?; diff --git a/library/core/src/iter/adapters/cloned.rs b/library/core/src/iter/adapters/cloned.rs index b0344ce1388..7efc155175c 100644 --- a/library/core/src/iter/adapters/cloned.rs +++ b/library/core/src/iter/adapters/cloned.rs @@ -1,6 +1,6 @@ use crate::iter::adapters::{zip::try_get_unchecked, TrustedRandomAccess}; use crate::iter::{FusedIterator, TrustedLen}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that clones the elements of an underlying iterator. /// @@ -46,7 +46,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.it.try_fold(init, clone_try_fold(f)) } @@ -82,7 +82,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.it.try_rfold(init, clone_try_fold(f)) } diff --git a/library/core/src/iter/adapters/copied.rs b/library/core/src/iter/adapters/copied.rs index d261effc104..def24089275 100644 --- a/library/core/src/iter/adapters/copied.rs +++ b/library/core/src/iter/adapters/copied.rs @@ -1,6 +1,6 @@ use crate::iter::adapters::{zip::try_get_unchecked, TrustedRandomAccess}; use crate::iter::{FusedIterator, TrustedLen}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that copies the elements of an underlying iterator. /// @@ -50,7 +50,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.it.try_fold(init, copy_try_fold(f)) } @@ -98,7 +98,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.it.try_rfold(init, copy_try_fold(f)) } diff --git a/library/core/src/iter/adapters/cycle.rs b/library/core/src/iter/adapters/cycle.rs index 5704dc35901..815e708f9ec 100644 --- a/library/core/src/iter/adapters/cycle.rs +++ b/library/core/src/iter/adapters/cycle.rs @@ -1,4 +1,4 @@ -use crate::{iter::FusedIterator, ops::TryWhereOutputEquals}; +use crate::{iter::FusedIterator, ops::Try}; /// An iterator that repeats endlessly. /// @@ -53,7 +53,7 @@ where fn try_fold(&mut self, mut acc: Acc, mut f: F) -> R where F: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { // fully iterate the current iterator. this is necessary because // `self.iter` may be empty even when `self.orig` isn't diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs index 8b37cc4d4a5..91722a4b62a 100644 --- a/library/core/src/iter/adapters/enumerate.rs +++ b/library/core/src/iter/adapters/enumerate.rs @@ -1,6 +1,6 @@ use crate::iter::adapters::{zip::try_get_unchecked, SourceIter, TrustedRandomAccess}; use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that yields the current count and the element during iteration. /// @@ -71,7 +71,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { #[inline] fn enumerate<'a, T, Acc, R>( @@ -150,7 +150,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { // Can safely add and subtract the count, as `ExactSizeIterator` promises // that the number of elements fits into a `usize`. diff --git a/library/core/src/iter/adapters/filter.rs b/library/core/src/iter/adapters/filter.rs index 8f5484c9a5c..d5f19f12747 100644 --- a/library/core/src/iter/adapters/filter.rs +++ b/library/core/src/iter/adapters/filter.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that filters the elements of `iter` with `predicate`. /// @@ -37,7 +37,7 @@ fn filter_fold( move |acc, item| if predicate(&item) { fold(acc, item) } else { acc } } -fn filter_try_fold<'a, T, Acc, R: TryWhereOutputEquals>( +fn filter_try_fold<'a, T, Acc, R: Try>( predicate: &'a mut impl FnMut(&T) -> bool, mut fold: impl FnMut(Acc, T) -> R + 'a, ) -> impl FnMut(Acc, T) -> R + 'a { @@ -88,7 +88,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_fold(init, filter_try_fold(&mut self.predicate, fold)) } @@ -117,7 +117,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_rfold(init, filter_try_fold(&mut self.predicate, fold)) } diff --git a/library/core/src/iter/adapters/filter_map.rs b/library/core/src/iter/adapters/filter_map.rs index 308f984cd94..01b7be9d52d 100644 --- a/library/core/src/iter/adapters/filter_map.rs +++ b/library/core/src/iter/adapters/filter_map.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator that uses `f` to both filter and map elements from `iter`. /// @@ -39,7 +39,7 @@ fn filter_map_fold( } } -fn filter_map_try_fold<'a, T, B, Acc, R: TryWhereOutputEquals>( +fn filter_map_try_fold<'a, T, B, Acc, R: Try>( f: &'a mut impl FnMut(T) -> Option, mut fold: impl FnMut(Acc, B) -> R + 'a, ) -> impl FnMut(Acc, T) -> R + 'a { @@ -72,7 +72,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_fold(init, filter_map_try_fold(&mut self.f, fold)) } @@ -111,7 +111,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_rfold(init, filter_map_try_fold(&mut self.f, fold)) } diff --git a/library/core/src/iter/adapters/flatten.rs b/library/core/src/iter/adapters/flatten.rs index b2fe1499ca6..3315d346596 100644 --- a/library/core/src/iter/adapters/flatten.rs +++ b/library/core/src/iter/adapters/flatten.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{DoubleEndedIterator, Fuse, FusedIterator, Iterator, Map}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that maps each element to an iterator, and yields the elements /// of the produced iterators. @@ -61,7 +61,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.inner.try_fold(init, fold) } @@ -91,7 +91,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.inner.try_rfold(init, fold) } @@ -178,7 +178,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.inner.try_fold(init, fold) } @@ -208,7 +208,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.inner.try_rfold(init, fold) } @@ -293,10 +293,10 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { #[inline] - fn flatten<'a, T: IntoIterator, Acc, R: TryWhereOutputEquals>( + fn flatten<'a, T: IntoIterator, Acc, R: Try>( frontiter: &'a mut Option, fold: &'a mut impl FnMut(Acc, T::Item) -> R, ) -> impl FnMut(Acc, T) -> R + 'a { @@ -382,10 +382,10 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { #[inline] - fn flatten<'a, T: IntoIterator, Acc, R: TryWhereOutputEquals>( + fn flatten<'a, T: IntoIterator, Acc, R: Try>( backiter: &'a mut Option, fold: &'a mut impl FnMut(Acc, T::Item) -> R, ) -> impl FnMut(Acc, T) -> R + 'a diff --git a/library/core/src/iter/adapters/fuse.rs b/library/core/src/iter/adapters/fuse.rs index 43d0626e3b7..aff48b1b220 100644 --- a/library/core/src/iter/adapters/fuse.rs +++ b/library/core/src/iter/adapters/fuse.rs @@ -3,7 +3,7 @@ use crate::iter::adapters::{zip::try_get_unchecked, InPlaceIterable, SourceIter} use crate::iter::{ DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess, }; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that yields `None` forever after the underlying iterator /// yields `None` once. @@ -92,7 +92,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { FuseImpl::try_fold(self, acc, fold) } @@ -148,7 +148,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { FuseImpl::try_rfold(self, acc, fold) } @@ -219,7 +219,7 @@ trait FuseImpl { where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals; + R: Try; fn fold(self, acc: Acc, fold: Fold) -> Acc where Fold: FnMut(Acc, Self::Item) -> Acc; @@ -238,7 +238,7 @@ trait FuseImpl { where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, I: DoubleEndedIterator; fn rfold(self, acc: Acc, fold: Fold) -> Acc where @@ -305,7 +305,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { if let Some(ref mut iter) = self.iter { acc = iter.try_fold(acc, fold)?; @@ -354,7 +354,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, I: DoubleEndedIterator, { if let Some(ref mut iter) = self.iter { @@ -443,7 +443,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { unchecked!(self).try_fold(init, fold) } @@ -485,7 +485,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, I: DoubleEndedIterator, { unchecked!(self).try_rfold(init, fold) diff --git a/library/core/src/iter/adapters/inspect.rs b/library/core/src/iter/adapters/inspect.rs index 3221a0eeafa..36835d12e56 100644 --- a/library/core/src/iter/adapters/inspect.rs +++ b/library/core/src/iter/adapters/inspect.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that calls a function with a reference to each element before /// yielding it. @@ -87,7 +87,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_fold(init, inspect_try_fold(&mut self.f, fold)) } @@ -117,7 +117,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_rfold(init, inspect_try_fold(&mut self.f, fold)) } diff --git a/library/core/src/iter/adapters/map.rs b/library/core/src/iter/adapters/map.rs index 8ca7adb013f..0bf9f4b0327 100644 --- a/library/core/src/iter/adapters/map.rs +++ b/library/core/src/iter/adapters/map.rs @@ -1,7 +1,7 @@ use crate::fmt; use crate::iter::adapters::{zip::try_get_unchecked, SourceIter, TrustedRandomAccess}; use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that maps the values of `iter` with `f`. /// @@ -110,7 +110,7 @@ where where Self: Sized, G: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_fold(init, map_try_fold(&mut self.f, g)) } @@ -146,7 +146,7 @@ where where Self: Sized, G: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_rfold(init, map_try_fold(&mut self.f, g)) } diff --git a/library/core/src/iter/adapters/map_while.rs b/library/core/src/iter/adapters/map_while.rs index ab16dbdb073..8f89e158804 100644 --- a/library/core/src/iter/adapters/map_while.rs +++ b/library/core/src/iter/adapters/map_while.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{adapters::SourceIter, InPlaceIterable}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator that only accepts elements while `predicate` returns `Some(_)`. /// @@ -54,7 +54,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let Self { iter, predicate } = self; iter.try_fold(init, |acc, x| match predicate(x) { diff --git a/library/core/src/iter/adapters/mod.rs b/library/core/src/iter/adapters/mod.rs index 048d209561b..915585086b0 100644 --- a/library/core/src/iter/adapters/mod.rs +++ b/library/core/src/iter/adapters/mod.rs @@ -1,5 +1,5 @@ use crate::iter::{InPlaceIterable, Iterator}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; mod chain; mod cloned; @@ -167,7 +167,7 @@ where fn try_fold(&mut self, init: B, mut f: F) -> R where F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let error = &mut *self.error; self.iter diff --git a/library/core/src/iter/adapters/peekable.rs b/library/core/src/iter/adapters/peekable.rs index c9c9d952392..8ee7d0955c6 100644 --- a/library/core/src/iter/adapters/peekable.rs +++ b/library/core/src/iter/adapters/peekable.rs @@ -1,5 +1,5 @@ use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator with a `peek()` that returns an optional reference to the next /// element. @@ -91,7 +91,7 @@ impl Iterator for Peekable { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let acc = match self.peeked.take() { Some(None) => return try { init }, @@ -135,7 +135,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { match self.peeked.take() { Some(None) => try { init }, @@ -156,7 +156,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let _use_the_import: ControlFlow<()>; match self.peeked.take() { diff --git a/library/core/src/iter/adapters/rev.rs b/library/core/src/iter/adapters/rev.rs index f24bde9f6ad..139fb7bbdd9 100644 --- a/library/core/src/iter/adapters/rev.rs +++ b/library/core/src/iter/adapters/rev.rs @@ -1,5 +1,5 @@ use crate::iter::{FusedIterator, TrustedLen}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// A double-ended iterator with the direction inverted. /// @@ -51,7 +51,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_rfold(init, f) } @@ -96,7 +96,7 @@ where where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { self.iter.try_fold(init, f) } diff --git a/library/core/src/iter/adapters/scan.rs b/library/core/src/iter/adapters/scan.rs index 38a3f255389..96705b01f66 100644 --- a/library/core/src/iter/adapters/scan.rs +++ b/library/core/src/iter/adapters/scan.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{adapters::SourceIter, InPlaceIterable}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator to maintain state while iterating another iterator. /// @@ -56,9 +56,9 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { - fn scan<'a, T, St, B, Acc, R: TryWhereOutputEquals>( + fn scan<'a, T, St, B, Acc, R: Try>( state: &'a mut St, f: &'a mut impl FnMut(&mut St, T) -> Option, mut fold: impl FnMut(Acc, B) -> R + 'a, diff --git a/library/core/src/iter/adapters/skip.rs b/library/core/src/iter/adapters/skip.rs index bee160baaad..c358a6d12b7 100644 --- a/library/core/src/iter/adapters/skip.rs +++ b/library/core/src/iter/adapters/skip.rs @@ -1,6 +1,6 @@ use crate::intrinsics::unlikely; use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator that skips over `n` elements of `iter`. /// @@ -88,7 +88,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let n = self.n; self.n = 0; @@ -146,9 +146,9 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { - fn check>( + fn check>( mut n: usize, mut fold: impl FnMut(Acc, T) -> R, ) -> impl FnMut(Acc, T) -> ControlFlow { diff --git a/library/core/src/iter/adapters/skip_while.rs b/library/core/src/iter/adapters/skip_while.rs index 3c679187c62..93e29edc8df 100644 --- a/library/core/src/iter/adapters/skip_while.rs +++ b/library/core/src/iter/adapters/skip_while.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; /// An iterator that rejects elements while `predicate` returns `true`. /// @@ -70,7 +70,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { if !self.flag { match self.next() { diff --git a/library/core/src/iter/adapters/step_by.rs b/library/core/src/iter/adapters/step_by.rs index ad29bff213c..4252c34a0e0 100644 --- a/library/core/src/iter/adapters/step_by.rs +++ b/library/core/src/iter/adapters/step_by.rs @@ -1,4 +1,4 @@ -use crate::{intrinsics, iter::from_fn, ops::TryWhereOutputEquals}; +use crate::{intrinsics, iter::from_fn, ops::Try}; /// An iterator for stepping iterators by a custom amount. /// @@ -111,7 +111,7 @@ where fn try_fold(&mut self, mut acc: Acc, mut f: F) -> R where F: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { #[inline] fn nth(iter: &mut I, step: usize) -> impl FnMut() -> Option + '_ { @@ -187,7 +187,7 @@ where fn try_rfold(&mut self, init: Acc, mut f: F) -> R where F: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { #[inline] fn nth_back( diff --git a/library/core/src/iter/adapters/take.rs b/library/core/src/iter/adapters/take.rs index 4852efebdf4..92f82ae2325 100644 --- a/library/core/src/iter/adapters/take.rs +++ b/library/core/src/iter/adapters/take.rs @@ -3,7 +3,7 @@ use crate::iter::{ adapters::zip::try_get_unchecked, adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen, TrustedRandomAccess, }; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator that only iterates over the first `n` iterations of `iter`. /// @@ -80,9 +80,9 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { - fn check<'a, T, Acc, R: TryWhereOutputEquals>( + fn check<'a, T, Acc, R: Try>( n: &'a mut usize, mut fold: impl FnMut(Acc, T) -> R + 'a, ) -> impl FnMut(Acc, T) -> ControlFlow + 'a { @@ -178,7 +178,7 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { if self.n == 0 { try { init } diff --git a/library/core/src/iter/adapters/take_while.rs b/library/core/src/iter/adapters/take_while.rs index d97d3141496..93457d20f7c 100644 --- a/library/core/src/iter/adapters/take_while.rs +++ b/library/core/src/iter/adapters/take_while.rs @@ -1,6 +1,6 @@ use crate::fmt; use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator that only accepts elements while `predicate` returns `true`. /// @@ -68,9 +68,9 @@ where where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { - fn check<'a, T, Acc, R: TryWhereOutputEquals>( + fn check<'a, T, Acc, R: Try>( flag: &'a mut bool, p: &'a mut impl FnMut(&T) -> bool, mut fold: impl FnMut(Acc, T) -> R + 'a, diff --git a/library/core/src/iter/range.rs b/library/core/src/iter/range.rs index d3da6066654..d0b2b4dd631 100644 --- a/library/core/src/iter/range.rs +++ b/library/core/src/iter/range.rs @@ -1,7 +1,7 @@ use crate::char; use crate::convert::TryFrom; use crate::mem; -use crate::ops::{self, TryWhereOutputEquals}; +use crate::ops::{self, Try}; use super::{FusedIterator, TrustedLen, TrustedRandomAccess}; @@ -755,7 +755,7 @@ impl Iterator for ops::RangeInclusive { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { if self.is_empty() { return try { init }; @@ -860,7 +860,7 @@ impl DoubleEndedIterator for ops::RangeInclusive { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { if self.is_empty() { return try { init }; diff --git a/library/core/src/iter/traits/double_ended.rs b/library/core/src/iter/traits/double_ended.rs index aed48a48dde..c302502b3b7 100644 --- a/library/core/src/iter/traits/double_ended.rs +++ b/library/core/src/iter/traits/double_ended.rs @@ -1,4 +1,4 @@ -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; /// An iterator able to yield elements from both ends. /// @@ -218,7 +218,7 @@ pub trait DoubleEndedIterator: Iterator { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let mut accum = init; while let Some(x) = self.next_back() { diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 04315003dd7..ffac4534b20 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -3,7 +3,7 @@ // can't split that into multiple files. use crate::cmp::{self, Ordering}; -use crate::ops::{ControlFlow, TryWhereOutputEquals}; +use crate::ops::{ControlFlow, Try}; use super::super::TrustedRandomAccess; use super::super::{Chain, Cloned, Copied, Cycle, Enumerate, Filter, FilterMap, Fuse}; @@ -1999,7 +1999,7 @@ pub trait Iterator { where Self: Sized, F: FnMut(B, Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { let mut accum = init; while let Some(x) = self.next() { @@ -2041,7 +2041,7 @@ pub trait Iterator { where Self: Sized, F: FnMut(Self::Item) -> R, - R: TryWhereOutputEquals<()>, + R: Try, { #[inline] fn call(mut f: impl FnMut(T) -> R) -> impl FnMut((), T) -> R { @@ -2417,7 +2417,7 @@ pub trait Iterator { where Self: Sized, F: FnMut(&Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, // FIXME: This is a weird bound; the API should change R: crate::ops::TryV2>, { @@ -2425,7 +2425,7 @@ pub trait Iterator { fn check(mut f: F) -> impl FnMut((), T) -> ControlFlow> where F: FnMut(&T) -> R, - R: TryWhereOutputEquals, + R: Try, R: crate::ops::TryV2>, { move |(), x| match f(&x).branch() { @@ -2446,13 +2446,13 @@ pub trait Iterator { where Self: Sized, F: FnMut(&Self::Item) -> R, - R: TryWhereOutputEquals, + R: Try, { #[inline] fn check(mut f: F) -> impl FnMut((), T) -> ControlFlow> where F: FnMut(&T) -> R, - R: TryWhereOutputEquals, + R: Try, { move |(), x| match f(&x).into_result() { Ok(false) => ControlFlow::CONTINUE, diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index 238fcd447bd..dbb51540bd4 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -64,10 +64,10 @@ pub enum ControlFlow { #[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")] impl ops::TryV1 for ControlFlow { - type Ok = C; + type Output = C; type Error = B; #[inline] - fn into_result(self) -> Result { + fn into_result(self) -> Result { match self { ControlFlow::Continue(y) => Ok(y), ControlFlow::Break(x) => Err(x), @@ -78,7 +78,7 @@ impl ops::TryV1 for ControlFlow { ControlFlow::Break(v) } #[inline] - fn from_ok(v: Self::Ok) -> Self { + fn from_ok(v: Self::Output) -> Self { ControlFlow::Continue(v) } } @@ -184,7 +184,7 @@ impl ControlFlow { } #[cfg(bootstrap)] -impl ControlFlow { +impl ControlFlow { /// Create a `ControlFlow` from any type implementing `Try`. #[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")] #[inline] diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 2c4de92d383..beef74de617 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -210,24 +210,3 @@ pub use self::unsize::DispatchFromDyn; #[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")] pub use self::control_flow::ControlFlow; - -/// `TryV1` and `TryV2` have different associated type names, -/// so rather than need `bootstrap` checks all over the library, -/// centralize the difference to this one trait alias. -/// -/// As with all `try_trait_transition` stuff, this will be deleted -/// after the bootstrap compiler uses V2 for `?`. -/// -/// ``` -/// #![feature(try_trait_transition)] -/// use std::ops::TryWhereOutputEquals; -/// fn foo() where T: TryWhereOutputEquals {} -/// foo::, i32>(); -/// ``` -#[unstable(feature = "try_trait_transition", reason = "for bootstrap", issue = "none")] -#[cfg(not(bootstrap))] -pub trait TryWhereOutputEquals = TryV2; - -#[unstable(feature = "try_trait_transition", reason = "for bootstrap", issue = "none")] -#[cfg(bootstrap)] -pub trait TryWhereOutputEquals = TryV1; diff --git a/library/core/src/ops/try.rs b/library/core/src/ops/try.rs index 18e2f951ce5..9d659e78d3c 100644 --- a/library/core/src/ops/try.rs +++ b/library/core/src/ops/try.rs @@ -29,7 +29,7 @@ pub trait Try { /// The type of this value when viewed as successful. #[unstable(feature = "try_trait", issue = "42327")] - type Ok; + type Output; // This no longer follows its RFC, but is only used in bootstrap. /// The type of this value when viewed as failed. #[unstable(feature = "try_trait", issue = "42327")] type Error; @@ -45,7 +45,7 @@ pub trait Try { /// is returned, where `X` is the return type of the enclosing function. #[cfg_attr(bootstrap, lang = "into_result")] #[unstable(feature = "try_trait", issue = "42327")] - fn into_result(self) -> Result; + fn into_result(self) -> Result; /// Wrap an error value to construct the composite result. For example, /// `Result::Err(x)` and `Result::from_error(x)` are equivalent. @@ -57,5 +57,5 @@ pub trait Try { /// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent. #[cfg_attr(bootstrap, lang = "from_ok")] #[unstable(feature = "try_trait", issue = "42327")] - fn from_ok(v: Self::Ok) -> Self; + fn from_ok(v: Self::Output) -> Self; } diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 928d8441fa6..c5b1c804ead 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1645,7 +1645,7 @@ pub struct NoneError; #[unstable(feature = "try_trait", issue = "42327")] impl ops::TryV1 for Option { - type Ok = T; + type Output = T; type Error = NoneError; #[inline] diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 5f6afcc8221..21e406194bc 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1628,7 +1628,7 @@ impl> FromIterator> for Result { #[unstable(feature = "try_trait", issue = "42327")] impl ops::TryV1 for Result { - type Ok = T; + type Output = T; type Error = E; #[inline] diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index c3ba8b23e8d..b92ab7e3475 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -110,7 +110,7 @@ impl<'a> iter::Iterator for EscapeAscii<'a> { fn try_fold(&mut self, init: Acc, fold: Fold) -> R where Fold: FnMut(Acc, Self::Item) -> R, - R: ops::TryWhereOutputEquals, + R: ops::Try, { self.inner.try_fold(init, fold) } diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index 612f17a1e61..6ec6b70b571 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -5,7 +5,7 @@ use crate::fmt::{self, Write}; use crate::iter::TrustedRandomAccess; use crate::iter::{Chain, FlatMap, Flatten}; use crate::iter::{Copied, Filter, FusedIterator, Map, TrustedLen}; -use crate::ops::TryWhereOutputEquals; +use crate::ops::Try; use crate::option; use crate::slice::{self, Split as SliceSplit}; @@ -1467,7 +1467,7 @@ macro_rules! escape_types_impls { #[inline] fn try_fold(&mut self, init: Acc, fold: Fold) -> R where - Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: TryWhereOutputEquals + Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try { self.inner.try_fold(init, fold) } diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index 2ccfc22c27c..188639e7962 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -130,11 +130,11 @@ impl From for Poll { #[stable(feature = "futures_api", since = "1.36.0")] impl ops::TryV1 for Poll> { - type Ok = Poll; + type Output = Poll; type Error = E; #[inline] - fn into_result(self) -> Result { + fn into_result(self) -> Result { match self { Poll::Ready(Ok(x)) => Ok(Poll::Ready(x)), Poll::Ready(Err(e)) => Err(e), @@ -148,7 +148,7 @@ impl ops::TryV1 for Poll> { } #[inline] - fn from_ok(x: Self::Ok) -> Self { + fn from_ok(x: Self::Output) -> Self { x.map(Ok) } } @@ -185,11 +185,11 @@ impl> ops::FromResidual> for Pol #[stable(feature = "futures_api", since = "1.36.0")] impl ops::TryV1 for Poll>> { - type Ok = Poll>; + type Output = Poll>; type Error = E; #[inline] - fn into_result(self) -> Result { + fn into_result(self) -> Result { match self { Poll::Ready(Some(Ok(x))) => Ok(Poll::Ready(Some(x))), Poll::Ready(Some(Err(e))) => Err(e), @@ -204,7 +204,7 @@ impl ops::TryV1 for Poll>> { } #[inline] - fn from_ok(x: Self::Ok) -> Self { + fn from_ok(x: Self::Output) -> Self { x.map(|x| x.map(Ok)) } } -- cgit 1.4.1-3-g733a5 From bf0e34c00159b60472ca2f78adb8837b9f5849a2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 9 May 2021 22:05:02 -0700 Subject: PR feedback --- library/alloc/src/lib.rs | 4 ++-- library/core/src/iter/traits/iterator.rs | 3 ++- src/test/codegen/try_identity.rs | 8 ++++---- src/test/mir-opt/simplify-arm.rs | 8 ++++---- src/test/mir-opt/simplify_try.rs | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index a635d6ffe99..3bc376482e9 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -140,8 +140,8 @@ #![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_uninit_array)] #![feature(alloc_layout_extra)] #![feature(trusted_random_access)] -#![feature(try_trait)] -#![feature(try_trait_v2)] +#![cfg_attr(bootstrap, feature(try_trait))] +#![cfg_attr(not(bootstrap), feature(try_trait_v2))] #![feature(min_type_alias_impl_trait)] #![feature(associated_type_bounds)] #![feature(slice_group_by)] diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index ffac4534b20..777e4bc2c89 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -2418,7 +2418,8 @@ pub trait Iterator { Self: Sized, F: FnMut(&Self::Item) -> R, R: Try, - // FIXME: This is a weird bound; the API should change + // FIXME: This bound is rather strange, but means minimal breakage on nightly. + // See #85115 for the issue tracking a holistic solution for this and try_map. R: crate::ops::TryV2>, { #[inline] diff --git a/src/test/codegen/try_identity.rs b/src/test/codegen/try_identity.rs index 78da06b2fe4..71bfc3b44da 100644 --- a/src/test/codegen/try_identity.rs +++ b/src/test/codegen/try_identity.rs @@ -7,10 +7,10 @@ type R = Result; -// This was written to the `?` from `try_trait`, -// but `try_trait_v2` uses a different structure, -// so the relevant desugar is copied inline -// in order to keep the test testing the same thing. +// This was written to the `?` from `try_trait`, but `try_trait_v2` uses a different structure, +// so the relevant desugar is copied inline in order to keep the test testing the same thing. +// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 #[no_mangle] pub fn try_identity(x: R) -> R { // CHECK: start: diff --git a/src/test/mir-opt/simplify-arm.rs b/src/test/mir-opt/simplify-arm.rs index b789b87f6c2..6a6e39e68f9 100644 --- a/src/test/mir-opt/simplify-arm.rs +++ b/src/test/mir-opt/simplify-arm.rs @@ -28,10 +28,10 @@ fn from_error(e: E) -> Result { Err(e) } -// This was written to the `?` from `try_trait`, -// but `try_trait_v2` uses a different structure, -// so the relevant desugar is copied inline -// in order to keep the test testing the same thing. +// This was written to the `?` from `try_trait`, but `try_trait_v2` uses a different structure, +// so the relevant desugar is copied inline in order to keep the test testing the same thing. +// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 fn id_try(r: Result) -> Result { let x = match into_result(r) { Err(e) => return from_error(From::from(e)), diff --git a/src/test/mir-opt/simplify_try.rs b/src/test/mir-opt/simplify_try.rs index a95cb665a97..b91a7bfe68f 100644 --- a/src/test/mir-opt/simplify_try.rs +++ b/src/test/mir-opt/simplify_try.rs @@ -13,10 +13,10 @@ fn from_error(e: E) -> Result { Err(e) } -// This was written to the `?` from `try_trait`, -// but `try_trait_v2` uses a different structure, -// so the relevant desugar is copied inline -// in order to keep the test testing the same thing. +// This was written to the `?` from `try_trait`, but `try_trait_v2` uses a different structure, +// so the relevant desugar is copied inline in order to keep the test testing the same thing. +// FIXME: while this might be useful for `r#try!`, it would be nice to have a MIR optimization +// that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. See #85133 fn try_identity(x: Result) -> Result { let y = match into_result(x) { Err(e) => return from_error(From::from(e)), -- cgit 1.4.1-3-g733a5