Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add test for issue-72352
  • Loading branch information
JohnTitor committed Jun 27, 2020
1 parent 7125ce7 commit 1d16aed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/test/ui/const-generics/issues/issue-72352.rs
@@ -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 changes: 8 additions & 0 deletions src/test/ui/const-generics/issues/issue-72352.stderr
@@ -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

0 comments on commit 1d16aed

Please sign in to comment.