2020-08-26 05:22:55 -05:00
|
|
|
//@ revisions: full min
|
2024-02-14 05:12:19 -06:00
|
|
|
|
2021-08-30 03:59:53 -05:00
|
|
|
#![cfg_attr(full, feature(adt_const_params))]
|
2020-08-26 05:22:55 -05:00
|
|
|
#![cfg_attr(full, allow(incomplete_features))]
|
2020-06-27 06:34:27 -05:00
|
|
|
|
2024-02-14 05:12:19 -06:00
|
|
|
use std::ffi::{c_char, CStr, CString};
|
2020-06-27 06:34:27 -05:00
|
|
|
|
2024-02-14 05:12:19 -06:00
|
|
|
unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const c_char) -> usize {
|
2020-08-31 05:35:04 -05:00
|
|
|
//~^ ERROR: using function pointers as const generic parameters is forbidden
|
2020-06-27 06:34:27 -05:00
|
|
|
F(CStr::from_ptr(ptr))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn safely_do_the_thing(s: &CStr) -> usize {
|
|
|
|
s.to_bytes().len()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let baguette = CString::new("baguette").unwrap();
|
|
|
|
let ptr = baguette.as_ptr();
|
2024-02-14 05:12:19 -06:00
|
|
|
println!("{}", unsafe { unsafely_do_the_thing::<safely_do_the_thing>(ptr) });
|
2020-06-27 06:34:27 -05:00
|
|
|
}
|