File tree 2 files changed +29
-0
lines changed
src/test/ui/const-generics/issues
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( const_generics) ]
2
+ #![ allow( incomplete_features) ]
3
+
4
+ use std:: ffi:: { CStr , CString } ;
5
+
6
+ unsafe fn unsafely_do_the_thing < const F : fn ( & CStr ) -> usize > ( ptr : * const i8 ) -> usize {
7
+ //~^ ERROR: using function pointers as const generic parameters is forbidden
8
+ F ( CStr :: from_ptr ( ptr) )
9
+ }
10
+
11
+ fn safely_do_the_thing ( s : & CStr ) -> usize {
12
+ s. to_bytes ( ) . len ( )
13
+ }
14
+
15
+ fn main ( ) {
16
+ let baguette = CString :: new ( "baguette" ) . unwrap ( ) ;
17
+ let ptr = baguette. as_ptr ( ) ;
18
+ println ! ( "{}" , unsafe {
19
+ unsafely_do_the_thing:: <safely_do_the_thing>( ptr)
20
+ } ) ;
21
+ }
Original file line number Diff line number Diff line change
1
+ error: using function pointers as const generic parameters is forbidden
2
+ --> $DIR/issue-72352.rs:6:42
3
+ |
4
+ LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
5
+ | ^^^^^^^^^^^^^^^^^^
6
+
7
+ error: aborting due to previous error
8
+
You can’t perform that action at this time.
0 commit comments