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.
add regression tests for rust-lang#67144
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/test/ui/const-generics/type-dependent/issue-67144-1.rs
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,28 @@ | ||
// check-pass | ||
#![feature(const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
struct X; | ||
|
||
impl X { | ||
pub fn getn<const N: usize>(&self) -> [u8; N] { | ||
getn::<N>() | ||
} | ||
} | ||
|
||
fn getn<const N: usize>() -> [u8; N] { | ||
unsafe { | ||
std::mem::zeroed() | ||
} | ||
} | ||
|
||
fn main() { | ||
// works | ||
let [a,b,c] = getn::<3>(); | ||
|
||
// cannot pattern-match on an array without a fixed length | ||
let [a,b,c] = X.getn::<3>(); | ||
|
||
// mismatched types, expected array `[u8; 3]` found array `[u8; _]` | ||
let arr: [u8; 3] = X.getn::<3>(); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/const-generics/type-dependent/issue-67144-2.rs
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,22 @@ | ||
// check-pass | ||
#![feature(const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
struct A<const N: usize>; | ||
|
||
struct X; | ||
|
||
impl X { | ||
fn inner<const N: usize>() -> A<N> { | ||
outer::<N>() | ||
} | ||
} | ||
|
||
fn outer<const N: usize>() -> A<N> { | ||
A | ||
} | ||
|
||
fn main() { | ||
let i: A<3usize> = outer::<3usize>(); | ||
let o: A<3usize> = X::inner::<3usize>(); | ||
} |