4
4
mod macros;
5
5
6
6
use crate :: cmp;
7
- use crate :: cmp:: Ordering ;
8
7
use crate :: fmt;
9
8
use crate :: intrinsics:: assume;
10
9
use crate :: iter:: {
11
10
FusedIterator , TrustedLen , TrustedRandomAccess , TrustedRandomAccessNoCoerce , UncheckedIterator ,
12
11
} ;
12
+ #[ cfg( not( bootstrap) ) ]
13
+ use crate :: marker:: Destruct ;
13
14
use crate :: marker:: { PhantomData , Send , Sized , Sync } ;
14
15
use crate :: mem:: { self , SizedTypeProperties } ;
15
16
use crate :: num:: NonZeroUsize ;
@@ -18,7 +19,8 @@ use crate::ptr::NonNull;
18
19
use super :: { from_raw_parts, from_raw_parts_mut} ;
19
20
20
21
#[ 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 ] {
22
24
type Item = & ' a T ;
23
25
type IntoIter = Iter < ' a , T > ;
24
26
@@ -80,8 +82,9 @@ unsafe impl<T: Sync> Sync for Iter<'_, T> {}
80
82
unsafe impl < T : Sync > Send for Iter < ' _ , T > { }
81
83
82
84
impl < ' a , T > Iter < ' a , T > {
85
+ #[ rustc_const_unstable( feature = "const_iter" , issue = "92476" ) ]
83
86
#[ inline]
84
- pub ( super ) fn new ( slice : & ' a [ T ] ) -> Self {
87
+ pub ( super ) const fn new ( slice : & ' a [ T ] ) -> Self {
85
88
let ptr = slice. as_ptr ( ) ;
86
89
// SAFETY: Similar to `IterMut::new`.
87
90
unsafe {
@@ -121,21 +124,23 @@ impl<'a, T> Iter<'a, T> {
121
124
#[ must_use]
122
125
#[ stable( feature = "iter_to_slice" , since = "1.4.0" ) ]
123
126
#[ 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 ] {
125
129
self . make_slice ( )
126
130
}
127
131
}
128
132
129
133
iterator ! { 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
+ // }
139
144
} }
140
145
141
146
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -202,7 +207,7 @@ unsafe impl<T: Send> Send for IterMut<'_, T> {}
202
207
203
208
impl < ' a , T > IterMut < ' a , T > {
204
209
#[ inline]
205
- pub ( super ) fn new ( slice : & ' a mut [ T ] ) -> Self {
210
+ pub ( super ) const fn new ( slice : & ' a mut [ T ] ) -> Self {
206
211
let ptr = slice. as_mut_ptr ( ) ;
207
212
// SAFETY: There are several things here:
208
213
//
0 commit comments