File tree Expand file tree Collapse file tree 12 files changed +205
-0
lines changed
src/test/ui/const-generics Expand file tree Collapse file tree 12 files changed +205
-0
lines changed Original file line number Diff line number Diff line change 1+ // run-pass
2+ #![ feature( const_generics) ]
3+ #![ allow( incomplete_features, unused_braces) ]
4+
5+ trait Bar < T > { }
6+ impl < T > Bar < T > for [ u8 ; { 7 } ] { }
7+
8+ struct Foo < const N : usize > { }
9+ impl < const N : usize > Foo < N >
10+ where
11+ [ u8 ; N ] : Bar < [ ( ) ; N ] > ,
12+ {
13+ fn foo ( ) { }
14+ }
15+
16+ fn main ( ) {
17+ Foo :: foo ( ) ;
18+ }
Original file line number Diff line number Diff line change 1+ #![ feature( const_generics) ]
2+ #![ allow( incomplete_features) ]
3+
4+ trait Bar < T > { }
5+ impl < T > Bar < T > for [ u8 ; T ] { }
6+ //~^ ERROR expected value, found type parameter `T`
7+
8+ struct Foo < const N : usize > { }
9+ impl < const N : usize > Foo < N >
10+ where
11+ [ u8 ; N ] : Bar < [ ( ) ; N ] > ,
12+ {
13+ fn foo ( ) { }
14+ }
15+
16+ fn main ( ) {
17+ Foo :: foo ( ) ;
18+ }
Original file line number Diff line number Diff line change 1+ error[E0423]: expected value, found type parameter `T`
2+ --> $DIR/issue-69654.rs:5:25
3+ |
4+ LL | impl<T> Bar<T> for [u8; T] {}
5+ | ^ not a value
6+
7+ error: aborting due to previous error
8+
9+ For more information about this error, try `rustc --explain E0423`.
Original file line number Diff line number Diff line change 1+ // build-pass
2+ #![ feature( const_generics) ]
3+ #![ allow( incomplete_features) ]
4+
5+ // This test does not use any "unevaluated" consts, so it should compile just fine.
6+
7+ fn bind < const N : usize > ( value : [ u8 ; N ] ) -> [ u8 ; N ] {
8+ todo ! ( )
9+ }
10+
11+ fn sink ( _: [ u8 ; 5 ] ) { }
12+
13+ fn main ( ) {
14+ let mut arr = Default :: default ( ) ;
15+ arr = bind ( arr) ;
16+ sink ( arr) ;
17+ }
Original file line number Diff line number Diff line change 1+ #![ feature( const_generics) ] //~ WARN the feature `const_generics` is incomplete
2+
3+ // It depends on how we normalize constants and how const equate works if this
4+ // compiles.
5+ //
6+ // Please ping @lcnr if the output if this test changes.
7+
8+
9+ fn bind < const N : usize > ( value : [ u8 ; N + 2 ] ) -> [ u8 ; N * 2 ] {
10+ //~^ ERROR constant expression depends on a generic parameter
11+ //~| ERROR constant expression depends on a generic parameter
12+ todo ! ( )
13+ }
14+
15+ fn main ( ) {
16+ let mut arr = Default :: default ( ) ;
17+ arr = bind :: < 2 > ( arr) ;
18+ }
Original file line number Diff line number Diff line change 1+ warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
2+ --> $DIR/unify-fixpoint.rs:1:12
3+ |
4+ LL | #![feature(const_generics)]
5+ | ^^^^^^^^^^^^^^
6+ |
7+ = note: `#[warn(incomplete_features)]` on by default
8+ = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
9+
10+ error: constant expression depends on a generic parameter
11+ --> $DIR/unify-fixpoint.rs:9:32
12+ |
13+ LL | fn bind<const N: usize>(value: [u8; N + 2]) -> [u8; N * 2] {
14+ | ^^^^^^^^^^^
15+ |
16+ = note: this may fail depending on what value the parameter takes
17+
18+ error: constant expression depends on a generic parameter
19+ --> $DIR/unify-fixpoint.rs:9:48
20+ |
21+ LL | fn bind<const N: usize>(value: [u8; N + 2]) -> [u8; N * 2] {
22+ | ^^^^^^^^^^^
23+ |
24+ = note: this may fail depending on what value the parameter takes
25+
26+ error: aborting due to 2 previous errors; 1 warning emitted
27+
Original file line number Diff line number Diff line change 1+ #![ feature( const_generics) ]
2+ #![ allow( incomplete_features) ]
3+
4+ // This test would try to unify `N` with `N + 1` which must fail the occurs check.
5+
6+ fn bind < const N : usize > ( value : [ u8 ; N ] ) -> [ u8 ; N + 1 ] {
7+ //~^ ERROR constant expression depends on a generic parameter
8+ todo ! ( )
9+ }
10+
11+ fn sink ( _: [ u8 ; 5 ] ) { }
12+
13+ fn main ( ) {
14+ let mut arr = Default :: default ( ) ;
15+ arr = bind ( arr) ;
16+ sink ( arr) ;
17+ }
Original file line number Diff line number Diff line change 1+ error: constant expression depends on a generic parameter
2+ --> $DIR/unify-n-nplusone.rs:6:44
3+ |
4+ LL | fn bind<const N: usize>(value: [u8; N]) -> [u8; N + 1] {
5+ | ^^^^^^^^^^^
6+ |
7+ = note: this may fail depending on what value the parameter takes
8+
9+ error: aborting due to previous error
10+
Original file line number Diff line number Diff line change 1+ // build-pass
2+ #![ feature( const_generics) ]
3+ #![ allow( incomplete_features) ]
4+
5+ trait Bar < const M : usize > { }
6+ impl < const N : usize > Bar < N > for A < { 6 + 1 } > { }
7+
8+ struct A < const N : usize >
9+ where
10+ A < N > : Bar < N > ;
11+
12+ fn main ( ) {
13+ let _ = A ;
14+ }
Original file line number Diff line number Diff line change 1+ // check-pass
2+ #![ feature( const_generics) ]
3+ #![ allow( incomplete_features) ]
4+
5+ // The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
6+ //
7+ // If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
8+ // artificial inference cycle.
9+ struct Foo < const N : usize > ;
10+
11+ trait Bind < T > {
12+ fn bind ( ) -> ( T , Self ) ;
13+ }
14+
15+ // `N` has to be `ConstKind::Unevaluated`.
16+ impl < T > Bind < T > for Foo < { 6 + 1 } > {
17+ fn bind ( ) -> ( T , Self ) {
18+ ( panic ! ( ) , Foo )
19+ }
20+ }
21+
22+ fn main ( ) {
23+ let ( mut t, foo) = Foo :: bind ( ) ;
24+ // `t` is `ty::Infer(TyVar(_#1t))`
25+ // `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
26+ t = foo;
27+ }
You can’t perform that action at this time.
0 commit comments