diff options
author | Aleksey Kladov <[email protected]> | 2021-06-16 20:48:48 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-16 20:48:48 +0100 |
commit | 604267088c9ef6afa021807b437dab22d72dfc99 (patch) | |
tree | a98a495f7d24f943541f50c8d21f22ff3460729d /crates | |
parent | 7ba5482a04e2534890b85cf832616a08c1b1bf21 (diff) |
internal: add iterator to minicore
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 47 | ||||
-rw-r--r-- | crates/test_utils/src/minicore.rs | 30 |
2 files changed, 38 insertions, 39 deletions
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 1edec1615..e0ad41fb9 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -418,48 +418,17 @@ fn issue_2705() { | |||
418 | fn issue_2683_chars_impl() { | 418 | fn issue_2683_chars_impl() { |
419 | check_types( | 419 | check_types( |
420 | r#" | 420 | r#" |
421 | //- /main.rs crate:main deps:std | 421 | //- minicore: iterator |
422 | pub struct Chars<'a> {} | ||
423 | impl<'a> Iterator for Chars<'a> { | ||
424 | type Item = char; | ||
425 | fn next(&mut self) -> Option<char> {} | ||
426 | } | ||
427 | |||
422 | fn test() { | 428 | fn test() { |
423 | let chars: std::str::Chars<'_>; | 429 | let chars: Chars<'_>; |
424 | (chars.next(), chars.nth(1)); | 430 | (chars.next(), chars.nth(1)); |
425 | } //^ (Option<char>, Option<char>) | 431 | } //^ (Option<char>, Option<char>) |
426 | |||
427 | //- /std.rs crate:std | ||
428 | #[prelude_import] | ||
429 | use self::prelude::rust_2018::*; | ||
430 | pub mod prelude { | ||
431 | pub mod rust_2018 { | ||
432 | pub use crate::iter::Iterator; | ||
433 | pub use crate::option::Option; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | pub mod iter { | ||
438 | pub use self::traits::Iterator; | ||
439 | pub mod traits { | ||
440 | pub use self::iterator::Iterator; | ||
441 | |||
442 | pub mod iterator { | ||
443 | pub trait Iterator { | ||
444 | type Item; | ||
445 | fn next(&mut self) -> Option<Self::Item>; | ||
446 | fn nth(&mut self, n: usize) -> Option<Self::Item> {} | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | } | ||
451 | |||
452 | pub mod option { | ||
453 | pub enum Option<T> {} | ||
454 | } | ||
455 | |||
456 | pub mod str { | ||
457 | pub struct Chars<'a> {} | ||
458 | impl<'a> Iterator for Chars<'a> { | ||
459 | type Item = char; | ||
460 | fn next(&mut self) -> Option<char> {} | ||
461 | } | ||
462 | } | ||
463 | "#, | 432 | "#, |
464 | ); | 433 | ); |
465 | } | 434 | } |
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index e04ca58d2..011d460be 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs | |||
@@ -20,6 +20,7 @@ | |||
20 | //! future: pin | 20 | //! future: pin |
21 | //! option: | 21 | //! option: |
22 | //! result: | 22 | //! result: |
23 | //! iterator: option | ||
23 | 24 | ||
24 | pub mod marker { | 25 | pub mod marker { |
25 | // region:sized | 26 | // region:sized |
@@ -206,9 +207,38 @@ pub mod task { | |||
206 | } | 207 | } |
207 | // endregion:future | 208 | // endregion:future |
208 | 209 | ||
210 | // region:iterator | ||
211 | pub mod iter { | ||
212 | mod traits { | ||
213 | mod iterator { | ||
214 | pub trait Iterator { | ||
215 | type Item; | ||
216 | #[lang = "next"] | ||
217 | fn next(&mut self) -> Option<Self::Item>; | ||
218 | fn nth(&mut self, n: usize) -> Option<Self::Item> { | ||
219 | loop {} | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | mod collect { | ||
224 | pub trait IntoIterator { | ||
225 | type Item; | ||
226 | type IntoIter: Iterator<Item = Self::Item>; | ||
227 | #[lang = "into_iter"] | ||
228 | fn into_iter(self) -> Self::IntoIter; | ||
229 | } | ||
230 | } | ||
231 | pub use self::collect::IntoIterator; | ||
232 | pub use self::iterator::Iterator; | ||
233 | } | ||
234 | pub use self::traits::{IntoIterator, Iterator}; | ||
235 | } | ||
236 | // endregion:iterator | ||
237 | |||
209 | pub mod prelude { | 238 | pub mod prelude { |
210 | pub mod v1 { | 239 | pub mod v1 { |
211 | pub use crate::{ | 240 | pub use crate::{ |
241 | iter::{IntoIterator, Iterator}, // :iterator | ||
212 | marker::Sized, // :sized | 242 | marker::Sized, // :sized |
213 | ops::{Fn, FnMut, FnOnce}, // :fn | 243 | ops::{Fn, FnMut, FnOnce}, // :fn |
214 | option::Option::{self, None, Some}, // :option | 244 | option::Option::{self, None, Some}, // :option |