-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Don't implement Fn* traits for #[target_feature] functions #73306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
144206e
c98b4c8
8e899b1
51858da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// only-x86_64 | ||
|
||
#![feature(target_feature_11)] | ||
|
||
#[target_feature(enable = "avx")] | ||
fn foo() {} | ||
|
||
#[target_feature(enable = "avx")] | ||
unsafe fn foo_unsafe() {} | ||
|
||
fn call(f: impl Fn()) { | ||
f() | ||
} | ||
|
||
fn call_mut(f: impl FnMut()) { | ||
f() | ||
} | ||
|
||
fn call_once(f: impl FnOnce()) { | ||
f() | ||
} | ||
|
||
fn main() { | ||
call(foo); //~ ERROR expected a `std::ops::Fn<()>` closure, found `fn() {foo}` | ||
call_mut(foo); //~ ERROR expected a `std::ops::FnMut<()>` closure, found `fn() {foo}` | ||
call_once(foo); //~ ERROR expected a `std::ops::FnOnce<()>` closure, found `fn() {foo}` | ||
|
||
call(foo_unsafe); | ||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
call_mut(foo_unsafe); | ||
//~^ ERROR expected a `std::ops::FnMut<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
call_once(foo_unsafe); | ||
//~^ ERROR expected a `std::ops::FnOnce<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `fn() {foo}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this error is confusing and misleading, but at the same time it is consistent with error emitted for unsafe functions. Maybe we want to change it to better explain why foo doesn’t implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a note (open to phrasing suggestions), however I didn't remove this potentially misleading note since it's applied to all closures without any arguments. I'm not sure if it's within the scope of this PR to fix the |
||
--> $DIR/fn-traits.rs:24:10 | ||
| | ||
LL | fn call(f: impl Fn()) { | ||
| ---- required by this bound in `call` | ||
... | ||
LL | call(foo); | ||
| ^^^ expected an `Fn<()>` closure, found `fn() {foo}` | ||
| | ||
= help: the trait `std::ops::Fn<()>` is not implemented for `fn() {foo}` | ||
= note: wrap the `fn() {foo}` in a closure with no arguments: `|| { /* code */ } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a note or change this note? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, this is misleading -- but then I think I would like to make this suggestion actually work, that's what #73631 is about. |
||
= note: `#[target_feature]` functions do not implement the `Fn` traits | ||
|
||
error[E0277]: expected a `std::ops::FnMut<()>` closure, found `fn() {foo}` | ||
--> $DIR/fn-traits.rs:25:14 | ||
| | ||
LL | fn call_mut(f: impl FnMut()) { | ||
| ------- required by this bound in `call_mut` | ||
... | ||
LL | call_mut(foo); | ||
| ^^^ expected an `FnMut<()>` closure, found `fn() {foo}` | ||
| | ||
= help: the trait `std::ops::FnMut<()>` is not implemented for `fn() {foo}` | ||
= note: wrap the `fn() {foo}` in a closure with no arguments: `|| { /* code */ } | ||
= note: `#[target_feature]` functions do not implement the `Fn` traits | ||
|
||
error[E0277]: expected a `std::ops::FnOnce<()>` closure, found `fn() {foo}` | ||
--> $DIR/fn-traits.rs:26:15 | ||
| | ||
LL | fn call_once(f: impl FnOnce()) { | ||
| -------- required by this bound in `call_once` | ||
... | ||
LL | call_once(foo); | ||
| ^^^ expected an `FnOnce<()>` closure, found `fn() {foo}` | ||
| | ||
= help: the trait `std::ops::FnOnce<()>` is not implemented for `fn() {foo}` | ||
= note: wrap the `fn() {foo}` in a closure with no arguments: `|| { /* code */ } | ||
= note: `#[target_feature]` functions do not implement the `Fn` traits | ||
|
||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
--> $DIR/fn-traits.rs:28:10 | ||
| | ||
LL | fn call(f: impl Fn()) { | ||
| ---- required by this bound in `call` | ||
... | ||
LL | call(foo_unsafe); | ||
| ^^^^^^^^^^ expected an `Fn<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
| | ||
= help: the trait `std::ops::Fn<()>` is not implemented for `unsafe fn() {foo_unsafe}` | ||
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ } | ||
= note: `#[target_feature]` functions do not implement the `Fn` traits | ||
|
||
error[E0277]: expected a `std::ops::FnMut<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
--> $DIR/fn-traits.rs:30:14 | ||
| | ||
LL | fn call_mut(f: impl FnMut()) { | ||
| ------- required by this bound in `call_mut` | ||
... | ||
LL | call_mut(foo_unsafe); | ||
| ^^^^^^^^^^ expected an `FnMut<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
| | ||
= help: the trait `std::ops::FnMut<()>` is not implemented for `unsafe fn() {foo_unsafe}` | ||
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ } | ||
= note: `#[target_feature]` functions do not implement the `Fn` traits | ||
|
||
error[E0277]: expected a `std::ops::FnOnce<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
--> $DIR/fn-traits.rs:32:15 | ||
| | ||
LL | fn call_once(f: impl FnOnce()) { | ||
| -------- required by this bound in `call_once` | ||
... | ||
LL | call_once(foo_unsafe); | ||
| ^^^^^^^^^^ expected an `FnOnce<()>` closure, found `unsafe fn() {foo_unsafe}` | ||
| | ||
= help: the trait `std::ops::FnOnce<()>` is not implemented for `unsafe fn() {foo_unsafe}` | ||
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ } | ||
= note: `#[target_feature]` functions do not implement the `Fn` traits | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Uh oh!
There was an error while loading. Please reload this page.