blob: 2ec37cc3a1be5dda36b4455e85abb85272891f91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// build-pass
pub fn works() {
let array/*: [_; _]*/ = default_array();
let _: [_; 4] = array;
Foo::foo(&array);
}
pub fn didnt_work() {
let array/*: [_; _]*/ = default_array();
Foo::foo(&array);
let _: [_; 4] = array;
}
trait Foo {
fn foo(&self) {}
}
impl Foo for [i32; 4] {}
impl Foo for [i64; 8] {}
// Only needed because `[_; _]` is not valid type syntax.
fn default_array<T, const N: usize>() -> [T; N]
where
[T; N]: Default,
{
Default::default()
}
fn main() {
works();
didnt_work();
}
|