forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64809 - davidtwco:issue-64768-target-featur…
…e-const, r=varkor hir: Disallow `target_feature` on constants Fixes rust-lang#64768. This PR fixes an ICE when `#[target_feature]` is applied to constants by disallowing this with the same error as when `#[target_feature]` is applied to other places it shouldn't be. I couldn't see anything in the [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2045-target-feature.md) that suggested that `#[target_feature]` should be applicable to constants or any tests that suggested it should, though I might have missed something - if this is desirable in future, it remains possible to remove this error (but for the time being, I think this error is better than an ICE). I also added some extra cases to the test for other places where `#[target_feature]` should not be permitted. cc @gnzlbg
- Loading branch information
Showing
8 changed files
with
204 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// This test checks that all expected errors occur when there are multiple invalid attributes | ||
// on an item. | ||
|
||
#[inline] | ||
//~^ ERROR attribute should be applied to function or closure [E0518] | ||
#[target_feature(enable = "sse2")] | ||
//~^ ERROR attribute should be applied to a function | ||
const FOO: u8 = 0; | ||
|
||
fn main() { } |
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,21 @@ | ||
error[E0518]: attribute should be applied to function or closure | ||
--> $DIR/multiple-invalid.rs:4:1 | ||
| | ||
LL | #[inline] | ||
| ^^^^^^^^^ | ||
... | ||
LL | const FOO: u8 = 0; | ||
| ------------------ not a function or closure | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/multiple-invalid.rs:6:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | const FOO: u8 = 0; | ||
| ------------------ not a function | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0518`. |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/test/ui/target-feature-gate.stderr → src/test/ui/target-feature/gate.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
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,95 @@ | ||
error: malformed `target_feature` attribute input | ||
--> $DIR/invalid-attribute.rs:16:1 | ||
| | ||
LL | #[target_feature = "+sse2"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]` | ||
|
||
error: the feature named `foo` is not valid for this target | ||
--> $DIR/invalid-attribute.rs:18:18 | ||
| | ||
LL | #[target_feature(enable = "foo")] | ||
| ^^^^^^^^^^^^^^ `foo` is not valid for this target | ||
|
||
error: malformed `target_feature` attribute input | ||
--> $DIR/invalid-attribute.rs:21:18 | ||
| | ||
LL | #[target_feature(bar)] | ||
| ^^^ help: must be of the form: `enable = ".."` | ||
|
||
error: malformed `target_feature` attribute input | ||
--> $DIR/invalid-attribute.rs:23:18 | ||
| | ||
LL | #[target_feature(disable = "baz")] | ||
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."` | ||
|
||
error: `#[target_feature(..)]` can only be applied to `unsafe` functions | ||
--> $DIR/invalid-attribute.rs:27:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only be applied to `unsafe` functions | ||
... | ||
LL | fn bar() {} | ||
| ----------- not an `unsafe` function | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-attribute.rs:33:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | mod another {} | ||
| -------------- not a function | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-attribute.rs:38:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | const FOO: usize = 7; | ||
| --------------------- not a function | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-attribute.rs:43:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | struct Foo; | ||
| ----------- not a function | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-attribute.rs:48:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | enum Bar { } | ||
| ------------ not a function | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-attribute.rs:53:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | union Qux { f1: u16, f2: u16 } | ||
| ------------------------------ not a function | ||
|
||
error: attribute should be applied to a function | ||
--> $DIR/invalid-attribute.rs:58:1 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | trait Baz { } | ||
| ------------- not a function | ||
|
||
error: cannot use `#[inline(always)]` with `#[target_feature]` | ||
--> $DIR/invalid-attribute.rs:63:1 | ||
| | ||
LL | #[inline(always)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 12 previous errors | ||
|