about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-03-08 11:25:59 -0800
committerGitHub <noreply@github.com>2018-03-08 11:25:59 -0800
commitc8a73e438ad8f0f258fdfa2bf6722bfb656d91d0 (patch)
treec79e290712c0a1debd1575b82348a9242e1f69a7 /src/librustc
parent7c581b08fa9a9b843ecee2a8af82b346da6fd42b (diff)
parent4bde92c17674ba5ac8de4123e0c1023d1e29a60f (diff)
downloadrust-c8a73e438ad8f0f258fdfa2bf6722bfb656d91d0.tar.gz
rust-c8a73e438ad8f0f258fdfa2bf6722bfb656d91d0.zip
Rollup merge of #48752 - alexcrichton:fix-target-feature, r=michaelwoerister
rustc: Fix ICE with `#[target_feature]` on module

This commit fixes an ICE in rustc when `#[target_feature]` was applied to items
other than functions due to the way the feature was validated.
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/hir/check_attr.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs
index d2270345260..d7194e9c2ca 100644
--- a/src/librustc/hir/check_attr.rs
+++ b/src/librustc/hir/check_attr.rs
@@ -47,7 +47,13 @@ struct CheckAttrVisitor<'a, 'tcx: 'a> {
 impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
     /// Check any attribute.
     fn check_attributes(&self, item: &hir::Item, target: Target) {
-        self.tcx.trans_fn_attrs(self.tcx.hir.local_def_id(item.id));
+        if target == Target::Fn {
+            self.tcx.trans_fn_attrs(self.tcx.hir.local_def_id(item.id));
+        } else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
+            self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
+                .span_label(item.span, "not a function")
+                .emit();
+        }
 
         for attr in &item.attrs {
             if let Some(name) = attr.name() {