rustc: Tweak #[target_feature]
syntax
This is an implementation of the `#[target_feature]` syntax-related changes of [RFC 2045][rfc]. Notably two changes have been implemented: * The new syntax is `#[target_feature(enable = "..")]` instead of `#[target_feature = "+.."]`. The `enable` key is necessary instead of the `+` to indicate that a feature is being enabled, and a sub-list is used for possible expansion in the future. Additionally within this syntax the feature names being enabled are now whitelisted against a known set of target feature names that we know about. * The `#[target_feature]` attribute can only be applied to unsafe functions. It was decided in the RFC that invoking an instruction possibly not defined for the current processor is undefined behavior, so to enable this feature for now it requires an `unsafe` intervention. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2045-target-feature.md
This commit is contained in:
parent
e6072a7b38
commit
5f006cebfc
11 changed files with 216 additions and 27 deletions
35
src/test/ui/target-feature-wrong.rs
Normal file
35
src/test/ui/target-feature-wrong.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-arm
|
||||
// ignore-aarch64
|
||||
|
||||
#![feature(target_feature)]
|
||||
|
||||
#[target_feature = "+sse2"]
|
||||
//~^ WARN: deprecated
|
||||
#[target_feature(enable = "foo")]
|
||||
//~^ ERROR: not valid for this target
|
||||
#[target_feature(bar)]
|
||||
//~^ ERROR: only accepts sub-keys
|
||||
#[target_feature(disable = "baz")]
|
||||
//~^ ERROR: only accepts sub-keys
|
||||
unsafe fn foo() {}
|
||||
|
||||
#[target_feature(enable = "sse2")]
|
||||
//~^ ERROR: can only be applied to `unsafe` function
|
||||
fn bar() {}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
foo();
|
||||
bar();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue