44mod macros;
55
66use crate :: cmp;
7- use crate :: cmp:: Ordering ;
87use crate :: fmt;
98use crate :: intrinsics:: assume;
109use crate :: iter:: {
1110 FusedIterator , TrustedLen , TrustedRandomAccess , TrustedRandomAccessNoCoerce , UncheckedIterator ,
1211} ;
12+ #[ cfg( not( bootstrap) ) ]
13+ use crate :: marker:: Destruct ;
1314use crate :: marker:: { PhantomData , Send , Sized , Sync } ;
1415use crate :: mem:: { self , SizedTypeProperties } ;
1516use crate :: num:: NonZeroUsize ;
@@ -18,7 +19,8 @@ use crate::ptr::NonNull;
1819use super :: { from_raw_parts, from_raw_parts_mut} ;
1920
2021#[ stable( feature = "rust1" , since = "1.0.0" ) ]
21- impl < ' a , T > IntoIterator for & ' a [ T ] {
22+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
23+ impl < ' a , T > const IntoIterator for & ' a [ T ] {
2224 type Item = & ' a T ;
2325 type IntoIter = Iter < ' a , T > ;
2426
@@ -80,8 +82,9 @@ unsafe impl<T: Sync> Sync for Iter<'_, T> {}
8082unsafe impl < T : Sync > Send for Iter < ' _ , T > { }
8183
8284impl < ' a , T > Iter < ' a , T > {
85+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
8386 #[ inline]
84- pub ( super ) fn new ( slice : & ' a [ T ] ) -> Self {
87+ pub ( super ) const fn new ( slice : & ' a [ T ] ) -> Self {
8588 let ptr = slice. as_ptr ( ) ;
8689 // SAFETY: Similar to `IterMut::new`.
8790 unsafe {
@@ -121,21 +124,23 @@ impl<'a, T> Iter<'a, T> {
121124 #[ must_use]
122125 #[ stable( feature = "iter_to_slice" , since = "1.4.0" ) ]
123126 #[ inline]
124- pub fn as_slice ( & self ) -> & ' a [ T ] {
127+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
128+ pub const fn as_slice ( & self ) -> & ' a [ T ] {
125129 self . make_slice ( )
126130 }
127131}
128132
129133iterator ! { struct Iter -> * const T , & ' a T , const , { /* no mut */ } , {
130- fn is_sorted_by<F >( self , mut compare: F ) -> bool
131- where
132- Self : Sized ,
133- F : FnMut ( & Self :: Item , & Self :: Item ) -> Option <Ordering >,
134- {
135- self . as_slice( ) . windows( 2 ) . all( |w| {
136- compare( &&w[ 0 ] , &&w[ 1 ] ) . map( |o| o != Ordering :: Greater ) . unwrap_or( false )
137- } )
138- }
134+ // FIXME(const_trait_impl)
135+ // fn is_sorted_by<F>(self, mut compare: F) -> bool
136+ // where
137+ // Self: Sized,
138+ // F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
139+ // {
140+ // self.as_slice().windows(2).all(|w| {
141+ // compare(&&w[0], &&w[1]).map(|o| o != Ordering::Greater).unwrap_or(false)
142+ // })
143+ // }
139144} }
140145
141146#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -202,7 +207,7 @@ unsafe impl<T: Send> Send for IterMut<'_, T> {}
202207
203208impl < ' a , T > IterMut < ' a , T > {
204209 #[ inline]
205- pub ( super ) fn new ( slice : & ' a mut [ T ] ) -> Self {
210+ pub ( super ) const fn new ( slice : & ' a mut [ T ] ) -> Self {
206211 let ptr = slice. as_mut_ptr ( ) ;
207212 // SAFETY: There are several things here:
208213 //
0 commit comments