Skip to content

Commit 1d16aed

Browse files
committed
Add test for issue-72352
1 parent 7125ce7 commit 1d16aed

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+

0 commit comments

Comments
 (0)