Add new tests and bless old tests
This commit is contained in:
parent
f9b9ba51d3
commit
8d9f73a690
@ -1,11 +1,14 @@
|
|||||||
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||||
--> $DIR/issue-68060.rs:6:13
|
--> $DIR/issue-68060.rs:6:13
|
||||||
|
|
|
|
||||||
LL | #[target_feature(enable = "")]
|
LL | #[target_feature(enable = "")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
...
|
...
|
||||||
LL | |_| (),
|
LL | |_| (),
|
||||||
| ------ not an `unsafe` function
|
| ------ 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: the feature named `` is not valid for this target
|
error: the feature named `` is not valid for this target
|
||||||
--> $DIR/issue-68060.rs:6:30
|
--> $DIR/issue-68060.rs:6:30
|
||||||
@ -21,4 +24,5 @@ LL | #[track_caller]
|
|||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0737`.
|
Some errors have detailed explanations: E0658, E0737.
|
||||||
|
For more information about an error, try `rustc --explain E0658`.
|
||||||
|
50
src/test/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs
Normal file
50
src/test/ui/rfcs/rfc-2396-target_feature-11/check-pass.rs
Normal file
@ -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;
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
// only-x86_64
|
||||||
|
|
||||||
|
#[target_feature(enable = "sse2")] //~ ERROR can only be applied to `unsafe` functions
|
||||||
|
fn foo() {}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -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`.
|
10
src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs
Normal file
10
src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.rs
Normal file
@ -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
|
||||||
|
}
|
18
src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr
Normal file
18
src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr
Normal file
@ -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`.
|
47
src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.rs
Normal file
47
src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// only-x86_64
|
||||||
|
|
||||||
|
#![feature(target_feature_11)]
|
||||||
|
|
||||||
|
#[target_feature(enable = "sse2")]
|
||||||
|
const fn sse2() {}
|
||||||
|
|
||||||
|
#[target_feature(enable = "avx")]
|
||||||
|
#[target_feature(enable = "bmi2")]
|
||||||
|
fn avx_bmi2() {}
|
||||||
|
|
||||||
|
struct Quux;
|
||||||
|
|
||||||
|
impl Quux {
|
||||||
|
#[target_feature(enable = "avx")]
|
||||||
|
#[target_feature(enable = "bmi2")]
|
||||||
|
fn avx_bmi2(&self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
Quux.avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
}
|
||||||
|
|
||||||
|
#[target_feature(enable = "sse2")]
|
||||||
|
fn bar() {
|
||||||
|
avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
Quux.avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
}
|
||||||
|
|
||||||
|
#[target_feature(enable = "avx")]
|
||||||
|
fn baz() {
|
||||||
|
sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
Quux.avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
}
|
||||||
|
|
||||||
|
#[target_feature(enable = "avx")]
|
||||||
|
#[target_feature(enable = "bmi2")]
|
||||||
|
fn qux() {
|
||||||
|
sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
}
|
||||||
|
|
||||||
|
const name: () = sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,83 @@
|
|||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:21:5
|
||||||
|
|
|
||||||
|
LL | sse2();
|
||||||
|
| ^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:22:5
|
||||||
|
|
|
||||||
|
LL | avx_bmi2();
|
||||||
|
| ^^^^^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:23:5
|
||||||
|
|
|
||||||
|
LL | Quux.avx_bmi2();
|
||||||
|
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:28:5
|
||||||
|
|
|
||||||
|
LL | avx_bmi2();
|
||||||
|
| ^^^^^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:29:5
|
||||||
|
|
|
||||||
|
LL | Quux.avx_bmi2();
|
||||||
|
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:34:5
|
||||||
|
|
|
||||||
|
LL | sse2();
|
||||||
|
| ^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:35:5
|
||||||
|
|
|
||||||
|
LL | avx_bmi2();
|
||||||
|
| ^^^^^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:36:5
|
||||||
|
|
|
||||||
|
LL | Quux.avx_bmi2();
|
||||||
|
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:42:5
|
||||||
|
|
|
||||||
|
LL | sse2();
|
||||||
|
| ^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/safe-calls.rs:45:18
|
||||||
|
|
|
||||||
|
LL | const name: () = sse2();
|
||||||
|
| ^^^^^^ call to function with `#[target_feature]`
|
||||||
|
|
|
||||||
|
= note: can only be called if the required target features are available
|
||||||
|
|
||||||
|
error: aborting due to 10 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0133`.
|
21
src/test/ui/rfcs/rfc-2396-target_feature-11/trait-impl.rs
Normal file
21
src/test/ui/rfcs/rfc-2396-target_feature-11/trait-impl.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// only-x86_64
|
||||||
|
|
||||||
|
#![feature(target_feature_11)]
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
fn foo(&self);
|
||||||
|
unsafe fn unsf_foo(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar;
|
||||||
|
|
||||||
|
impl Foo for Bar {
|
||||||
|
#[target_feature(enable = "sse2")]
|
||||||
|
//~^ ERROR cannot be applied to safe trait method
|
||||||
|
fn foo(&self) {}
|
||||||
|
|
||||||
|
#[target_feature(enable = "sse2")]
|
||||||
|
unsafe fn unsf_foo(&self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,11 @@
|
|||||||
|
error: `#[target_feature(..)]` cannot be applied to safe trait method
|
||||||
|
--> $DIR/trait-impl.rs:13:5
|
||||||
|
|
|
||||||
|
LL | #[target_feature(enable = "sse2")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot be applied to safe trait method
|
||||||
|
LL |
|
||||||
|
LL | fn foo(&self) {}
|
||||||
|
| ---------------- not an `unsafe` function
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
@ -26,7 +26,7 @@ unsafe fn foo() {}
|
|||||||
|
|
||||||
#[target_feature(enable = "sse2")]
|
#[target_feature(enable = "sse2")]
|
||||||
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
|
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||||
//~| NOTE can only be applied to `unsafe` functions
|
//~| NOTE see issue #69098
|
||||||
fn bar() {}
|
fn bar() {}
|
||||||
//~^ NOTE not an `unsafe` function
|
//~^ NOTE not an `unsafe` function
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ trait Quux {
|
|||||||
impl Quux for Foo {
|
impl Quux for Foo {
|
||||||
#[target_feature(enable = "sse2")]
|
#[target_feature(enable = "sse2")]
|
||||||
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
|
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||||
//~| NOTE can only be applied to `unsafe` functions
|
//~| NOTE see issue #69098
|
||||||
fn foo() {}
|
fn foo() {}
|
||||||
//~^ NOTE not an `unsafe` function
|
//~^ NOTE not an `unsafe` function
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
#[target_feature(enable = "sse2")]
|
#[target_feature(enable = "sse2")]
|
||||||
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
|
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||||
//~| NOTE can only be applied to `unsafe` functions
|
//~| NOTE see issue #69098
|
||||||
|| {};
|
|| {};
|
||||||
//~^ NOTE not an `unsafe` function
|
//~^ NOTE not an `unsafe` function
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,17 @@ error: malformed `target_feature` attribute input
|
|||||||
LL | #[target_feature(disable = "baz")]
|
LL | #[target_feature(disable = "baz")]
|
||||||
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
|
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
|
||||||
|
|
||||||
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||||
--> $DIR/invalid-attribute.rs:27:1
|
--> $DIR/invalid-attribute.rs:27:1
|
||||||
|
|
|
|
||||||
LL | #[target_feature(enable = "sse2")]
|
LL | #[target_feature(enable = "sse2")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
...
|
...
|
||||||
LL | fn bar() {}
|
LL | fn bar() {}
|
||||||
| ----------- not an `unsafe` function
|
| ----------- 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: attribute should be applied to a function
|
error: attribute should be applied to a function
|
||||||
--> $DIR/invalid-attribute.rs:33:1
|
--> $DIR/invalid-attribute.rs:33:1
|
||||||
@ -91,23 +94,30 @@ error: cannot use `#[inline(always)]` with `#[target_feature]`
|
|||||||
LL | #[inline(always)]
|
LL | #[inline(always)]
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||||
--> $DIR/invalid-attribute.rs:85:5
|
--> $DIR/invalid-attribute.rs:85:5
|
||||||
|
|
|
|
||||||
LL | #[target_feature(enable = "sse2")]
|
LL | #[target_feature(enable = "sse2")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
...
|
...
|
||||||
LL | || {};
|
LL | || {};
|
||||||
| ----- not an `unsafe` function
|
| ----- 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: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||||
--> $DIR/invalid-attribute.rs:73:5
|
--> $DIR/invalid-attribute.rs:73:5
|
||||||
|
|
|
|
||||||
LL | #[target_feature(enable = "sse2")]
|
LL | #[target_feature(enable = "sse2")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
...
|
...
|
||||||
LL | fn foo() {}
|
LL | fn foo() {}
|
||||||
| ----------- not an `unsafe` function
|
| ----------- 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 14 previous errors
|
error: aborting due to 14 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
|
Loading…
Reference in New Issue
Block a user