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:
commit
2c1b732961
8 changed files with 125 additions and 0 deletions
33
src/test/ui/const-generics/issues/issue-71381.rs
Normal file
33
src/test/ui/const-generics/issues/issue-71381.rs
Normal 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>()
|
||||
}
|
||||
14
src/test/ui/const-generics/issues/issue-71381.stderr
Normal file
14
src/test/ui/const-generics/issues/issue-71381.stderr
Normal 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
|
||||
|
||||
24
src/test/ui/const-generics/issues/issue-71382.rs
Normal file
24
src/test/ui/const-generics/issues/issue-71382.rs
Normal 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()
|
||||
}
|
||||
8
src/test/ui/const-generics/issues/issue-71382.stderr
Normal file
8
src/test/ui/const-generics/issues/issue-71382.stderr
Normal 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
|
||||
|
||||
9
src/test/ui/const-generics/issues/issue-71611.rs
Normal file
9
src/test/ui/const-generics/issues/issue-71611.rs
Normal 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() {}
|
||||
8
src/test/ui/const-generics/issues/issue-71611.stderr
Normal file
8
src/test/ui/const-generics/issues/issue-71611.stderr
Normal 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
|
||||
|
||||
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
Add a link
Reference in a new issue