// from live codes are live, and everything else is dead.
use dep_graph::DepNode;
-use front::map as ast_map;
-use rustc_front::hir::{self, PatKind};
-use rustc_front::intravisit::{self, Visitor};
-
-use middle::{pat_util, privacy, ty};
-use middle::def::Def;
-use middle::def_id::{DefId};
+use hir::map as ast_map;
+use hir::{self, pat_util, PatKind};
+use hir::intravisit::{self, Visitor};
+
+use middle::privacy;
+use ty::{self, TyCtxt};
+use hir::def::Def;
+use hir::def_id::{DefId};
use lint;
use std::collections::HashSet;
// explored. For example, if it's a live NodeItem that is a
// function, then we should explore its block to check for codes that
// may need to be marked as live.
-fn should_explore(tcx: &ty::ctxt, node_id: ast::NodeId) -> bool {
+fn should_explore(tcx: &TyCtxt, node_id: ast::NodeId) -> bool {
match tcx.map.find(node_id) {
Some(ast_map::NodeItem(..)) |
Some(ast_map::NodeImplItem(..)) |
struct MarkSymbolVisitor<'a, 'tcx: 'a> {
worklist: Vec<ast::NodeId>,
- tcx: &'a ty::ctxt<'tcx>,
+ tcx: &'a TyCtxt<'tcx>,
live_symbols: Box<HashSet<ast::NodeId>>,
struct_has_extern_repr: bool,
ignore_non_const_paths: bool,
}
impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
- fn new(tcx: &'a ty::ctxt<'tcx>,
+ fn new(tcx: &'a TyCtxt<'tcx>,
worklist: Vec<ast::NodeId>) -> MarkSymbolVisitor<'a, 'tcx> {
MarkSymbolVisitor {
worklist: worklist,
}
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
- use middle::ty::TypeVariants::{TyEnum, TyStruct};
+ use ty::TypeVariants::{TyEnum, TyStruct};
// If `bar` is a trait item, make sure to mark Foo as alive in `Foo::bar`
self.tcx.tables.borrow().item_substs.get(id)
if let ty::TyStruct(def, _) = self.tcx.expr_ty_adjusted(lhs).sty {
self.insert_def_id(def.struct_variant().field_named(name).did);
} else {
- self.tcx.sess.span_bug(lhs.span, "named field access on non-struct")
+ span_bug!(lhs.span, "named field access on non-struct")
}
}
let pat_ty = self.tcx.node_id_to_type(lhs.id);
let variant = match pat_ty.sty {
ty::TyStruct(adt, _) | ty::TyEnum(adt, _) => adt.variant_of_def(def),
- _ => self.tcx.sess.span_bug(lhs.span, "non-ADT in struct pattern")
+ _ => span_bug!(lhs.span, "non-ADT in struct pattern")
};
for pat in pats {
if let PatKind::Wild = pat.node.pat.node {
let has_extern_repr = self.struct_has_extern_repr;
let inherited_pub_visibility = self.inherited_pub_visibility;
let live_fields = def.fields().iter().filter(|f| {
- has_extern_repr || inherited_pub_visibility || match f.node.kind {
- hir::NamedField(_, hir::Public) => true,
- _ => false
- }
+ has_extern_repr || inherited_pub_visibility || f.vis == hir::Public
});
- self.live_symbols.extend(live_fields.map(|f| f.node.id));
+ self.live_symbols.extend(live_fields.map(|f| f.id));
intravisit::walk_struct_def(self, def);
}
}
hir::ItemImpl(_, _, _, ref opt_trait, _, ref impl_items) => {
for impl_item in impl_items {
- match impl_item.node {
- hir::ImplItemKind::Const(..) |
- hir::ImplItemKind::Method(..) => {
- if opt_trait.is_some() ||
- has_allow_dead_code_or_lang_attr(&impl_item.attrs) {
- self.worklist.push(impl_item.id);
- }
- }
- hir::ImplItemKind::Type(_) => {}
+ if opt_trait.is_some() ||
+ has_allow_dead_code_or_lang_attr(&impl_item.attrs) {
+ self.worklist.push(impl_item.id);
}
}
}
}
}
-fn create_and_seed_worklist(tcx: &ty::ctxt,
+fn create_and_seed_worklist(tcx: &TyCtxt,
access_levels: &privacy::AccessLevels,
krate: &hir::Crate) -> Vec<ast::NodeId> {
let mut worklist = Vec::new();
return life_seeder.worklist;
}
-fn find_live(tcx: &ty::ctxt,
+fn find_live(tcx: &TyCtxt,
access_levels: &privacy::AccessLevels,
krate: &hir::Crate)
-> Box<HashSet<ast::NodeId>> {
}
struct DeadVisitor<'a, 'tcx: 'a> {
- tcx: &'a ty::ctxt<'tcx>,
+ tcx: &'a TyCtxt<'tcx>,
live_symbols: Box<HashSet<ast::NodeId>>,
}
should_warn && !self.symbol_is_live(item.id, ctor_id)
}
- fn should_warn_about_field(&mut self, node: &hir::StructField_) -> bool {
- let is_named = node.name().is_some();
- let field_type = self.tcx.node_id_to_type(node.id);
+ fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
+ let field_type = self.tcx.node_id_to_type(field.id);
let is_marker_field = match field_type.ty_to_def_id() {
Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)),
_ => false
};
- is_named
- && !self.symbol_is_live(node.id, None)
+ !field.is_positional()
+ && !self.symbol_is_live(field.id, None)
&& !is_marker_field
- && !has_allow_dead_code_or_lang_attr(&node.attrs)
+ && !has_allow_dead_code_or_lang_attr(&field.attrs)
}
fn should_warn_about_variant(&mut self, variant: &hir::Variant_) -> bool {
}
fn visit_struct_field(&mut self, field: &hir::StructField) {
- if self.should_warn_about_field(&field.node) {
- self.warn_dead_code(field.node.id, field.span,
- field.node.name().unwrap(), "struct field");
+ if self.should_warn_about_field(&field) {
+ self.warn_dead_code(field.id, field.span,
+ field.name, "struct field");
}
intravisit::walk_struct_field(self, field);
}
}
-pub fn check_crate(tcx: &ty::ctxt, access_levels: &privacy::AccessLevels) {
+pub fn check_crate(tcx: &TyCtxt, access_levels: &privacy::AccessLevels) {
let _task = tcx.dep_graph.in_task(DepNode::DeadCheck);
let krate = tcx.map.krate();
let live_symbols = find_live(tcx, access_levels, krate);