about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-24 20:59:15 +0000
committerbors <bors@rust-lang.org>2018-04-24 20:59:15 +0000
commit190a6c41cf2afdb11e81545846f2639ee96998e8 (patch)
treed93609e13545a6e8fe91850ed9f10ff7601faa30
parentf5203d1073a774e01ae0c57ebb561648a8fd9910 (diff)
parent81a643731d987aa320c936110326ab9dfe812bd0 (diff)
Auto merge of #50096 - alexcrichton:less-simd-warnings, r=michaelwoerister
Tweak some warnings around #[target_feature]

This commit fixes up some issues discovered when getting the `stdsimd` crate's CI compiling again.
-rw-r--r--src/librustc_typeck/collect.rs5
-rw-r--r--src/libsyntax/feature_gate.rs2
-rw-r--r--src/test/run-pass/auxiliary/using-target-feature-unstable.rs15
-rw-r--r--src/test/run-pass/using-target-feature-unstable.rs20
4 files changed, 39 insertions, 3 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 6bd38244e8c..a1eb043995a 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -1682,6 +1682,7 @@ fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
 fn from_target_feature(
     tcx: TyCtxt,
+    id: DefId,
     attr: &ast::Attribute,
     whitelist: &FxHashMap<String, Option<String>>,
     target_features: &mut Vec<Symbol>,
@@ -1752,7 +1753,7 @@ fn from_target_feature(
                 Some(name) => bug!("unknown target feature gate {}", name),
                 None => true,
             };
-            if !allowed {
+            if !allowed && id.is_local() {
                 feature_gate::emit_feature_err(
                     &tcx.sess.parse_sess,
                     feature_gate.as_ref().unwrap(),
@@ -1877,7 +1878,7 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
                            `unsafe` function";
                 tcx.sess.span_err(attr.span, msg);
             }
-            from_target_feature(tcx, attr, &whitelist, &mut trans_fn_attrs.target_features);
+            from_target_feature(tcx, id, attr, &whitelist, &mut trans_fn_attrs.target_features);
         } else if attr.check_name("linkage") {
             if let Some(val) = attr.value_str() {
                 trans_fn_attrs.linkage = Some(linkage_by_name(tcx, id, &val.as_str()));
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 120dff2dbb9..39ddb13d347 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -936,7 +936,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
                                  "the `#[naked]` attribute \
                                   is an experimental feature",
                                  cfg_fn!(naked_functions))),
-    ("target_feature", Normal, Ungated),
+    ("target_feature", Whitelisted, Ungated),
     ("export_name", Whitelisted, Ungated),
     ("inline", Whitelisted, Ungated),
     ("link", Whitelisted, Ungated),
diff --git a/src/test/run-pass/auxiliary/using-target-feature-unstable.rs b/src/test/run-pass/auxiliary/using-target-feature-unstable.rs
new file mode 100644
index 00000000000..8b7d0332fe9
--- /dev/null
+++ b/src/test/run-pass/auxiliary/using-target-feature-unstable.rs
@@ -0,0 +1,15 @@
+// Copyright 2018 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.
+
+#![feature(mmx_target_feature)]
+
+#[inline]
+#[target_feature(enable = "mmx")]
+pub unsafe fn foo() {}
diff --git a/src/test/run-pass/using-target-feature-unstable.rs b/src/test/run-pass/using-target-feature-unstable.rs
new file mode 100644
index 00000000000..614c8d4e1d4
--- /dev/null
+++ b/src/test/run-pass/using-target-feature-unstable.rs
@@ -0,0 +1,20 @@
+// Copyright 2018 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.
+
+// only-x86_64
+// aux-build:using-target-feature-unstable.rs
+
+extern crate using_target_feature_unstable;
+
+fn main() {
+    unsafe {
+        using_target_feature_unstable::foo();
+    }
+}