@@ -122,6 +122,22 @@ where
122
122
{
123
123
}
124
124
125
+ #[ unstable( feature = "trusted_len" , issue = "37572" ) ]
126
+ unsafe impl < ' a , T , I , F , const N : usize > TrustedLen for FlatMap < I , & ' a [ T ; N ] , F >
127
+ where
128
+ I : TrustedLen ,
129
+ F : FnMut ( I :: Item ) -> & ' a [ T ; N ] ,
130
+ {
131
+ }
132
+
133
+ #[ unstable( feature = "trusted_len" , issue = "37572" ) ]
134
+ unsafe impl < ' a , T , I , F , const N : usize > TrustedLen for FlatMap < I , & ' a mut [ T ; N ] , F >
135
+ where
136
+ I : TrustedLen ,
137
+ F : FnMut ( I :: Item ) -> & ' a mut [ T ; N ] ,
138
+ {
139
+ }
140
+
125
141
/// An iterator that flattens one level of nesting in an iterator of things
126
142
/// that can be turned into iterators.
127
143
///
@@ -239,8 +255,10 @@ where
239
255
}
240
256
241
257
#[ unstable( feature = "trusted_len" , issue = "37572" ) ]
242
- unsafe impl < T , I , const N : usize > TrustedLen for Flatten < I > where
243
- I : Iterator < Item = [ T ; N ] > + TrustedLen
258
+ unsafe impl < I > TrustedLen for Flatten < I >
259
+ where
260
+ I : TrustedLen ,
261
+ <I as Iterator >:: Item : TrustedConstSize ,
244
262
{
245
263
}
246
264
@@ -475,10 +493,14 @@ where
475
493
}
476
494
477
495
trait ConstSizeIntoIterator : IntoIterator {
496
+ // FIXME(#31844): convert to an associated const once specialization supports that
478
497
fn size ( ) -> Option < usize > ;
479
498
}
480
499
481
- impl < T > ConstSizeIntoIterator for T where T : IntoIterator {
500
+ impl < T > ConstSizeIntoIterator for T
501
+ where
502
+ T : IntoIterator ,
503
+ {
482
504
#[ inline]
483
505
default fn size ( ) -> Option < usize > {
484
506
None
@@ -491,3 +513,30 @@ impl<T, const N: usize> ConstSizeIntoIterator for [T; N] {
491
513
Some ( N )
492
514
}
493
515
}
516
+
517
+ impl < T , const N : usize > ConstSizeIntoIterator for & [ T ; N ] {
518
+ #[ inline]
519
+ fn size ( ) -> Option < usize > {
520
+ Some ( N )
521
+ }
522
+ }
523
+
524
+ impl < T , const N : usize > ConstSizeIntoIterator for & mut [ T ; N ] {
525
+ #[ inline]
526
+ fn size ( ) -> Option < usize > {
527
+ Some ( N )
528
+ }
529
+ }
530
+
531
+ #[ doc( hidden) ]
532
+ #[ unstable( feature = "std_internals" , issue = "none" ) ]
533
+ // FIXME(#20400): Instead of this helper trait there should be multiple impl TrustedLen for Flatten<>
534
+ // blocks with different bounds on Iterator::Item but the compiler erroneously considers them overlapping
535
+ pub unsafe trait TrustedConstSize : IntoIterator { }
536
+
537
+ #[ unstable( feature = "std_internals" , issue = "none" ) ]
538
+ unsafe impl < T , const N : usize > TrustedConstSize for [ T ; N ] { }
539
+ #[ unstable( feature = "std_internals" , issue = "none" ) ]
540
+ unsafe impl < T , const N : usize > TrustedConstSize for & ' _ [ T ; N ] { }
541
+ #[ unstable( feature = "std_internals" , issue = "none" ) ]
542
+ unsafe impl < T , const N : usize > TrustedConstSize for & ' _ mut [ T ; N ] { }
0 commit comments