Skip to content

Commit 8d9f73a

Browse files
Add new tests and bless old tests
1 parent f9b9ba5 commit 8d9f73a

12 files changed

+286
-12
lines changed

src/test/ui/macros/issue-68060.stderr

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
1+
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
22
--> $DIR/issue-68060.rs:6:13
33
|
44
LL | #[target_feature(enable = "")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
...
77
LL | |_| (),
88
| ------ not an `unsafe` function
9+
|
10+
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
11+
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
912

1013
error: the feature named `` is not valid for this target
1114
--> $DIR/issue-68060.rs:6:30
@@ -21,4 +24,5 @@ LL | #[track_caller]
2124

2225
error: aborting due to 3 previous errors
2326

24-
For more information about this error, try `rustc --explain E0737`.
27+
Some errors have detailed explanations: E0658, E0737.
28+
For more information about an error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Tests the new rules added by RFC 2396, including:
2+
// - applying `#[target_feature]` to safe functions is allowed
3+
// - calling functions with `#[target_feature]` is allowed in
4+
// functions which have (at least) the same features
5+
// - calling functions with `#[target_feature]` is allowed in
6+
// unsafe contexts
7+
// - functions with `#[target_feature]` can coerce to unsafe fn pointers
8+
9+
// check-pass
10+
// only-x86_64
11+
12+
#![feature(target_feature_11)]
13+
14+
#[target_feature(enable = "sse2")]
15+
const fn sse2() {}
16+
17+
#[cfg(target_feature = "sse2")]
18+
const SSE2_ONLY: () = unsafe {
19+
sse2();
20+
};
21+
22+
#[target_feature(enable = "sse2")]
23+
fn also_sse2() {
24+
sse2();
25+
}
26+
27+
#[target_feature(enable = "sse2")]
28+
#[target_feature(enable = "avx")]
29+
fn sse2_and_avx() {
30+
sse2();
31+
}
32+
33+
struct Foo;
34+
35+
impl Foo {
36+
#[target_feature(enable = "sse2")]
37+
fn sse2(&self) {
38+
sse2();
39+
}
40+
}
41+
42+
fn main() {
43+
if cfg!(target_feature = "sse2") {
44+
unsafe {
45+
sse2();
46+
Foo.sse2();
47+
}
48+
}
49+
let sse2_ptr: unsafe fn() = sse2;
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// only-x86_64
2+
3+
#[target_feature(enable = "sse2")] //~ ERROR can only be applied to `unsafe` functions
4+
fn foo() {}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
2+
--> $DIR/feature-gate-target_feature_11.rs:3:1
3+
|
4+
LL | #[target_feature(enable = "sse2")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL | fn foo() {}
7+
| ----------- not an `unsafe` function
8+
|
9+
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
10+
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// only-x86_64
2+
3+
#![feature(target_feature_11)]
4+
5+
#[target_feature(enable = "sse2")]
6+
fn foo() {}
7+
8+
fn main() {
9+
let foo: fn() = foo; //~ ERROR mismatched types
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/fn-ptr.rs:9:21
3+
|
4+
LL | #[target_feature(enable = "sse2")]
5+
| ---------------------------------- `#[target_feature]` added here
6+
...
7+
LL | let foo: fn() = foo;
8+
| ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers
9+
| |
10+
| expected due to this
11+
|
12+
= note: expected fn pointer `fn()`
13+
found fn item `fn() {foo}`
14+
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// only-x86_64
2+
3+
#![feature(target_feature_11)]
4+
5+
#[target_feature(enable = "sse2")]
6+
const fn sse2() {}
7+
8+
#[target_feature(enable = "avx")]
9+
#[target_feature(enable = "bmi2")]
10+
fn avx_bmi2() {}
11+
12+
struct Quux;
13+
14+
impl Quux {
15+
#[target_feature(enable = "avx")]
16+
#[target_feature(enable = "bmi2")]
17+
fn avx_bmi2(&self) {}
18+
}
19+
20+
fn foo() {
21+
sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
22+
avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
23+
Quux.avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
24+
}
25+
26+
#[target_feature(enable = "sse2")]
27+
fn bar() {
28+
avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
29+
Quux.avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
30+
}
31+
32+
#[target_feature(enable = "avx")]
33+
fn baz() {
34+
sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
35+
avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
36+
Quux.avx_bmi2(); //~ ERROR call to function with `#[target_feature]` is unsafe
37+
}
38+
39+
#[target_feature(enable = "avx")]
40+
#[target_feature(enable = "bmi2")]
41+
fn qux() {
42+
sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
43+
}
44+
45+
const name: () = sse2(); //~ ERROR call to function with `#[target_feature]` is unsafe
46+
47+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
2+
--> $DIR/safe-calls.rs:21:5
3+
|
4+
LL | sse2();
5+
| ^^^^^^ call to function with `#[target_feature]`
6+
|
7+
= note: can only be called if the required target features are available
8+
9+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
10+
--> $DIR/safe-calls.rs:22:5
11+
|
12+
LL | avx_bmi2();
13+
| ^^^^^^^^^^ call to function with `#[target_feature]`
14+
|
15+
= note: can only be called if the required target features are available
16+
17+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
18+
--> $DIR/safe-calls.rs:23:5
19+
|
20+
LL | Quux.avx_bmi2();
21+
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
22+
|
23+
= note: can only be called if the required target features are available
24+
25+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
26+
--> $DIR/safe-calls.rs:28:5
27+
|
28+
LL | avx_bmi2();
29+
| ^^^^^^^^^^ call to function with `#[target_feature]`
30+
|
31+
= note: can only be called if the required target features are available
32+
33+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
34+
--> $DIR/safe-calls.rs:29:5
35+
|
36+
LL | Quux.avx_bmi2();
37+
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
38+
|
39+
= note: can only be called if the required target features are available
40+
41+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
42+
--> $DIR/safe-calls.rs:34:5
43+
|
44+
LL | sse2();
45+
| ^^^^^^ call to function with `#[target_feature]`
46+
|
47+
= note: can only be called if the required target features are available
48+
49+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
50+
--> $DIR/safe-calls.rs:35:5
51+
|
52+
LL | avx_bmi2();
53+
| ^^^^^^^^^^ call to function with `#[target_feature]`
54+
|
55+
= note: can only be called if the required target features are available
56+
57+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
58+
--> $DIR/safe-calls.rs:36:5
59+
|
60+
LL | Quux.avx_bmi2();
61+
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
62+
|
63+
= note: can only be called if the required target features are available
64+
65+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
66+
--> $DIR/safe-calls.rs:42:5
67+
|
68+
LL | sse2();
69+
| ^^^^^^ call to function with `#[target_feature]`
70+
|
71+
= note: can only be called if the required target features are available
72+
73+
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block
74+
--> $DIR/safe-calls.rs:45:18
75+
|
76+
LL | const name: () = sse2();
77+
| ^^^^^^ call to function with `#[target_feature]`
78+
|
79+
= note: can only be called if the required target features are available
80+
81+
error: aborting due to 10 previous errors
82+
83+
For more information about this error, try `rustc --explain E0133`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// only-x86_64
2+
3+
#![feature(target_feature_11)]
4+
5+
trait Foo {
6+
fn foo(&self);
7+
unsafe fn unsf_foo(&self);
8+
}
9+
10+
struct Bar;
11+
12+
impl Foo for Bar {
13+
#[target_feature(enable = "sse2")]
14+
//~^ ERROR cannot be applied to safe trait method
15+
fn foo(&self) {}
16+
17+
#[target_feature(enable = "sse2")]
18+
unsafe fn unsf_foo(&self) {}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: `#[target_feature(..)]` cannot be applied to safe trait method
2+
--> $DIR/trait-impl.rs:13:5
3+
|
4+
LL | #[target_feature(enable = "sse2")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot be applied to safe trait method
6+
LL |
7+
LL | fn foo(&self) {}
8+
| ---------------- not an `unsafe` function
9+
10+
error: aborting due to previous error
11+

src/test/ui/target-feature/invalid-attribute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ unsafe fn foo() {}
2626

2727
#[target_feature(enable = "sse2")]
2828
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
29-
//~| NOTE can only be applied to `unsafe` functions
29+
//~| NOTE see issue #69098
3030
fn bar() {}
3131
//~^ NOTE not an `unsafe` function
3232

@@ -72,7 +72,7 @@ trait Quux {
7272
impl Quux for Foo {
7373
#[target_feature(enable = "sse2")]
7474
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
75-
//~| NOTE can only be applied to `unsafe` functions
75+
//~| NOTE see issue #69098
7676
fn foo() {}
7777
//~^ NOTE not an `unsafe` function
7878
}
@@ -84,7 +84,7 @@ fn main() {
8484
}
8585
#[target_feature(enable = "sse2")]
8686
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
87-
//~| NOTE can only be applied to `unsafe` functions
87+
//~| NOTE see issue #69098
8888
|| {};
8989
//~^ NOTE not an `unsafe` function
9090
}

src/test/ui/target-feature/invalid-attribute.stderr

+16-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ error: malformed `target_feature` attribute input
2222
LL | #[target_feature(disable = "baz")]
2323
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
2424

25-
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
25+
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
2626
--> $DIR/invalid-attribute.rs:27:1
2727
|
2828
LL | #[target_feature(enable = "sse2")]
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030
...
3131
LL | fn bar() {}
3232
| ----------- not an `unsafe` function
33+
|
34+
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
35+
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
3336

3437
error: attribute should be applied to a function
3538
--> $DIR/invalid-attribute.rs:33:1
@@ -91,23 +94,30 @@ error: cannot use `#[inline(always)]` with `#[target_feature]`
9194
LL | #[inline(always)]
9295
| ^^^^^^^^^^^^^^^^^
9396

94-
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
97+
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
9598
--> $DIR/invalid-attribute.rs:85:5
9699
|
97100
LL | #[target_feature(enable = "sse2")]
98-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
101+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99102
...
100103
LL | || {};
101104
| ----- not an `unsafe` function
105+
|
106+
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
107+
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
102108

103-
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
109+
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
104110
--> $DIR/invalid-attribute.rs:73:5
105111
|
106112
LL | #[target_feature(enable = "sse2")]
107-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
113+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108114
...
109115
LL | fn foo() {}
110116
| ----------- not an `unsafe` function
117+
|
118+
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
119+
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
111120

112121
error: aborting due to 14 previous errors
113122

123+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)