diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-04-29 23:44:31 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-29 23:44:31 -0400 |
| commit | 43cb7c4212cde808475caeb440ee7436c2120acc (patch) | |
| tree | ea735cf84267223e093c413fbde112d4b13cd63c | |
| parent | eab2af9af517ab9e22ae269e5787bee93e599d0d (diff) | |
| parent | c054b2a761404e0057d678f4c04445505e287309 (diff) | |
| download | rust-43cb7c4212cde808475caeb440ee7436c2120acc.tar.gz rust-43cb7c4212cde808475caeb440ee7436c2120acc.zip | |
Rollup merge of #41637 - eddyb:used-not-dead, r=petrochenkov
Don't ever warn about #[used] items being dead code. Fixes #41628 by whitelisting `#[used]` items in `rustc::middle::dead`.
| -rw-r--r-- | src/librustc/middle/dead.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/issue-41628.rs | 17 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 622bf4dd0bd..84ead6506c8 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -283,6 +283,12 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool { return true; } + // #[used] also keeps the item alive forcefully, + // e.g. for placing it in a specific section. + if attr::contains_name(attrs, "used") { + return true; + } + let dead_code = lint::builtin::DEAD_CODE.name_lower(); for attr in lint::gather_attrs(attrs) { match attr { diff --git a/src/test/run-pass/issue-41628.rs b/src/test/run-pass/issue-41628.rs new file mode 100644 index 00000000000..cba47f98441 --- /dev/null +++ b/src/test/run-pass/issue-41628.rs @@ -0,0 +1,17 @@ +// 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. + +#![deny(dead_code)] +#![feature(used)] + +#[used] +static FOO: u32 = 0; + +fn main() {} |
