internal: minimize minicore

We want to keep minicore small, so let's split out iterator adapters and
sources into a separate `iterators` region, and use them only when
needed.
This commit is contained in:
Aleksey Kladov 2021-06-17 11:28:44 +03:00
parent 9b3aa591cd
commit c42cdff3d2
3 changed files with 36 additions and 59 deletions

View File

@ -818,7 +818,7 @@ fn main() {
fn shorten_iterators_in_associated_params() { fn shorten_iterators_in_associated_params() {
check_types( check_types(
r#" r#"
//- minicore: iterator //- minicore: iterators
use core::iter; use core::iter;
pub struct SomeIter<T> {} pub struct SomeIter<T> {}
@ -1126,7 +1126,7 @@ fn main() {
fn shorten_iterator_hints() { fn shorten_iterator_hints() {
check_types( check_types(
r#" r#"
//- minicore: iterator //- minicore: iterators
use core::iter; use core::iter;
struct MyIter; struct MyIter;
@ -1357,7 +1357,7 @@ fn main() {
max_length: None, max_length: None,
}, },
r#" r#"
//- minicore: iterator //- minicore: iterators
use core::iter; use core::iter;
struct MyIter; struct MyIter;

View File

@ -186,18 +186,14 @@ fn main() {
fn test_for_borrowed() { fn test_for_borrowed() {
check_assist( check_assist(
replace_for_loop_with_for_each, replace_for_loop_with_for_each,
r" r#"
//- minicore: iterator //- minicore: iterators
struct Iter; use core::iter::{Repeat, repeat};
impl Iterator for Iter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> { None }
}
struct S; struct S;
impl S { impl S {
fn iter(&self) -> Iter { Iter } fn iter(&self) -> Repeat<i32> { repeat(92) }
fn iter_mut(&mut self) -> Iter { Iter } fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
} }
fn main() { fn main() {
@ -206,18 +202,14 @@ fn main() {
let a = v * 2; let a = v * 2;
} }
} }
", "#,
r" r#"
struct Iter; use core::iter::{Repeat, repeat};
impl Iterator for Iter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> { None }
}
struct S; struct S;
impl S { impl S {
fn iter(&self) -> Iter { Iter } fn iter(&self) -> Repeat<i32> { repeat(92) }
fn iter_mut(&mut self) -> Iter { Iter } fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
} }
fn main() { fn main() {
@ -226,7 +218,7 @@ fn main() {
let a = v * 2; let a = v * 2;
}); });
} }
", "#,
) )
} }
@ -259,18 +251,14 @@ fn main() {
fn test_for_borrowed_mut() { fn test_for_borrowed_mut() {
check_assist( check_assist(
replace_for_loop_with_for_each, replace_for_loop_with_for_each,
r" r#"
//- minicore: iterator //- minicore: iterators
struct Iter; use core::iter::{Repeat, repeat};
impl Iterator for Iter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> { None }
}
struct S; struct S;
impl S { impl S {
fn iter(&self) -> Iter { Iter } fn iter(&self) -> Repeat<i32> { repeat(92) }
fn iter_mut(&mut self) -> Iter { Iter } fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
} }
fn main() { fn main() {
@ -279,18 +267,14 @@ fn main() {
let a = v * 2; let a = v * 2;
} }
} }
", "#,
r" r#"
struct Iter; use core::iter::{Repeat, repeat};
impl Iterator for Iter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> { None }
}
struct S; struct S;
impl S { impl S {
fn iter(&self) -> Iter { Iter } fn iter(&self) -> Repeat<i32> { repeat(92) }
fn iter_mut(&mut self) -> Iter { Iter } fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) }
} }
fn main() { fn main() {
@ -299,7 +283,7 @@ fn main() {
let a = v * 2; let a = v * 2;
}); });
} }
", "#,
) )
} }
@ -332,28 +316,16 @@ fn main() {
check_assist( check_assist(
replace_for_loop_with_for_each, replace_for_loop_with_for_each,
r#" r#"
//- minicore: iterator //- minicore: iterators
struct Iter;
impl Iterator for Iter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> { None }
}
fn main() { fn main() {
for$0 a in Iter.take(1) { for$0 a in core::iter::repeat(92).take(1) {
println!("{}", a); println!("{}", a);
} }
} }
"#, "#,
r#" r#"
struct Iter;
impl Iterator for Iter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> { None }
}
fn main() { fn main() {
Iter.take(1).for_each(|a| { core::iter::repeat(92).take(1).for_each(|a| {
println!("{}", a); println!("{}", a);
}); });
} }

View File

@ -21,6 +21,7 @@
//! option: //! option:
//! result: //! result:
//! iterator: option //! iterator: option
//! iterators: iterator
pub mod marker { pub mod marker {
// region:sized // region:sized
@ -209,6 +210,7 @@ pub mod task {
// region:iterator // region:iterator
pub mod iter { pub mod iter {
// region:iterators
mod adapters { mod adapters {
pub struct Take<I> { pub struct Take<I> {
iter: I, iter: I,
@ -249,6 +251,7 @@ pub mod iter {
pub use self::repeat::{repeat, Repeat}; pub use self::repeat::{repeat, Repeat};
} }
pub use self::sources::{repeat, Repeat}; pub use self::sources::{repeat, Repeat};
// endregion:iterators
mod traits { mod traits {
mod iterator { mod iterator {
@ -261,15 +264,17 @@ pub mod iter {
fn nth(&mut self, n: usize) -> Option<Self::Item> { fn nth(&mut self, n: usize) -> Option<Self::Item> {
loop {} loop {}
} }
fn take(self, n: usize) -> crate::iter::Take<Self> {
loop {}
}
fn by_ref(&mut self) -> &mut Self fn by_ref(&mut self) -> &mut Self
where where
Self: Sized, Self: Sized,
{ {
self self
} }
// region:iterators
fn take(self, n: usize) -> crate::iter::Take<Self> {
loop {}
}
// endregion:iterators
} }
impl<I: Iterator + ?Sized> Iterator for &mut I { impl<I: Iterator + ?Sized> Iterator for &mut I {
type Item = I::Item; type Item = I::Item;