Skip to content

Commit

Permalink
Extend UI tests for fixed check_attr()
Browse files Browse the repository at this point in the history
Add testcases for the `#[track_caller]` and `#[target_feature(..)]`
function attributes for errors that were not not caught before.
  • Loading branch information
neocturne committed Apr 16, 2020
1 parent 9a2bca6 commit 6c700dc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/test/ui/rfc-2091-track-caller/error-with-invalid-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
extern "C" fn f() {}
//~^^ ERROR `#[track_caller]` requires Rust ABI

extern "C" {
#[track_caller]
fn g();
//~^^ ERROR `#[track_caller]` requires Rust ABI
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ error[E0737]: `#[track_caller]` requires Rust ABI
LL | #[track_caller]
| ^^^^^^^^^^^^^^^

error: aborting due to previous error
error[E0737]: `#[track_caller]` requires Rust ABI
--> $DIR/error-with-invalid-abi.rs:8:5
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0737`.
17 changes: 17 additions & 0 deletions src/test/ui/target-feature/invalid-attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,26 @@ trait Baz { }
#[target_feature(enable = "sse2")]
unsafe fn test() {}

trait Quux {
fn foo();
}

impl Quux for Foo {
#[target_feature(enable = "sse2")]
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
//~| NOTE can only be applied to `unsafe` functions
fn foo() {}
//~^ NOTE not an `unsafe` function
}

fn main() {
unsafe {
foo();
bar();
}
#[target_feature(enable = "sse2")]
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
//~| NOTE can only be applied to `unsafe` functions
|| {};
//~^ NOTE not an `unsafe` function
}
20 changes: 19 additions & 1 deletion src/test/ui/target-feature/invalid-attribute.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,23 @@ error: cannot use `#[inline(always)]` with `#[target_feature]`
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^

error: aborting due to 12 previous errors
error: `#[target_feature(..)]` can only be applied to `unsafe` functions
--> $DIR/invalid-attribute.rs:85:5
|
LL | #[target_feature(enable = "sse2")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
...
LL | || {};
| ----- not an `unsafe` function

error: `#[target_feature(..)]` can only be applied to `unsafe` functions
--> $DIR/invalid-attribute.rs:73:5
|
LL | #[target_feature(enable = "sse2")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions
...
LL | fn foo() {}
| ----------- not an `unsafe` function

error: aborting due to 14 previous errors

0 comments on commit 6c700dc

Please sign in to comment.