Add test for issue-72352
This commit is contained in:
parent
7125ce7ab7
commit
1d16aed7f0
2 changed files with 29 additions and 0 deletions
21
src/test/ui/const-generics/issues/issue-72352.rs
Normal file
21
src/test/ui/const-generics/issues/issue-72352.rs
Normal 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)
|
||||
});
|
||||
}
|
8
src/test/ui/const-generics/issues/issue-72352.stderr
Normal file
8
src/test/ui/const-generics/issues/issue-72352.stderr
Normal 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
|
||||
|
Loading…
Add table
Reference in a new issue