Skip to content

Commit 9435722

Browse files
committed
---
yaml --- r: 98055 b: refs/heads/master c: e64b49d h: refs/heads/master i: 98053: ad6b0a5 98051: e30578b 98047: 00729a7 v: v3
1 parent a928164 commit 9435722

File tree

5 files changed

+14
-86
lines changed

5 files changed

+14
-86
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f42440bd7384bbd8febeea0220ce777d1d802ec9
2+
refs/heads/master: e64b49d8ff530e313927a9385e947188a08adddf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b6400f998497c3958f40997a71756ead344a776d
55
refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36

trunk/src/librustc/middle/dead.rs

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@
1212
// closely. The idea is that all reachable symbols are live, codes called
1313
// from live codes are live, and everything else is dead.
1414

15-
use middle::lint::{allow, contains_lint, DeadCode};
16-
use middle::privacy;
1715
use middle::ty;
1816
use middle::typeck;
17+
use middle::privacy;
18+
use middle::lint::DeadCode;
1919

2020
use std::hashmap::HashSet;
2121
use syntax::ast;
2222
use syntax::ast_map;
2323
use syntax::ast_util::{local_def, def_id_of_def, is_local};
24-
use syntax::attr;
2524
use syntax::codemap;
2625
use syntax::parse::token;
2726
use syntax::visit::Visitor;
2827
use syntax::visit;
2928

30-
pub static DEAD_CODE_LINT_STR: &'static str = "dead_code";
31-
3229
// Any local node that may call something in its body block should be
3330
// explored. For example, if it's a live NodeItem that is a
3431
// function, then we should explore its block to check for codes that
@@ -199,57 +196,26 @@ impl Visitor<()> for MarkSymbolVisitor {
199196
}
200197
}
201198

202-
fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
203-
contains_lint(attrs, allow, DEAD_CODE_LINT_STR)
204-
|| attr::contains_name(attrs, "lang")
205-
}
206-
207-
// This visitor seeds items that
208-
// 1) We want to explicitly consider as live:
209-
// * Item annotated with #[allow(dead_code)]
210-
// - This is done so that if we want to suppress warnings for a
211-
// group of dead functions, we only have to annotate the "root".
212-
// For example, if both `f` and `g` are dead and `f` calls `g`,
213-
// then annotating `f` with `#[allow(dead_code)]` will suppress
214-
// warning for both `f` and `g`.
215-
// * Item annotated with #[lang=".."]
216-
// - This is because lang items are always callable from elsewhere.
217-
// or
218-
// 2) We are not sure to be live or not
219-
// * Implementation of a trait method
220-
struct LifeSeeder {
199+
// This visitor is used to mark the implemented methods of a trait. Since we
200+
// can not be sure if such methods are live or dead, we simply mark them
201+
// as live.
202+
struct TraitMethodSeeder {
221203
worklist: ~[ast::NodeId],
222204
}
223205

224-
impl Visitor<()> for LifeSeeder {
206+
impl Visitor<()> for TraitMethodSeeder {
225207
fn visit_item(&mut self, item: &ast::Item, _: ()) {
226-
if has_allow_dead_code_or_lang_attr(item.attrs) {
227-
self.worklist.push(item.id);
228-
}
229208
match item.node {
230209
ast::ItemImpl(_, Some(ref _trait_ref), _, ref methods) => {
231210
for method in methods.iter() {
232211
self.worklist.push(method.id);
233212
}
234213
}
235-
_ => ()
236-
}
237-
visit::walk_item(self, item, ());
238-
}
239-
240-
fn visit_fn(&mut self, fk: &visit::FnKind,
241-
_: &ast::FnDecl, block: &ast::Block,
242-
_: codemap::Span, id: ast::NodeId, _: ()) {
243-
// Check for method here because methods are not ast::Item
244-
match *fk {
245-
visit::FkMethod(_, _, method) => {
246-
if has_allow_dead_code_or_lang_attr(method.attrs) {
247-
self.worklist.push(id);
248-
}
214+
ast::ItemMod(..) | ast::ItemFn(..) => {
215+
visit::walk_item(self, item, ());
249216
}
250217
_ => ()
251218
}
252-
visit::walk_block(self, block, ());
253219
}
254220
}
255221

@@ -278,12 +244,12 @@ fn create_and_seed_worklist(tcx: ty::ctxt,
278244
}
279245

280246
// Seed implemeneted trait methods
281-
let mut life_seeder = LifeSeeder {
247+
let mut trait_method_seeder = TraitMethodSeeder {
282248
worklist: worklist
283249
};
284-
visit::walk_crate(&mut life_seeder, crate, ());
250+
visit::walk_crate(&mut trait_method_seeder, crate, ());
285251

286-
return life_seeder.worklist;
252+
return trait_method_seeder.worklist;
287253
}
288254

289255
fn find_live(tcx: ty::ctxt,

trunk/src/librustc/middle/lint.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
//! Context itself, span_lint should be used instead of add_lint.
3535
3636
use driver::session;
37-
use middle::dead::DEAD_CODE_LINT_STR;
3837
use middle::privacy;
3938
use middle::trans::adt; // for `adt::is_ffi_safe`
4039
use middle::ty;
@@ -294,7 +293,7 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
294293
default: warn
295294
}),
296295

297-
(DEAD_CODE_LINT_STR,
296+
("dead_code",
298297
LintSpec {
299298
lint: DeadCode,
300299
desc: "detect piece of code that will never be used",
@@ -532,8 +531,6 @@ impl<'a> Context<'a> {
532531
}
533532
}
534533

535-
// Check that every lint from the list of attributes satisfies `f`.
536-
// Return true if that's the case. Otherwise return false.
537534
pub fn each_lint(sess: session::Session,
538535
attrs: &[ast::Attribute],
539536
f: |@ast::MetaItem, level, @str| -> bool)
@@ -567,25 +564,6 @@ pub fn each_lint(sess: session::Session,
567564
true
568565
}
569566

570-
// Check from a list of attributes if it contains the appropriate
571-
// `#[level(lintname)]` attribute (e.g. `#[allow(dead_code)]).
572-
pub fn contains_lint(attrs: &[ast::Attribute],
573-
level: level, lintname: &'static str) -> bool {
574-
let level_name = level_to_str(level);
575-
for attr in attrs.iter().filter(|m| level_name == m.name()) {
576-
if attr.meta_item_list().is_none() {
577-
continue
578-
}
579-
let list = attr.meta_item_list().unwrap();
580-
for meta_item in list.iter() {
581-
if lintname == meta_item.name() {
582-
return true;
583-
}
584-
}
585-
}
586-
false
587-
}
588-
589567
fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
590568
match e.node {
591569
ast::ExprWhile(cond, _) => {

trunk/src/librustpkg/util.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ pub fn compile_input(context: &BuildContext,
185185
let csysroot = context.sysroot();
186186
debug!("compile_input's sysroot = {}", csysroot.display());
187187

188-
let crate_type = match what {
189-
Lib => session::OutputDylib,
190-
Test | Bench | Main => session::OutputExecutable,
191-
};
192188
let matches = getopts(debug_flags()
193189
+ match what {
194190
Lib => ~[~"--lib"],
@@ -230,7 +226,6 @@ pub fn compile_input(context: &BuildContext,
230226
debug!("Output type = {:?}", output_type);
231227

232228
let options = @session::options {
233-
outputs: ~[crate_type],
234229
optimize: opt,
235230
test: what == Test || what == Bench,
236231
maybe_sysroot: Some(sysroot_to_use),

trunk/src/test/compile-fail/lint-dead-code-1.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[no_std];
1211
#[allow(unused_variable)];
1312
#[deny(dead_code)];
1413

@@ -86,13 +85,3 @@ fn foo() { //~ ERROR: code is never used
8685
fn bar() { //~ ERROR: code is never used
8786
foo();
8887
}
89-
90-
// Code with #[allow(dead_code)] should be marked live (and thus anything it
91-
// calls is marked live)
92-
#[allow(dead_code)]
93-
fn g() { h(); }
94-
fn h() {}
95-
96-
// Similarly, lang items are live
97-
#[lang="fail_"]
98-
fn fail(_: *u8, _: *u8, _: uint) -> ! { loop {} }

0 commit comments

Comments
 (0)