rust/tests/ui/const-generics/issues/issue-72352.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
615 B
Rust
Raw Normal View History

//@ revisions: full min
#![cfg_attr(full, feature(adt_const_params))]
#![cfg_attr(full, allow(incomplete_features))]
2020-06-27 06:34:27 -05:00
use std::ffi::{c_char, CStr, CString};
2020-06-27 06:34:27 -05:00
unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const c_char) -> usize {
//~^ 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();
println!("{}", unsafe { unsafely_do_the_thing::<safely_do_the_thing>(ptr) });
2020-06-27 06:34:27 -05:00
}