File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
src/test/ui/const-generics/type-dependent Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ #![ feature( const_generics) ]
2+ #![ allow( incomplete_features) ]
3+
4+ pub struct Struct < const N : usize > ( ( ) ) ;
5+
6+ impl < const N : usize > Struct < N > {
7+ pub fn new ( ) -> Self {
8+ Struct ( ( ) )
9+ }
10+
11+ pub fn same_ty < const M : usize > ( & self ) -> ( usize , usize ) {
12+ ( N , M )
13+ }
14+
15+ pub fn different_ty < const M : u8 > ( & self ) -> ( usize , u8 ) {
16+ ( N , M )
17+ }
18+
19+ pub fn containing_ty < T , const M : u8 > ( & self ) -> ( usize , u8 ) {
20+ ( std:: mem:: size_of :: < T > ( ) + N , M )
21+ }
22+
23+ pub fn we_have_to_go_deeper < const M : usize > ( & self ) -> Struct < M > {
24+ Struct ( ( ) )
25+ }
26+ }
27+
28+ pub trait Foo {
29+ fn foo < const M : usize > ( & self ) -> usize ;
30+ }
31+
32+ impl Foo for Struct < 7 > {
33+ fn foo < const M : usize > ( & self ) -> usize {
34+ M
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ // aux-build:type_dependent_lib.rs
2+ // run-pass
3+ #![ feature( const_generics) ]
4+ #![ allow( incomplete_features) ]
5+
6+ extern crate type_dependent_lib;
7+
8+ use type_dependent_lib:: * ;
9+
10+ fn main ( ) {
11+ let s = Struct :: < 42 > :: new ( ) ;
12+ assert_eq ! ( s. same_ty:: <7 >( ) , ( 42 , 7 ) ) ;
13+ assert_eq ! ( s. different_ty:: <19 >( ) , ( 42 , 19 ) ) ;
14+ assert_eq ! ( Struct :: <1337 >:: new( ) . different_ty:: <96 >( ) , ( 1337 , 96 ) ) ;
15+ assert_eq ! (
16+ Struct :: <18 >:: new( )
17+ . we_have_to_go_deeper:: <19 >( )
18+ . containing_ty:: <Option <u32 >, 3 >( ) ,
19+ ( 27 , 3 ) ,
20+ ) ;
21+
22+ let s = Struct :: < 7 > :: new ( ) ;
23+ assert_eq ! ( s. foo:: <18 >( ) , 18 ) ;
24+ }
You can’t perform that action at this time.
0 commit comments