Skip to content

Commit 6c700dc

Browse files
committed
Extend UI tests for fixed check_attr()
Add testcases for the `#[track_caller]` and `#[target_feature(..)]` function attributes for errors that were not not caught before.
1 parent 9a2bca6 commit 6c700dc

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/test/ui/rfc-2091-track-caller/error-with-invalid-abi.rs

+6
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44
extern "C" fn f() {}
55
//~^^ ERROR `#[track_caller]` requires Rust ABI
66

7+
extern "C" {
8+
#[track_caller]
9+
fn g();
10+
//~^^ ERROR `#[track_caller]` requires Rust ABI
11+
}
12+
713
fn main() {}

src/test/ui/rfc-2091-track-caller/error-with-invalid-abi.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ error[E0737]: `#[track_caller]` requires Rust ABI
44
LL | #[track_caller]
55
| ^^^^^^^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error[E0737]: `#[track_caller]` requires Rust ABI
8+
--> $DIR/error-with-invalid-abi.rs:8:5
9+
|
10+
LL | #[track_caller]
11+
| ^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
814

915
For more information about this error, try `rustc --explain E0737`.

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

+17
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,26 @@ trait Baz { }
6565
#[target_feature(enable = "sse2")]
6666
unsafe fn test() {}
6767

68+
trait Quux {
69+
fn foo();
70+
}
71+
72+
impl Quux for Foo {
73+
#[target_feature(enable = "sse2")]
74+
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
75+
//~| NOTE can only be applied to `unsafe` functions
76+
fn foo() {}
77+
//~^ NOTE not an `unsafe` function
78+
}
79+
6880
fn main() {
6981
unsafe {
7082
foo();
7183
bar();
7284
}
85+
#[target_feature(enable = "sse2")]
86+
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
87+
//~| NOTE can only be applied to `unsafe` functions
88+
|| {};
89+
//~^ NOTE not an `unsafe` function
7390
}

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

+19-1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,23 @@ error: cannot use `#[inline(always)]` with `#[target_feature]`
9191
LL | #[inline(always)]
9292
| ^^^^^^^^^^^^^^^^^
9393

94-
error: aborting due to 12 previous errors
94+
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
95+
--> $DIR/invalid-attribute.rs:85:5
96+
|
97+
LL | #[target_feature(enable = "sse2")]
98+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
99+
...
100+
LL | || {};
101+
| ----- not an `unsafe` function
102+
103+
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
104+
--> $DIR/invalid-attribute.rs:73:5
105+
|
106+
LL | #[target_feature(enable = "sse2")]
107+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
108+
...
109+
LL | fn foo() {}
110+
| ----------- not an `unsafe` function
111+
112+
error: aborting due to 14 previous errors
95113

0 commit comments

Comments
 (0)