about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan McKay <dylanmckay34@gmail.com>2017-01-03 14:54:15 +1300
committerDylan McKay <dylanmckay34@gmail.com>2017-01-03 14:54:15 +1300
commit09178e455ec56ce375521e2d249b81e1dd757977 (patch)
tree20e5ac31cd177b22b9a3928762e7f4a582dac547 /src
parentd3a2efa14b5da1fb11eb25496232bb164238d3c2 (diff)
downloadrust-09178e455ec56ce375521e2d249b81e1dd757977.tar.gz
rust-09178e455ec56ce375521e2d249b81e1dd757977.zip
Don't warn about dead foreign items if the 'allow(dead_code)' attribute is present
This functionality was missing, and should have existed previously.

Fixes #38780
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/dead.rs7
-rw-r--r--src/test/run-pass/test-allow-dead-extern-static-no-warning.rs20
2 files changed, 26 insertions, 1 deletions
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs
index 76adee4e00c..00e21410c70 100644
--- a/src/librustc/middle/dead.rs
+++ b/src/librustc/middle/dead.rs
@@ -445,6 +445,11 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
             && !has_allow_dead_code_or_lang_attr(&variant.attrs)
     }
 
+    fn should_warn_about_foreign_item(&mut self, fi: &hir::ForeignItem) -> bool {
+        !self.symbol_is_live(fi.id, None)
+            && !has_allow_dead_code_or_lang_attr(&fi.attrs)
+    }
+
     // id := node id of an item's definition.
     // ctor_id := `Some` if the item is a struct_ctor (tuple struct),
     //            `None` otherwise.
@@ -534,7 +539,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
     }
 
     fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) {
-        if !self.symbol_is_live(fi.id, None) {
+        if self.should_warn_about_foreign_item(fi) {
             self.warn_dead_code(fi.id, fi.span, fi.name, fi.node.descriptive_variant());
         }
         intravisit::walk_foreign_item(self, fi);
diff --git a/src/test/run-pass/test-allow-dead-extern-static-no-warning.rs b/src/test/run-pass/test-allow-dead-extern-static-no-warning.rs
new file mode 100644
index 00000000000..8df32b54b85
--- /dev/null
+++ b/src/test/run-pass/test-allow-dead-extern-static-no-warning.rs
@@ -0,0 +1,20 @@
+// Copyright 2017 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.
+
+// compile-flags: --test
+
+#![deny(dead_code)]
+
+extern "C" {
+    #[allow(dead_code)]
+    static Qt: u64;
+}
+
+fn main() {}