forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark DoubleEndedIterator as #[const_trait] using rustc_do_not_const_c…
…heck, implement const Iterator and DoubleEndedIterator for Range.
- Loading branch information
1 parent
7bc67ef
commit 8a9d6bf
Showing
9 changed files
with
70 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#[test] | ||
fn const_manual_iter() { | ||
struct S(bool); | ||
|
||
impl const Iterator for S { | ||
type Item = (); | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.0 == false { | ||
self.0 = true; | ||
Some(()) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
const { | ||
let mut val = S(false); | ||
assert!(val.next().is_some()); | ||
assert!(val.next().is_none()); | ||
assert!(val.next().is_none()); | ||
} | ||
} | ||
|
||
#[test] | ||
fn const_range() { | ||
const { | ||
let mut arr = [0; 3]; | ||
for i in 0..arr.len() { | ||
arr[i] = i; | ||
} | ||
assert!(arr[0] == 0); | ||
assert!(arr[1] == 1); | ||
assert!(arr[2] == 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters