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#128791 - compiler-errors:async-fn-unsafe, r…
…=lcnr Don't implement `AsyncFn` for `FnDef`/`FnPtr` that wouldnt implement `Fn` Due to unsafety, ABI, or the presence of target features, some `FnDef`/`FnPtr` types don't implement `Fn*`. Do the same for `AsyncFn*`. Noticed this due to rust-lang#128764, but this isn't really related to that ICE, which is fixed in rust-lang#128792.
- Loading branch information
Showing
6 changed files
with
139 additions
and
23 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
17 changes: 17 additions & 0 deletions
17
tests/ui/async-await/async-closures/fn-exception-target-features.rs
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,17 @@ | ||
//@ edition: 2021 | ||
//@ only-x86_64 | ||
|
||
#![feature(async_closure, target_feature_11)] | ||
// `target_feature_11` just to test safe functions w/ target features. | ||
|
||
use std::pin::Pin; | ||
use std::future::Future; | ||
|
||
#[target_feature(enable = "sse2")] | ||
fn target_feature() -> Pin<Box<dyn Future<Output = ()> + 'static>> { todo!() } | ||
|
||
fn test(f: impl async Fn()) {} | ||
|
||
fn main() { | ||
test(target_feature); //~ ERROR the trait bound | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/async-await/async-closures/fn-exception-target-features.stderr
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,17 @@ | ||
error[E0277]: the trait bound `fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}: AsyncFn<()>` is not satisfied | ||
--> $DIR/fn-exception-target-features.rs:16:10 | ||
| | ||
LL | test(target_feature); | ||
| ---- ^^^^^^^^^^^^^^ the trait `AsyncFn<()>` is not implemented for fn item `fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `test` | ||
--> $DIR/fn-exception-target-features.rs:13:17 | ||
| | ||
LL | fn test(f: impl async Fn()) {} | ||
| ^^^^^^^^^^ required by this bound in `test` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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 @@ | ||
//@ edition: 2021 | ||
|
||
#![feature(async_closure)] | ||
|
||
use std::pin::Pin; | ||
use std::future::Future; | ||
|
||
unsafe extern "Rust" { | ||
pub unsafe fn unsafety() -> Pin<Box<dyn Future<Output = ()> + 'static>>; | ||
} | ||
|
||
unsafe extern "C" { | ||
pub safe fn abi() -> Pin<Box<dyn Future<Output = ()> + 'static>>; | ||
} | ||
|
||
fn test(f: impl async Fn()) {} | ||
|
||
fn main() { | ||
test(unsafety); //~ ERROR the trait bound | ||
test(abi); //~ ERROR the trait bound | ||
} |
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,31 @@ | ||
error[E0277]: the trait bound `unsafe fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {unsafety}: AsyncFn<()>` is not satisfied | ||
--> $DIR/fn-exception.rs:19:10 | ||
| | ||
LL | test(unsafety); | ||
| ---- ^^^^^^^^ the trait `AsyncFn<()>` is not implemented for fn item `unsafe fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {unsafety}` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `test` | ||
--> $DIR/fn-exception.rs:16:17 | ||
| | ||
LL | fn test(f: impl async Fn()) {} | ||
| ^^^^^^^^^^ required by this bound in `test` | ||
|
||
error[E0277]: the trait bound `extern "C" fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {abi}: AsyncFn<()>` is not satisfied | ||
--> $DIR/fn-exception.rs:20:10 | ||
| | ||
LL | test(abi); | ||
| ---- ^^^ the trait `AsyncFn<()>` is not implemented for fn item `extern "C" fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {abi}` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `test` | ||
--> $DIR/fn-exception.rs:16:17 | ||
| | ||
LL | fn test(f: impl async Fn()) {} | ||
| ^^^^^^^^^^ required by this bound in `test` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |