File tree 1 file changed +52
-0
lines changed
tests/ui/const-generics/generic_const_exprs
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ // check-pass
2
+ // known-bug: #97156
3
+
4
+ #![ feature( const_type_id, generic_const_exprs) ]
5
+ #![ allow( incomplete_features) ]
6
+
7
+ use std:: any:: TypeId ;
8
+ // `One` and `Two` are currently considered equal types, as both
9
+ // `One <: Two` and `One :> Two` holds.
10
+ type One = for <' a > fn ( & ' a ( ) , & ' a ( ) ) ;
11
+ type Two = for <' a , ' b > fn ( & ' a ( ) , & ' b ( ) ) ;
12
+ trait AssocCt {
13
+ const ASSOC : usize ;
14
+ }
15
+ const fn to_usize < T : ' static > ( ) -> usize {
16
+ const WHAT_A_TYPE : TypeId = TypeId :: of :: < One > ( ) ;
17
+ match TypeId :: of :: < T > ( ) {
18
+ WHAT_A_TYPE => 0 ,
19
+ _ => 1000 ,
20
+ }
21
+ }
22
+ impl < T : ' static > AssocCt for T {
23
+ const ASSOC : usize = to_usize :: < T > ( ) ;
24
+ }
25
+
26
+ trait WithAssoc < U > {
27
+ type Assoc ;
28
+ }
29
+ impl < T : ' static > WithAssoc < ( ) > for T where [ ( ) ; <T as AssocCt >:: ASSOC ] : {
30
+ type Assoc = [ u8 ; <T as AssocCt >:: ASSOC ] ;
31
+ }
32
+
33
+ fn generic < T : ' static , U > ( x : <T as WithAssoc < U > >:: Assoc ) -> <T as WithAssoc < U > >:: Assoc
34
+ where
35
+ [ ( ) ; <T as AssocCt >:: ASSOC ] : ,
36
+ T : WithAssoc < U > ,
37
+ {
38
+ x
39
+ }
40
+
41
+
42
+ fn unsound < T > ( x : <One as WithAssoc < T > >:: Assoc ) -> <Two as WithAssoc < T > >:: Assoc
43
+ where
44
+ One : WithAssoc < T > ,
45
+ {
46
+ let x: <Two as WithAssoc < T > >:: Assoc = generic :: < One , T > ( x) ;
47
+ x
48
+ }
49
+
50
+ fn main ( ) {
51
+ println ! ( "{:?}" , unsound:: <( ) >( [ ] ) ) ;
52
+ }
You can’t perform that action at this time.
0 commit comments