forked from rust-lang/glacier
-
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.
Issue: rust-lang/rust#82956
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
rustc --crate-type=lib --crate-name=ordes - <<'EOF' | ||
#![feature(const_generics, const_evaluatable_checked, array_map)] | ||
use std::array::IntoIter; | ||
pub struct ConstCheck<const CHECK: bool>; | ||
pub trait True {} | ||
impl True for ConstCheck<true> {} | ||
pub trait OrdesDec { | ||
type Newlen; | ||
type Output; | ||
fn pop(self) -> (Self::Newlen, Self::Output); | ||
} | ||
impl<T, const N: usize> OrdesDec for [T; N] | ||
where | ||
ConstCheck<{N > 1}>: True, | ||
[T; N - 1]: Sized, | ||
{ | ||
type Newlen = [T; N - 1]; | ||
type Output = T; | ||
fn pop(self) -> (Self::Newlen, Self::Output) { | ||
let mut iter = IntoIter::new(self); | ||
let end = iter.next_back().unwrap(); | ||
let new = [(); N - 1].map(move |()| iter.next().unwrap()); | ||
(new, end) | ||
} | ||
} | ||
EOF | ||
|
||
rustc -L. - <<'EOF' | ||
extern crate ordes; | ||
use ordes::OrdesDec; | ||
fn main() { | ||
let foo = [0u8, 1, 2, 3, 4]; | ||
let (foo, pop) = foo.pop(); | ||
} | ||
EOF |