forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#73795 - JohnTitor:tests-for-const-fn-ptrs, …
…r=oli-obk Add some `const_compare_raw_pointers`-related regression tests Closes rust-lang#71381 Closes rust-lang#71382 Closes rust-lang#71611 Closes rust-lang#72352 r? @oli-obk, the author of rust-lang#73398
- Loading branch information
Showing
8 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|