Rollup merge of #73795 - JohnTitor:tests-for-const-fn-ptrs, r=oli-obk

Add some `const_compare_raw_pointers`-related regression tests

Closes #71381
Closes #71382
Closes #71611
Closes #72352

r? @oli-obk, the author of #73398
This commit is contained in:
Manish Goregaokar 2020-06-28 08:30:27 -07:00 committed by GitHub
commit 2c1b732961
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 125 additions and 0 deletions

View file

@ -0,0 +1,33 @@
#![feature(const_generics)]
#![allow(incomplete_features)]
struct Test(*const usize);
type PassArg = ();
unsafe extern "C" fn pass(args: PassArg) {
println!("Hello, world!");
}
impl Test {
pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
//~^ ERROR: using function pointers as const generic parameters is forbidden
self.0 = Self::trampiline::<Args, IDX, FN> as _
}
unsafe extern "C" fn trampiline<
Args: Sized,
const IDX: usize,
const FN: unsafe extern "C" fn(Args),
//~^ ERROR: using function pointers as const generic parameters is forbidden
>(
args: Args,
) {
FN(args)
}
}
fn main() {
let x = Test();
x.call_me::<PassArg, 30, pass>()
}

View file

@ -0,0 +1,14 @@
error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-71381.rs:13:61
|
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-71381.rs:21:19
|
LL | const FN: unsafe extern "C" fn(Args),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -0,0 +1,24 @@
#![feature(const_generics)]
#![allow(incomplete_features)]
struct Test();
fn pass() {
println!("Hello, world!");
}
impl Test {
pub fn call_me(&self) {
self.test::<pass>();
}
fn test<const FN: fn()>(&self) {
//~^ ERROR: using function pointers as const generic parameters is forbidden
FN();
}
}
fn main() {
let x = Test();
x.call_me()
}

View file

@ -0,0 +1,8 @@
error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-71382.rs:15:23
|
LL | fn test<const FN: fn()>(&self) {
| ^^^^
error: aborting due to previous error

View file

@ -0,0 +1,9 @@
#![feature(const_generics)]
#![allow(incomplete_features)]
fn func<A, const F: fn(inner: A)>(outer: A) {
//~^ ERROR: using function pointers as const generic parameters is forbidden
F(outer);
}
fn main() {}

View file

@ -0,0 +1,8 @@
error: using function pointers as const generic parameters is forbidden
--> $DIR/issue-71611.rs:4:21
|
LL | fn func<A, const F: fn(inner: A)>(outer: A) {
| ^^^^^^^^^^^^
error: aborting due to previous error

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