File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
src/test/ui/const-generics/type-dependent Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ // check-pass
2+ #![ feature( const_generics) ]
3+ #![ allow( incomplete_features) ]
4+
5+ struct X ;
6+
7+ impl X {
8+ pub fn getn < const N : usize > ( & self ) -> [ u8 ; N ] {
9+ getn :: < N > ( )
10+ }
11+ }
12+
13+ fn getn < const N : usize > ( ) -> [ u8 ; N ] {
14+ unsafe {
15+ std:: mem:: zeroed ( )
16+ }
17+ }
18+
19+ fn main ( ) {
20+ // works
21+ let [ a, b, c] = getn :: < 3 > ( ) ;
22+
23+ // cannot pattern-match on an array without a fixed length
24+ let [ a, b, c] = X . getn :: < 3 > ( ) ;
25+
26+ // mismatched types, expected array `[u8; 3]` found array `[u8; _]`
27+ let arr: [ u8 ; 3 ] = X . getn :: < 3 > ( ) ;
28+ }
Original file line number Diff line number Diff line change 1+ // check-pass
2+ #![ feature( const_generics) ]
3+ #![ allow( incomplete_features) ]
4+
5+ struct A < const N : usize > ;
6+
7+ struct X ;
8+
9+ impl X {
10+ fn inner < const N : usize > ( ) -> A < N > {
11+ outer :: < N > ( )
12+ }
13+ }
14+
15+ fn outer < const N : usize > ( ) -> A < N > {
16+ A
17+ }
18+
19+ fn main ( ) {
20+ let i: A < 3usize > = outer :: < 3usize > ( ) ;
21+ let o: A < 3usize > = X :: inner :: < 3usize > ( ) ;
22+ }
You can’t perform that action at this time.
0 commit comments