forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#69274 - LeSeulArtichaut:target-feature-11, r=…
…hanna-kruppe Implement RFC 2396: `#[target_feature]` 1.1 Tracking issue: rust-lang#69098 r? @nikomatsakis cc @gnzlbg @joshtriplett
- Loading branch information
Showing
19 changed files
with
392 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
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Tests the new rules added by RFC 2396, including: | ||
// - applying `#[target_feature]` to safe functions is allowed | ||
// - calling functions with `#[target_feature]` is allowed in | ||
// functions which have (at least) the same features | ||
// - calling functions with `#[target_feature]` is allowed in | ||
// unsafe contexts | ||
// - functions with `#[target_feature]` can coerce to unsafe fn pointers | ||
|
||
// check-pass | ||
// only-x86_64 | ||
|
||
#![feature(target_feature_11)] | ||
|
||
#[target_feature(enable = "sse2")] | ||
const fn sse2() {} | ||
|
||
#[cfg(target_feature = "sse2")] | ||
const SSE2_ONLY: () = unsafe { | ||
sse2(); | ||
}; | ||
|
||
#[target_feature(enable = "sse2")] | ||
fn also_sse2() { | ||
sse2(); | ||
} | ||
|
||
#[target_feature(enable = "sse2")] | ||
#[target_feature(enable = "avx")] | ||
fn sse2_and_avx() { | ||
sse2(); | ||
} | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
#[target_feature(enable = "sse2")] | ||
fn sse2(&self) { | ||
sse2(); | ||
} | ||
} | ||
|
||
fn main() { | ||
if cfg!(target_feature = "sse2") { | ||
unsafe { | ||
sse2(); | ||
Foo.sse2(); | ||
} | ||
} | ||
let sse2_ptr: unsafe fn() = sse2; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/ui/rfcs/rfc-2396-target_feature-11/feature-gate-target_feature_11.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,6 @@ | ||
// only-x86_64 | ||
|
||
#[target_feature(enable = "sse2")] //~ ERROR can only be applied to `unsafe` functions | ||
fn foo() {} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/rfcs/rfc-2396-target_feature-11/feature-gate-target_feature_11.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,14 @@ | ||
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions | ||
--> $DIR/feature-gate-target_feature_11.rs:3:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | fn foo() {} | ||
| ----------- not an `unsafe` function | ||
| | ||
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information | ||
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,10 @@ | ||
// only-x86_64 | ||
|
||
#![feature(target_feature_11)] | ||
|
||
#[target_feature(enable = "sse2")] | ||
fn foo() {} | ||
|
||
fn main() { | ||
let foo: fn() = foo; //~ ERROR mismatched types | ||
} |
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,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/fn-ptr.rs:9:21 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ---------------------------------- `#[target_feature]` added here | ||
... | ||
LL | let foo: fn() = foo; | ||
| ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected fn pointer `fn()` | ||
found fn item `fn() {foo}` | ||
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Oops, something went wrong.