-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #109441 - oli-obk:fn_trait_new_solver, r=compiler-errors
Only implement Fn* traits for extern "Rust" safe function pointers and items Since calling the function via an `Fn` trait will assume `extern "Rust"` ABI and not do any safety checks, only safe `extern "Rust"` function can implement the `Fn` traits. This syncs the logic between the old solver and the new solver. r? `@compiler-errors`
- Loading branch information
Showing
5 changed files
with
189 additions
and
28 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
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
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
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 |
---|---|---|
@@ -1,13 +1,32 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// check-pass | ||
|
||
fn require_fn(_: impl Fn() -> i32) {} | ||
|
||
fn f() -> i32 { | ||
1i32 | ||
} | ||
|
||
extern "C" fn g() -> i32 { | ||
2i32 | ||
} | ||
|
||
unsafe fn h() -> i32 { | ||
2i32 | ||
} | ||
|
||
fn main() { | ||
require_fn(f); | ||
require_fn(f as fn() -> i32); | ||
require_fn(f as unsafe fn() -> i32); | ||
//~^ ERROR: expected a `Fn<()>` closure, found `unsafe fn() -> i32` | ||
//~| ERROR: type mismatch resolving `<unsafe fn() -> i32 as FnOnce<()>>::Output == i32` | ||
require_fn(g); | ||
//~^ ERROR: expected a `Fn<()>` closure, found `extern "C" fn() -> i32 {g}` | ||
//~| ERROR: type mismatch resolving `<extern "C" fn() -> i32 {g} as FnOnce<()>>::Output == i32` | ||
require_fn(g as extern "C" fn() -> i32); | ||
//~^ ERROR: expected a `Fn<()>` closure, found `extern "C" fn() -> i32` | ||
//~| ERROR: type mismatch resolving `<extern "C" fn() -> i32 as FnOnce<()>>::Output == i32` | ||
require_fn(h); | ||
//~^ ERROR: expected a `Fn<()>` closure, found `unsafe fn() -> i32 {h}` | ||
//~| ERROR: type mismatch resolving `<unsafe fn() -> i32 {h} as FnOnce<()>>::Output == i32` | ||
} |
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,124 @@ | ||
error[E0277]: expected a `Fn<()>` closure, found `unsafe fn() -> i32` | ||
--> $DIR/fn-trait.rs:20:16 | ||
| | ||
LL | require_fn(f as unsafe fn() -> i32); | ||
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Fn<()>` is not implemented for `unsafe fn() -> i32` | ||
= note: wrap the `unsafe fn() -> i32` in a closure with no arguments: `|| { /* code */ }` | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:23 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^^^^^^^^^ required by this bound in `require_fn` | ||
|
||
error[E0271]: type mismatch resolving `<unsafe fn() -> i32 as FnOnce<()>>::Output == i32` | ||
--> $DIR/fn-trait.rs:20:16 | ||
| | ||
LL | require_fn(f as unsafe fn() -> i32); | ||
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^ types differ | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:31 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^ required by this bound in `require_fn` | ||
|
||
error[E0277]: expected a `Fn<()>` closure, found `extern "C" fn() -> i32 {g}` | ||
--> $DIR/fn-trait.rs:23:16 | ||
| | ||
LL | require_fn(g); | ||
| ---------- ^ expected an `Fn<()>` closure, found `extern "C" fn() -> i32 {g}` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Fn<()>` is not implemented for fn item `extern "C" fn() -> i32 {g}` | ||
= note: wrap the `extern "C" fn() -> i32 {g}` in a closure with no arguments: `|| { /* code */ }` | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:23 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^^^^^^^^^ required by this bound in `require_fn` | ||
|
||
error[E0271]: type mismatch resolving `<extern "C" fn() -> i32 {g} as FnOnce<()>>::Output == i32` | ||
--> $DIR/fn-trait.rs:23:16 | ||
| | ||
LL | require_fn(g); | ||
| ---------- ^ types differ | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:31 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^ required by this bound in `require_fn` | ||
|
||
error[E0277]: expected a `Fn<()>` closure, found `extern "C" fn() -> i32` | ||
--> $DIR/fn-trait.rs:26:16 | ||
| | ||
LL | require_fn(g as extern "C" fn() -> i32); | ||
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `extern "C" fn() -> i32` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Fn<()>` is not implemented for `extern "C" fn() -> i32` | ||
= note: wrap the `extern "C" fn() -> i32` in a closure with no arguments: `|| { /* code */ }` | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:23 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^^^^^^^^^ required by this bound in `require_fn` | ||
|
||
error[E0271]: type mismatch resolving `<extern "C" fn() -> i32 as FnOnce<()>>::Output == i32` | ||
--> $DIR/fn-trait.rs:26:16 | ||
| | ||
LL | require_fn(g as extern "C" fn() -> i32); | ||
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:31 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^ required by this bound in `require_fn` | ||
|
||
error[E0277]: expected a `Fn<()>` closure, found `unsafe fn() -> i32 {h}` | ||
--> $DIR/fn-trait.rs:29:16 | ||
| | ||
LL | require_fn(h); | ||
| ---------- ^ call the function in a closure: `|| unsafe { /* code */ }` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Fn<()>` is not implemented for fn item `unsafe fn() -> i32 {h}` | ||
= note: wrap the `unsafe fn() -> i32 {h}` in a closure with no arguments: `|| { /* code */ }` | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:23 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^^^^^^^^^ required by this bound in `require_fn` | ||
|
||
error[E0271]: type mismatch resolving `<unsafe fn() -> i32 {h} as FnOnce<()>>::Output == i32` | ||
--> $DIR/fn-trait.rs:29:16 | ||
| | ||
LL | require_fn(h); | ||
| ---------- ^ types differ | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `require_fn` | ||
--> $DIR/fn-trait.rs:3:31 | ||
| | ||
LL | fn require_fn(_: impl Fn() -> i32) {} | ||
| ^^^ required by this bound in `require_fn` | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0271, E0277. | ||
For more information about an error, try `rustc --explain E0271`. |