Add test for issue-72352

This commit is contained in:
Yuki Okushi 2020-06-27 20:34:27 +09:00
parent 7125ce7ab7
commit 1d16aed7f0
No known key found for this signature in database
GPG key ID: B0986C85C0E2DAA1
2 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,21 @@
#![feature(const_generics)]
#![allow(incomplete_features)]
use std::ffi::{CStr, CString};
unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
//~^ ERROR: using function pointers as const generic parameters is forbidden
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)
});
}

View file

@ -0,0 +1,8 @@
error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-72352.rs:6:42
|
LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
| ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error