From 8b0937293bdb70ab4a5efed02b90a71af2b234f6 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 29 Mar 2016 08:50:44 +0300 Subject: rustc: move rustc_front to rustc::hir. --- src/librustc_metadata/decoder.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/librustc_metadata/decoder.rs') diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index e85fdb05ca8..5aafd015f9a 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -22,10 +22,10 @@ use index; use tls_context; use tydecode::TyDecoder; -use rustc::back::svh::Svh; -use rustc::front::map as hir_map; +use rustc::hir::svh::Svh; +use rustc::hir::map as hir_map; use rustc::util::nodemap::FnvHashMap; -use rustc_front::hir; +use rustc::hir; use middle::cstore::{LOCAL_CRATE, FoundAst, InlinedItem, LinkagePreference}; use middle::cstore::{DefLike, DlDef, DlField, DlImpl, tls}; -- cgit 1.4.1-3-g733a5 From ffca6c3e155cb6033b1f749d0ba1be32dfc4d22a Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 29 Mar 2016 12:54:26 +0300 Subject: rustc: move middle::{def,def_id,pat_util} to hir. --- src/librustc/cfg/construct.rs | 4 +- src/librustc/dep_graph/mod.rs | 2 +- src/librustc/hir/def.rs | 176 +++++++++++++++ src/librustc/hir/def_id.rs | 88 ++++++++ src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/definitions.rs | 2 +- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 3 + src/librustc/hir/pat_util.rs | 246 +++++++++++++++++++++ src/librustc/infer/error_reporting.rs | 4 +- src/librustc/infer/mod.rs | 2 +- src/librustc/infer/type_variable.rs | 2 +- src/librustc/lib.rs | 3 - src/librustc/middle/astconv_util.rs | 2 +- src/librustc/middle/const_val.rs | 2 +- src/librustc/middle/cstore.rs | 6 +- src/librustc/middle/dead.rs | 8 +- src/librustc/middle/def.rs | 176 --------------- src/librustc/middle/def_id.rs | 88 -------- src/librustc/middle/effect.rs | 2 +- src/librustc/middle/entry.rs | 2 +- src/librustc/middle/expr_use_visitor.rs | 6 +- src/librustc/middle/intrinsicck.rs | 4 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/liveness.rs | 4 +- src/librustc/middle/mem_categorization.rs | 4 +- src/librustc/middle/pat_util.rs | 246 --------------------- src/librustc/middle/reachable.rs | 4 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/stability.rs | 4 +- src/librustc/mir/repr.rs | 2 +- src/librustc/mir/visit.rs | 2 +- src/librustc/traits/coherence.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/mod.rs | 2 +- src/librustc/traits/object_safety.rs | 2 +- src/librustc/traits/project.rs | 2 +- src/librustc/traits/select.rs | 2 +- src/librustc/traits/specialize/mod.rs | 2 +- .../traits/specialize/specialization_graph.rs | 2 +- src/librustc/traits/util.rs | 2 +- src/librustc/ty/contents.rs | 2 +- src/librustc/ty/context.rs | 4 +- src/librustc/ty/error.rs | 2 +- src/librustc/ty/fast_reject.rs | 2 +- src/librustc/ty/item_path.rs | 2 +- src/librustc/ty/maps.rs | 2 +- src/librustc/ty/mod.rs | 4 +- src/librustc/ty/relate.rs | 2 +- src/librustc/ty/sty.rs | 2 +- src/librustc/ty/subst.rs | 2 +- src/librustc/ty/trait_def.rs | 2 +- src/librustc/ty/util.rs | 4 +- src/librustc/ty/wf.rs | 2 +- src/librustc/util/nodemap.rs | 2 +- src/librustc/util/ppaux.rs | 2 +- src/librustc_borrowck/borrowck/fragments.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_const_eval/check_match.rs | 6 +- src/librustc_const_eval/eval.rs | 6 +- src/librustc_lint/bad_style.rs | 2 +- src/librustc_lint/builtin.rs | 4 +- src/librustc_lint/types.rs | 2 +- src/librustc_lint/unused.rs | 2 +- src/librustc_metadata/astencode.rs | 4 +- src/librustc_metadata/csearch.rs | 4 +- src/librustc_metadata/cstore.rs | 2 +- src/librustc_metadata/decoder.rs | 4 +- src/librustc_metadata/encoder.rs | 4 +- src/librustc_metadata/index.rs | 2 +- src/librustc_metadata/tls_context.rs | 2 +- src/librustc_metadata/tydecode.rs | 2 +- src/librustc_metadata/tyencode.rs | 2 +- src/librustc_mir/hair/cx/expr.rs | 4 +- src/librustc_mir/hair/cx/mod.rs | 2 +- src/librustc_mir/hair/cx/pattern.rs | 4 +- src/librustc_mir/hair/mod.rs | 2 +- src/librustc_passes/consts.rs | 4 +- src/librustc_passes/static_recursion.rs | 2 +- src/librustc_privacy/lib.rs | 4 +- src/librustc_resolve/build_reduced_graph.rs | 4 +- src/librustc_resolve/lib.rs | 8 +- src/librustc_resolve/resolve_imports.rs | 2 +- src/librustc_save_analysis/csv_dumper.rs | 2 +- src/librustc_save_analysis/data.rs | 2 +- src/librustc_save_analysis/dump_visitor.rs | 4 +- src/librustc_save_analysis/lib.rs | 4 +- src/librustc_trans/_match.rs | 6 +- src/librustc_trans/assert_dep_graph.rs | 2 +- src/librustc_trans/back/symbol_names.rs | 2 +- src/librustc_trans/base.rs | 4 +- src/librustc_trans/callee.rs | 2 +- src/librustc_trans/closure.rs | 2 +- src/librustc_trans/collector.rs | 2 +- src/librustc_trans/common.rs | 4 +- src/librustc_trans/consts.rs | 4 +- src/librustc_trans/context.rs | 4 +- src/librustc_trans/controlflow.rs | 2 +- src/librustc_trans/debuginfo/create_scope_map.rs | 2 +- src/librustc_trans/debuginfo/metadata.rs | 4 +- src/librustc_trans/debuginfo/mod.rs | 2 +- src/librustc_trans/debuginfo/namespace.rs | 2 +- src/librustc_trans/debuginfo/type_names.rs | 2 +- src/librustc_trans/debuginfo/utils.rs | 2 +- src/librustc_trans/expr.rs | 2 +- src/librustc_trans/inline.rs | 2 +- src/librustc_trans/meth.rs | 2 +- src/librustc_trans/monomorphize.rs | 2 +- src/librustc_trans/type_of.rs | 2 +- src/librustc_typeck/astconv.rs | 4 +- src/librustc_typeck/check/_match.rs | 6 +- src/librustc_typeck/check/callee.rs | 4 +- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/check/dropck.rs | 2 +- src/librustc_typeck/check/method/confirm.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 4 +- src/librustc_typeck/check/method/probe.rs | 4 +- src/librustc_typeck/check/method/suggest.rs | 4 +- src/librustc_typeck/check/mod.rs | 6 +- src/librustc_typeck/check/op.rs | 2 +- src/librustc_typeck/check/regionck.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/check/writeback.rs | 4 +- src/librustc_typeck/coherence/mod.rs | 2 +- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/coherence/overlap.rs | 2 +- src/librustc_typeck/collect.rs | 4 +- src/librustc_typeck/lib.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustdoc/clean/inline.rs | 4 +- src/librustdoc/clean/mod.rs | 4 +- src/librustdoc/clean/simplify.rs | 2 +- src/librustdoc/core.rs | 2 +- src/librustdoc/html/format.rs | 2 +- src/librustdoc/html/render.rs | 2 +- src/librustdoc/passes.rs | 2 +- 136 files changed, 697 insertions(+), 697 deletions(-) create mode 100644 src/librustc/hir/def.rs create mode 100644 src/librustc/hir/def_id.rs create mode 100644 src/librustc/hir/pat_util.rs delete mode 100644 src/librustc/middle/def.rs delete mode 100644 src/librustc/middle/def_id.rs delete mode 100644 src/librustc/middle/pat_util.rs (limited to 'src/librustc_metadata/decoder.rs') diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 13c3e3895b5..70497491355 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -10,8 +10,8 @@ use rustc_data_structures::graph; use cfg::*; -use middle::def::Def; -use middle::pat_util; +use hir::def::Def; +use hir::pat_util; use ty::{self, TyCtxt}; use syntax::ast; use syntax::ptr::P; diff --git a/src/librustc/dep_graph/mod.rs b/src/librustc/dep_graph/mod.rs index 70e7f675fce..55ec56a4bbe 100644 --- a/src/librustc/dep_graph/mod.rs +++ b/src/librustc/dep_graph/mod.rs @@ -9,7 +9,7 @@ // except according to those terms. use self::thread::{DepGraphThreadData, DepMessage}; -use middle::def_id::DefId; +use hir::def_id::DefId; use syntax::ast::NodeId; use ty::TyCtxt; use hir; diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs new file mode 100644 index 00000000000..c270a4413bf --- /dev/null +++ b/src/librustc/hir/def.rs @@ -0,0 +1,176 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use hir::def_id::DefId; +use ty::subst::ParamSpace; +use util::nodemap::NodeMap; +use syntax::ast; +use hir; + +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub enum Def { + Fn(DefId), + SelfTy(Option, // trait id + Option<(ast::NodeId, ast::NodeId)>), // (impl id, self type id) + Mod(DefId), + ForeignMod(DefId), + Static(DefId, bool /* is_mutbl */), + Const(DefId), + AssociatedConst(DefId), + Local(DefId, // def id of variable + ast::NodeId), // node id of variable + Variant(DefId /* enum */, DefId /* variant */), + Enum(DefId), + TyAlias(DefId), + AssociatedTy(DefId /* trait */, DefId), + Trait(DefId), + PrimTy(hir::PrimTy), + TyParam(ParamSpace, u32, DefId, ast::Name), + Upvar(DefId, // def id of closed over local + ast::NodeId, // node id of closed over local + usize, // index in the freevars list of the closure + ast::NodeId), // expr node that creates the closure + + // If Def::Struct lives in type namespace it denotes a struct item and its DefId refers + // to NodeId of the struct itself. + // If Def::Struct lives in value namespace (e.g. tuple struct, unit struct expressions) + // it denotes a constructor and its DefId refers to NodeId of the struct's constructor. + Struct(DefId), + Label(ast::NodeId), + Method(DefId), + Err, +} + +/// The result of resolving a path. +/// Before type checking completes, `depth` represents the number of +/// trailing segments which are yet unresolved. Afterwards, if there +/// were no errors, all paths should be fully resolved, with `depth` +/// set to `0` and `base_def` representing the final resolution. +/// +/// module::Type::AssocX::AssocY::MethodOrAssocType +/// ^~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/// base_def depth = 3 +/// +/// ::AssocX::AssocY::MethodOrAssocType +/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~ +/// base_def depth = 2 +#[derive(Copy, Clone, Debug)] +pub struct PathResolution { + pub base_def: Def, + pub depth: usize +} + +impl PathResolution { + /// Get the definition, if fully resolved, otherwise panic. + pub fn full_def(&self) -> Def { + if self.depth != 0 { + bug!("path not fully resolved: {:?}", self); + } + self.base_def + } + + /// Get the DefId, if fully resolved, otherwise panic. + pub fn def_id(&self) -> DefId { + self.full_def().def_id() + } + + pub fn new(base_def: Def, + depth: usize) + -> PathResolution { + PathResolution { + base_def: base_def, + depth: depth, + } + } +} + +// Definition mapping +pub type DefMap = NodeMap; +// This is the replacement export map. It maps a module to all of the exports +// within. +pub type ExportMap = NodeMap>; + +#[derive(Copy, Clone)] +pub struct Export { + pub name: ast::Name, // The name of the target. + pub def_id: DefId, // The definition of the target. +} + +impl Def { + pub fn var_id(&self) -> ast::NodeId { + match *self { + Def::Local(_, id) | + Def::Upvar(_, id, _, _) => { + id + } + + Def::Fn(..) | Def::Mod(..) | Def::ForeignMod(..) | Def::Static(..) | + Def::Variant(..) | Def::Enum(..) | Def::TyAlias(..) | Def::AssociatedTy(..) | + Def::TyParam(..) | Def::Struct(..) | Def::Trait(..) | + Def::Method(..) | Def::Const(..) | Def::AssociatedConst(..) | + Def::PrimTy(..) | Def::Label(..) | Def::SelfTy(..) | Def::Err => { + bug!("attempted .var_id() on invalid {:?}", self) + } + } + } + + pub fn def_id(&self) -> DefId { + match *self { + Def::Fn(id) | Def::Mod(id) | Def::ForeignMod(id) | Def::Static(id, _) | + Def::Variant(_, id) | Def::Enum(id) | Def::TyAlias(id) | Def::AssociatedTy(_, id) | + Def::TyParam(_, _, id, _) | Def::Struct(id) | Def::Trait(id) | + Def::Method(id) | Def::Const(id) | Def::AssociatedConst(id) | + Def::Local(id, _) | Def::Upvar(id, _, _, _) => { + id + } + + Def::Label(..) | + Def::PrimTy(..) | + Def::SelfTy(..) | + Def::Err => { + bug!("attempted .def_id() on invalid def: {:?}", self) + } + } + } + + pub fn variant_def_ids(&self) -> Option<(DefId, DefId)> { + match *self { + Def::Variant(enum_id, var_id) => { + Some((enum_id, var_id)) + } + _ => None + } + } + + pub fn kind_name(&self) -> &'static str { + match *self { + Def::Fn(..) => "function", + Def::Mod(..) => "module", + Def::ForeignMod(..) => "foreign module", + Def::Static(..) => "static", + Def::Variant(..) => "variant", + Def::Enum(..) => "enum", + Def::TyAlias(..) => "type", + Def::AssociatedTy(..) => "associated type", + Def::Struct(..) => "struct", + Def::Trait(..) => "trait", + Def::Method(..) => "method", + Def::Const(..) => "const", + Def::AssociatedConst(..) => "associated const", + Def::TyParam(..) => "type parameter", + Def::PrimTy(..) => "builtin type", + Def::Local(..) => "local variable", + Def::Upvar(..) => "closure capture", + Def::Label(..) => "label", + Def::SelfTy(..) => "self type", + Def::Err => "unresolved item", + } + } +} diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs new file mode 100644 index 00000000000..a3b83ec5be4 --- /dev/null +++ b/src/librustc/hir/def_id.rs @@ -0,0 +1,88 @@ +// Copyright 2012-2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use middle::cstore::LOCAL_CRATE; +use ty; +use syntax::ast::CrateNum; +use std::fmt; +use std::u32; + +/// A DefIndex is an index into the hir-map for a crate, identifying a +/// particular definition. It should really be considered an interned +/// shorthand for a particular DefPath. +#[derive(Clone, Debug, Eq, Ord, PartialOrd, PartialEq, RustcEncodable, + RustcDecodable, Hash, Copy)] +pub struct DefIndex(u32); + +impl DefIndex { + pub fn new(x: usize) -> DefIndex { + assert!(x < (u32::MAX as usize)); + DefIndex(x as u32) + } + + pub fn from_u32(x: u32) -> DefIndex { + DefIndex(x) + } + + pub fn as_usize(&self) -> usize { + self.0 as usize + } + + pub fn as_u32(&self) -> u32 { + self.0 + } +} + +/// The crate root is always assigned index 0 by the AST Map code, +/// thanks to `NodeCollector::new`. +pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0); + +/// A DefId identifies a particular *definition*, by combining a crate +/// index and a def index. +#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable, + RustcDecodable, Hash, Copy)] +pub struct DefId { + pub krate: CrateNum, + pub index: DefIndex, +} + +impl fmt::Debug for DefId { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "DefId {{ krate: {:?}, node: {:?}", + self.krate, self.index)?; + + // Unfortunately, there seems to be no way to attempt to print + // a path for a def-id, so I'll just make a best effort for now + // and otherwise fallback to just printing the crate/node pair + if self.is_local() { // (1) + // (1) side-step fact that not all external things have paths at + // the moment, such as type parameters + ty::tls::with_opt(|opt_tcx| { + if let Some(tcx) = opt_tcx { + write!(f, " => {}", tcx.item_path_str(*self))?; + } + Ok(()) + })?; + } + + write!(f, " }}") + } +} + + +impl DefId { + pub fn local(index: DefIndex) -> DefId { + DefId { krate: LOCAL_CRATE, index: index } + } + + pub fn is_local(&self) -> bool { + self.krate == LOCAL_CRATE + } +} diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 62c80c9c8bb..b1a084ac799 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -13,7 +13,7 @@ use super::MapEntry::*; use hir::*; use hir::intravisit::Visitor; -use middle::def_id::{CRATE_DEF_INDEX, DefId, DefIndex}; +use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex}; use std::iter::repeat; use syntax::ast::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID}; use syntax::codemap::Span; diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 82574b85229..d045313cb1e 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -9,7 +9,7 @@ // except according to those terms. use middle::cstore::LOCAL_CRATE; -use middle::def_id::{DefId, DefIndex}; +use hir::def_id::{DefId, DefIndex}; use rustc_data_structures::fnv::FnvHashMap; use syntax::ast; use syntax::parse::token::InternedString; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 4325be9b9a4..4096606b001 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -19,7 +19,7 @@ use dep_graph::{DepGraph, DepNode}; use middle::cstore::InlinedItem; use middle::cstore::InlinedItem as II; -use middle::def_id::{CRATE_DEF_INDEX, DefId}; +use hir::def_id::{CRATE_DEF_INDEX, DefId}; use syntax::abi::Abi; use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID}; diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index cb3cdd0b825..10fe86246de 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -63,10 +63,13 @@ macro_rules! hir_vec { } pub mod check_attr; +pub mod def; +pub mod def_id; pub mod fold; pub mod intravisit; pub mod lowering; pub mod map; +pub mod pat_util; pub mod print; pub mod svh; diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs new file mode 100644 index 00000000000..5eb4d53ea6a --- /dev/null +++ b/src/librustc/hir/pat_util.rs @@ -0,0 +1,246 @@ +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use hir::def::*; +use hir::def_id::DefId; +use ty::TyCtxt; +use util::nodemap::FnvHashMap; + +use syntax::ast; +use hir::{self, PatKind}; +use syntax::codemap::{respan, Span, Spanned, DUMMY_SP}; + +use std::cell::RefCell; + +pub type PatIdMap = FnvHashMap; + +// This is used because same-named variables in alternative patterns need to +// use the NodeId of their namesake in the first pattern. +pub fn pat_id_map(dm: &RefCell, pat: &hir::Pat) -> PatIdMap { + let mut map = FnvHashMap(); + pat_bindings(dm, pat, |_bm, p_id, _s, path1| { + map.insert(path1.node, p_id); + }); + map +} + +pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool { + match pat.node { + PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::QPath(..) => true, + PatKind::TupleStruct(..) | + PatKind::Path(..) | + PatKind::Ident(_, _, None) | + PatKind::Struct(..) => { + match dm.get(&pat.id).map(|d| d.full_def()) { + Some(Def::Variant(..)) => true, + _ => false + } + } + PatKind::Vec(_, _, _) => true, + _ => false + } +} + +pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool { + match pat.node { + PatKind::TupleStruct(..) | + PatKind::Path(..) | + PatKind::Ident(_, _, None) | + PatKind::Struct(..) => { + match dm.get(&pat.id).map(|d| d.full_def()) { + Some(Def::Variant(..)) | Some(Def::Struct(..)) | Some(Def::TyAlias(..)) => true, + _ => false + } + } + _ => false + } +} + +pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool { + match pat.node { + PatKind::Ident(_, _, None) | PatKind::Path(..) | PatKind::QPath(..) => { + match dm.get(&pat.id).map(|d| d.full_def()) { + Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true, + _ => false + } + } + _ => false + } +} + +// Same as above, except that partially-resolved defs cause `false` to be +// returned instead of a panic. +pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool { + match pat.node { + PatKind::Ident(_, _, None) | PatKind::Path(..) | PatKind::QPath(..) => { + match dm.get(&pat.id) + .and_then(|d| if d.depth == 0 { Some(d.base_def) } + else { None } ) { + Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true, + _ => false + } + } + _ => false + } +} + +pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool { + match pat.node { + PatKind::Ident(..) => { + !pat_is_variant_or_struct(dm, pat) && + !pat_is_const(dm, pat) + } + _ => false + } +} + +pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool { + match pat.node { + PatKind::Ident(..) => pat_is_binding(dm, pat), + PatKind::Wild => true, + _ => false + } +} + +/// Call `it` on every "binding" in a pattern, e.g., on `a` in +/// `match foo() { Some(a) => (), None => () }` +pub fn pat_bindings(dm: &RefCell, pat: &hir::Pat, mut it: I) where + I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned), +{ + pat.walk(|p| { + match p.node { + PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => { + it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name)); + } + _ => {} + } + true + }); +} +pub fn pat_bindings_ident(dm: &RefCell, pat: &hir::Pat, mut it: I) where + I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned), +{ + pat.walk(|p| { + match p.node { + PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => { + it(binding_mode, p.id, p.span, &respan(pth.span, pth.node)); + } + _ => {} + } + true + }); +} + +/// Checks if the pattern contains any patterns that bind something to +/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`. +pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool { + let mut contains_bindings = false; + pat.walk(|p| { + if pat_is_binding(dm, p) { + contains_bindings = true; + false // there's at least one binding, can short circuit now. + } else { + true + } + }); + contains_bindings +} + +/// Checks if the pattern contains any `ref` or `ref mut` bindings, +/// and if yes whether its containing mutable ones or just immutables ones. +pub fn pat_contains_ref_binding(dm: &RefCell, pat: &hir::Pat) -> Option { + let mut result = None; + pat_bindings(dm, pat, |mode, _, _, _| { + match mode { + hir::BindingMode::BindByRef(m) => { + // Pick Mutable as maximum + match result { + None | Some(hir::MutImmutable) => result = Some(m), + _ => (), + } + } + hir::BindingMode::BindByValue(_) => { } + } + }); + result +} + +/// Checks if the patterns for this arm contain any `ref` or `ref mut` +/// bindings, and if yes whether its containing mutable ones or just immutables ones. +pub fn arm_contains_ref_binding(dm: &RefCell, arm: &hir::Arm) -> Option { + arm.pats.iter() + .filter_map(|pat| pat_contains_ref_binding(dm, pat)) + .max_by_key(|m| match *m { + hir::MutMutable => 1, + hir::MutImmutable => 0, + }) +} + +/// Checks if the pattern contains any patterns that bind something to +/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`, +pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool { + let mut contains_bindings = false; + pat.walk(|p| { + if pat_is_binding_or_wild(dm, p) { + contains_bindings = true; + false // there's at least one binding/wildcard, can short circuit now. + } else { + true + } + }); + contains_bindings +} + +pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option { + match pat.node { + PatKind::Ident(hir::BindByValue(_), ref path1, None) => { + Some(path1.node.name) + } + _ => { + None + } + } +} + +pub fn def_to_path(tcx: &TyCtxt, id: DefId) -> hir::Path { + tcx.with_path(id, |path| hir::Path { + global: false, + segments: path.last().map(|elem| hir::PathSegment { + identifier: hir::Ident::from_name(elem.name()), + parameters: hir::PathParameters::none(), + }).into_iter().collect(), + span: DUMMY_SP, + }) +} + +/// Return variants that are necessary to exist for the pattern to match. +pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec { + let mut variants = vec![]; + pat.walk(|p| { + match p.node { + PatKind::TupleStruct(..) | + PatKind::Path(..) | + PatKind::Ident(_, _, None) | + PatKind::Struct(..) => { + match dm.get(&p.id) { + Some(&PathResolution { base_def: Def::Variant(_, id), .. }) => { + variants.push(id); + } + _ => () + } + } + _ => () + } + true + }); + variants.sort(); + variants.dedup(); + variants +} diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index c0c63ac5042..5a0d9ec1332 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -78,8 +78,8 @@ use hir; use hir::print as pprust; use middle::cstore::CrateStore; -use middle::def::Def; -use middle::def_id::DefId; +use hir::def::Def; +use hir::def_id::DefId; use infer::{self, TypeOrigin}; use middle::region; use ty::subst; diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 427ff88b8f2..4c1216aa862 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -18,7 +18,7 @@ pub use ty::IntVarValue; pub use self::freshen::TypeFreshener; pub use self::region_inference::{GenericKind, VerifyBound}; -use middle::def_id::DefId; +use hir::def_id::DefId; use hir; use middle::free_region::FreeRegionMap; use middle::mem_categorization as mc; diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 3cc076f1f00..c2a8d04ac00 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -11,7 +11,7 @@ pub use self::RelationDir::*; use self::TypeVariableValue::*; use self::UndoEntry::*; -use middle::def_id::{DefId}; +use hir::def_id::{DefId}; use ty::{self, Ty}; use syntax::codemap::Span; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 291eab30dec..deb20627772 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -86,8 +86,6 @@ pub mod middle { pub mod cstore; pub mod dataflow; pub mod dead; - pub mod def; - pub mod def_id; pub mod dependency_format; pub mod effect; pub mod entry; @@ -96,7 +94,6 @@ pub mod middle { pub mod lang_items; pub mod liveness; pub mod mem_categorization; - pub mod pat_util; pub mod privacy; pub mod reachable; pub mod region; diff --git a/src/librustc/middle/astconv_util.rs b/src/librustc/middle/astconv_util.rs index 871440a7e54..2a27732b953 100644 --- a/src/librustc/middle/astconv_util.rs +++ b/src/librustc/middle/astconv_util.rs @@ -14,7 +14,7 @@ * Almost certainly this could (and should) be refactored out of existence. */ -use middle::def::Def; +use hir::def::Def; use ty::{Ty, TyCtxt}; use syntax::codemap::Span; diff --git a/src/librustc/middle/const_val.rs b/src/librustc/middle/const_val.rs index a939389c460..3621cb267d9 100644 --- a/src/librustc/middle/const_val.rs +++ b/src/librustc/middle/const_val.rs @@ -11,7 +11,7 @@ use syntax::parse::token::InternedString; use syntax::ast; use std::rc::Rc; -use middle::def_id::DefId; +use hir::def_id::DefId; use std::hash; use std::mem::transmute; use rustc_const_math::*; diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index a7f415ef2a0..027792b7439 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -24,10 +24,10 @@ use hir::svh::Svh; use hir::map as hir_map; -use middle::def::{self, Def}; +use hir::def::{self, Def}; use middle::lang_items; use ty::{self, Ty, TyCtxt, VariantKind}; -use middle::def_id::{DefId, DefIndex}; +use hir::def_id::{DefId, DefIndex}; use mir::repr::Mir; use mir::mir_map::MirMap; use session::Session; @@ -504,7 +504,7 @@ pub mod tls { use std::mem; use ty::{self, Ty, TyCtxt}; use ty::subst::Substs; - use middle::def_id::DefId; + use hir::def_id::DefId; pub trait EncodingContext<'tcx> { fn tcx<'a>(&'a self) -> &'a TyCtxt<'tcx>; diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index b7b6279270c..dcdc02c9df6 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -14,13 +14,13 @@ use dep_graph::DepNode; use hir::map as ast_map; -use hir::{self, PatKind}; +use hir::{self, pat_util, PatKind}; use hir::intravisit::{self, Visitor}; -use middle::{pat_util, privacy}; +use middle::privacy; use ty::{self, TyCtxt}; -use middle::def::Def; -use middle::def_id::{DefId}; +use hir::def::Def; +use hir::def_id::{DefId}; use lint; use std::collections::HashSet; diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs deleted file mode 100644 index ee6e747a855..00000000000 --- a/src/librustc/middle/def.rs +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use middle::def_id::DefId; -use ty::subst::ParamSpace; -use util::nodemap::NodeMap; -use syntax::ast; -use hir; - -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Def { - Fn(DefId), - SelfTy(Option, // trait id - Option<(ast::NodeId, ast::NodeId)>), // (impl id, self type id) - Mod(DefId), - ForeignMod(DefId), - Static(DefId, bool /* is_mutbl */), - Const(DefId), - AssociatedConst(DefId), - Local(DefId, // def id of variable - ast::NodeId), // node id of variable - Variant(DefId /* enum */, DefId /* variant */), - Enum(DefId), - TyAlias(DefId), - AssociatedTy(DefId /* trait */, DefId), - Trait(DefId), - PrimTy(hir::PrimTy), - TyParam(ParamSpace, u32, DefId, ast::Name), - Upvar(DefId, // def id of closed over local - ast::NodeId, // node id of closed over local - usize, // index in the freevars list of the closure - ast::NodeId), // expr node that creates the closure - - // If Def::Struct lives in type namespace it denotes a struct item and its DefId refers - // to NodeId of the struct itself. - // If Def::Struct lives in value namespace (e.g. tuple struct, unit struct expressions) - // it denotes a constructor and its DefId refers to NodeId of the struct's constructor. - Struct(DefId), - Label(ast::NodeId), - Method(DefId), - Err, -} - -/// The result of resolving a path. -/// Before type checking completes, `depth` represents the number of -/// trailing segments which are yet unresolved. Afterwards, if there -/// were no errors, all paths should be fully resolved, with `depth` -/// set to `0` and `base_def` representing the final resolution. -/// -/// module::Type::AssocX::AssocY::MethodOrAssocType -/// ^~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/// base_def depth = 3 -/// -/// ::AssocX::AssocY::MethodOrAssocType -/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~ -/// base_def depth = 2 -#[derive(Copy, Clone, Debug)] -pub struct PathResolution { - pub base_def: Def, - pub depth: usize -} - -impl PathResolution { - /// Get the definition, if fully resolved, otherwise panic. - pub fn full_def(&self) -> Def { - if self.depth != 0 { - bug!("path not fully resolved: {:?}", self); - } - self.base_def - } - - /// Get the DefId, if fully resolved, otherwise panic. - pub fn def_id(&self) -> DefId { - self.full_def().def_id() - } - - pub fn new(base_def: Def, - depth: usize) - -> PathResolution { - PathResolution { - base_def: base_def, - depth: depth, - } - } -} - -// Definition mapping -pub type DefMap = NodeMap; -// This is the replacement export map. It maps a module to all of the exports -// within. -pub type ExportMap = NodeMap>; - -#[derive(Copy, Clone)] -pub struct Export { - pub name: ast::Name, // The name of the target. - pub def_id: DefId, // The definition of the target. -} - -impl Def { - pub fn var_id(&self) -> ast::NodeId { - match *self { - Def::Local(_, id) | - Def::Upvar(_, id, _, _) => { - id - } - - Def::Fn(..) | Def::Mod(..) | Def::ForeignMod(..) | Def::Static(..) | - Def::Variant(..) | Def::Enum(..) | Def::TyAlias(..) | Def::AssociatedTy(..) | - Def::TyParam(..) | Def::Struct(..) | Def::Trait(..) | - Def::Method(..) | Def::Const(..) | Def::AssociatedConst(..) | - Def::PrimTy(..) | Def::Label(..) | Def::SelfTy(..) | Def::Err => { - bug!("attempted .var_id() on invalid {:?}", self) - } - } - } - - pub fn def_id(&self) -> DefId { - match *self { - Def::Fn(id) | Def::Mod(id) | Def::ForeignMod(id) | Def::Static(id, _) | - Def::Variant(_, id) | Def::Enum(id) | Def::TyAlias(id) | Def::AssociatedTy(_, id) | - Def::TyParam(_, _, id, _) | Def::Struct(id) | Def::Trait(id) | - Def::Method(id) | Def::Const(id) | Def::AssociatedConst(id) | - Def::Local(id, _) | Def::Upvar(id, _, _, _) => { - id - } - - Def::Label(..) | - Def::PrimTy(..) | - Def::SelfTy(..) | - Def::Err => { - bug!("attempted .def_id() on invalid def: {:?}", self) - } - } - } - - pub fn variant_def_ids(&self) -> Option<(DefId, DefId)> { - match *self { - Def::Variant(enum_id, var_id) => { - Some((enum_id, var_id)) - } - _ => None - } - } - - pub fn kind_name(&self) -> &'static str { - match *self { - Def::Fn(..) => "function", - Def::Mod(..) => "module", - Def::ForeignMod(..) => "foreign module", - Def::Static(..) => "static", - Def::Variant(..) => "variant", - Def::Enum(..) => "enum", - Def::TyAlias(..) => "type", - Def::AssociatedTy(..) => "associated type", - Def::Struct(..) => "struct", - Def::Trait(..) => "trait", - Def::Method(..) => "method", - Def::Const(..) => "const", - Def::AssociatedConst(..) => "associated const", - Def::TyParam(..) => "type parameter", - Def::PrimTy(..) => "builtin type", - Def::Local(..) => "local variable", - Def::Upvar(..) => "closure capture", - Def::Label(..) => "label", - Def::SelfTy(..) => "self type", - Def::Err => "unresolved item", - } - } -} diff --git a/src/librustc/middle/def_id.rs b/src/librustc/middle/def_id.rs deleted file mode 100644 index a3b83ec5be4..00000000000 --- a/src/librustc/middle/def_id.rs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2012-2015 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use middle::cstore::LOCAL_CRATE; -use ty; -use syntax::ast::CrateNum; -use std::fmt; -use std::u32; - -/// A DefIndex is an index into the hir-map for a crate, identifying a -/// particular definition. It should really be considered an interned -/// shorthand for a particular DefPath. -#[derive(Clone, Debug, Eq, Ord, PartialOrd, PartialEq, RustcEncodable, - RustcDecodable, Hash, Copy)] -pub struct DefIndex(u32); - -impl DefIndex { - pub fn new(x: usize) -> DefIndex { - assert!(x < (u32::MAX as usize)); - DefIndex(x as u32) - } - - pub fn from_u32(x: u32) -> DefIndex { - DefIndex(x) - } - - pub fn as_usize(&self) -> usize { - self.0 as usize - } - - pub fn as_u32(&self) -> u32 { - self.0 - } -} - -/// The crate root is always assigned index 0 by the AST Map code, -/// thanks to `NodeCollector::new`. -pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0); - -/// A DefId identifies a particular *definition*, by combining a crate -/// index and a def index. -#[derive(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable, - RustcDecodable, Hash, Copy)] -pub struct DefId { - pub krate: CrateNum, - pub index: DefIndex, -} - -impl fmt::Debug for DefId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "DefId {{ krate: {:?}, node: {:?}", - self.krate, self.index)?; - - // Unfortunately, there seems to be no way to attempt to print - // a path for a def-id, so I'll just make a best effort for now - // and otherwise fallback to just printing the crate/node pair - if self.is_local() { // (1) - // (1) side-step fact that not all external things have paths at - // the moment, such as type parameters - ty::tls::with_opt(|opt_tcx| { - if let Some(tcx) = opt_tcx { - write!(f, " => {}", tcx.item_path_str(*self))?; - } - Ok(()) - })?; - } - - write!(f, " }}") - } -} - - -impl DefId { - pub fn local(index: DefIndex) -> DefId { - DefId { krate: LOCAL_CRATE, index: index } - } - - pub fn is_local(&self) -> bool { - self.krate == LOCAL_CRATE - } -} diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index e4c93dfdb93..ac7a1b8aa0d 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -13,7 +13,7 @@ use self::RootUnsafeContext::*; use dep_graph::DepNode; -use middle::def::Def; +use hir::def::Def; use ty::{self, Ty, TyCtxt}; use ty::MethodCall; diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 4a64980fcdd..602889375e9 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -11,7 +11,7 @@ use dep_graph::DepNode; use hir::map as ast_map; -use middle::def_id::{CRATE_DEF_INDEX}; +use hir::def_id::{CRATE_DEF_INDEX}; use session::{config, Session}; use syntax::ast::NodeId; use syntax::attr; diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 1b967377304..c4d6f100671 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -19,9 +19,9 @@ pub use self::MatchMode::*; use self::TrackMatchMode::*; use self::OverloadedCallType::*; -use middle::pat_util; -use middle::def::Def; -use middle::def_id::{DefId}; +use hir::pat_util; +use hir::def::Def; +use hir::def_id::{DefId}; use infer; use middle::mem_categorization as mc; use ty::{self, TyCtxt, adjustment}; diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 354a6c5e13b..767c5adc81e 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -9,8 +9,8 @@ // except according to those terms. use dep_graph::DepNode; -use middle::def::Def; -use middle::def_id::DefId; +use hir::def::Def; +use hir::def_id::DefId; use ty::subst::{Subst, Substs, EnumeratedItems}; use ty::{TransmuteRestriction, TyCtxt}; use ty::{self, Ty, TypeFoldable}; diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 7aad106c4ed..86531ced8df 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -25,7 +25,7 @@ use dep_graph::DepNode; use hir::map as hir_map; use session::Session; use middle::cstore::CrateStore; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty; use middle::weak_lang_items; use util::nodemap::FnvHashMap; diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 72d3c9414a4..35991ae56c8 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -110,8 +110,8 @@ use self::LiveNodeKind::*; use self::VarKind::*; use dep_graph::DepNode; -use middle::def::*; -use middle::pat_util; +use hir::def::*; +use hir::pat_util; use ty::{self, TyCtxt, ParameterEnvironment}; use traits::{self, ProjectionMode}; use infer; diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 7260bdde3ee..2f77552c389 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -71,11 +71,11 @@ pub use self::deref_kind::*; use self::Aliasability::*; -use middle::def_id::DefId; +use hir::def_id::DefId; use hir::map as ast_map; use infer; use middle::const_qualif::ConstQualif; -use middle::def::Def; +use hir::def::Def; use ty::adjustment; use ty::{self, Ty, TyCtxt}; diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs deleted file mode 100644 index 3c60d544228..00000000000 --- a/src/librustc/middle/pat_util.rs +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use middle::def::*; -use middle::def_id::DefId; -use ty::TyCtxt; -use util::nodemap::FnvHashMap; - -use syntax::ast; -use hir::{self, PatKind}; -use syntax::codemap::{respan, Span, Spanned, DUMMY_SP}; - -use std::cell::RefCell; - -pub type PatIdMap = FnvHashMap; - -// This is used because same-named variables in alternative patterns need to -// use the NodeId of their namesake in the first pattern. -pub fn pat_id_map(dm: &RefCell, pat: &hir::Pat) -> PatIdMap { - let mut map = FnvHashMap(); - pat_bindings(dm, pat, |_bm, p_id, _s, path1| { - map.insert(path1.node, p_id); - }); - map -} - -pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool { - match pat.node { - PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::QPath(..) => true, - PatKind::TupleStruct(..) | - PatKind::Path(..) | - PatKind::Ident(_, _, None) | - PatKind::Struct(..) => { - match dm.get(&pat.id).map(|d| d.full_def()) { - Some(Def::Variant(..)) => true, - _ => false - } - } - PatKind::Vec(_, _, _) => true, - _ => false - } -} - -pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool { - match pat.node { - PatKind::TupleStruct(..) | - PatKind::Path(..) | - PatKind::Ident(_, _, None) | - PatKind::Struct(..) => { - match dm.get(&pat.id).map(|d| d.full_def()) { - Some(Def::Variant(..)) | Some(Def::Struct(..)) | Some(Def::TyAlias(..)) => true, - _ => false - } - } - _ => false - } -} - -pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool { - match pat.node { - PatKind::Ident(_, _, None) | PatKind::Path(..) | PatKind::QPath(..) => { - match dm.get(&pat.id).map(|d| d.full_def()) { - Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true, - _ => false - } - } - _ => false - } -} - -// Same as above, except that partially-resolved defs cause `false` to be -// returned instead of a panic. -pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool { - match pat.node { - PatKind::Ident(_, _, None) | PatKind::Path(..) | PatKind::QPath(..) => { - match dm.get(&pat.id) - .and_then(|d| if d.depth == 0 { Some(d.base_def) } - else { None } ) { - Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true, - _ => false - } - } - _ => false - } -} - -pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool { - match pat.node { - PatKind::Ident(..) => { - !pat_is_variant_or_struct(dm, pat) && - !pat_is_const(dm, pat) - } - _ => false - } -} - -pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool { - match pat.node { - PatKind::Ident(..) => pat_is_binding(dm, pat), - PatKind::Wild => true, - _ => false - } -} - -/// Call `it` on every "binding" in a pattern, e.g., on `a` in -/// `match foo() { Some(a) => (), None => () }` -pub fn pat_bindings(dm: &RefCell, pat: &hir::Pat, mut it: I) where - I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned), -{ - pat.walk(|p| { - match p.node { - PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => { - it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name)); - } - _ => {} - } - true - }); -} -pub fn pat_bindings_ident(dm: &RefCell, pat: &hir::Pat, mut it: I) where - I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned), -{ - pat.walk(|p| { - match p.node { - PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => { - it(binding_mode, p.id, p.span, &respan(pth.span, pth.node)); - } - _ => {} - } - true - }); -} - -/// Checks if the pattern contains any patterns that bind something to -/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`. -pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool { - let mut contains_bindings = false; - pat.walk(|p| { - if pat_is_binding(dm, p) { - contains_bindings = true; - false // there's at least one binding, can short circuit now. - } else { - true - } - }); - contains_bindings -} - -/// Checks if the pattern contains any `ref` or `ref mut` bindings, -/// and if yes whether its containing mutable ones or just immutables ones. -pub fn pat_contains_ref_binding(dm: &RefCell, pat: &hir::Pat) -> Option { - let mut result = None; - pat_bindings(dm, pat, |mode, _, _, _| { - match mode { - hir::BindingMode::BindByRef(m) => { - // Pick Mutable as maximum - match result { - None | Some(hir::MutImmutable) => result = Some(m), - _ => (), - } - } - hir::BindingMode::BindByValue(_) => { } - } - }); - result -} - -/// Checks if the patterns for this arm contain any `ref` or `ref mut` -/// bindings, and if yes whether its containing mutable ones or just immutables ones. -pub fn arm_contains_ref_binding(dm: &RefCell, arm: &hir::Arm) -> Option { - arm.pats.iter() - .filter_map(|pat| pat_contains_ref_binding(dm, pat)) - .max_by_key(|m| match *m { - hir::MutMutable => 1, - hir::MutImmutable => 0, - }) -} - -/// Checks if the pattern contains any patterns that bind something to -/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`, -pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool { - let mut contains_bindings = false; - pat.walk(|p| { - if pat_is_binding_or_wild(dm, p) { - contains_bindings = true; - false // there's at least one binding/wildcard, can short circuit now. - } else { - true - } - }); - contains_bindings -} - -pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option { - match pat.node { - PatKind::Ident(hir::BindByValue(_), ref path1, None) => { - Some(path1.node.name) - } - _ => { - None - } - } -} - -pub fn def_to_path(tcx: &TyCtxt, id: DefId) -> hir::Path { - tcx.with_path(id, |path| hir::Path { - global: false, - segments: path.last().map(|elem| hir::PathSegment { - identifier: hir::Ident::from_name(elem.name()), - parameters: hir::PathParameters::none(), - }).into_iter().collect(), - span: DUMMY_SP, - }) -} - -/// Return variants that are necessary to exist for the pattern to match. -pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec { - let mut variants = vec![]; - pat.walk(|p| { - match p.node { - PatKind::TupleStruct(..) | - PatKind::Path(..) | - PatKind::Ident(_, _, None) | - PatKind::Struct(..) => { - match dm.get(&p.id) { - Some(&PathResolution { base_def: Def::Variant(_, id), .. }) => { - variants.push(id); - } - _ => () - } - } - _ => () - } - true - }); - variants.sort(); - variants.dedup(); - variants -} diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 8c44594c1f7..63bccc2d02e 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -17,8 +17,8 @@ use dep_graph::DepNode; use hir::map as ast_map; -use middle::def::Def; -use middle::def_id::DefId; +use hir::def::Def; +use hir::def_id::DefId; use ty::{self, TyCtxt}; use middle::privacy; use session::config; diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 1275753a340..585b65b9f5e 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -21,7 +21,7 @@ use self::ScopeChain::*; use dep_graph::DepNode; use hir::map::Map; use session::Session; -use middle::def::{Def, DefMap}; +use hir::def::{Def, DefMap}; use middle::region; use ty::subst; use ty; diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index ffb4a791363..6c7c7f160f4 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -18,8 +18,8 @@ use hir::map as hir_map; use session::Session; use lint; use middle::cstore::{CrateStore, LOCAL_CRATE}; -use middle::def::Def; -use middle::def_id::{CRATE_DEF_INDEX, DefId}; +use hir::def::Def; +use hir::def_id::{CRATE_DEF_INDEX, DefId}; use ty::{self, TyCtxt}; use middle::privacy::AccessLevels; use syntax::parse::token::InternedString; diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index 1b24b4f6210..28437fa1336 100644 --- a/src/librustc/mir/repr.rs +++ b/src/librustc/mir/repr.rs @@ -11,7 +11,7 @@ use graphviz::IntoCow; use middle::const_val::ConstVal; use rustc_const_math::{ConstUsize, ConstInt}; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst::Substs; use ty::{self, AdtDef, ClosureSubsts, FnOutput, Region, Ty}; use util::ppaux; diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 403c749fe4b..ae803f50231 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -9,7 +9,7 @@ // except according to those terms. use middle::const_val::ConstVal; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst::Substs; use ty::{ClosureSubsts, FnOutput, Region, Ty}; use mir::repr::*; diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index a0ac5148526..6710d2a653c 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -13,7 +13,7 @@ use super::{SelectionContext, Obligation, ObligationCause}; use middle::cstore::LOCAL_CRATE; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst::TypeSpace; use ty::{self, Ty, TyCtxt}; use infer::{self, InferCtxt, TypeOrigin}; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index f15b9ee44ce..9357dda2583 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -24,7 +24,7 @@ use super::{ }; use fmt_macros::{Parser, Piece, Position}; -use middle::def_id::DefId; +use hir::def_id::DefId; use infer::InferCtxt; use ty::{self, ToPredicate, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable}; use ty::fast_reject; diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 867bd054fa9..a160465e2e8 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -15,7 +15,7 @@ pub use self::FulfillmentErrorCode::*; pub use self::Vtable::*; pub use self::ObligationCauseCode::*; -use middle::def_id::DefId; +use hir::def_id::DefId; use middle::free_region::FreeRegionMap; use ty::subst; use ty::{self, Ty, TypeFoldable}; diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 7cd2ac5938d..9af2cfbd04d 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -20,7 +20,7 @@ use super::supertraits; use super::elaborate_predicates; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst::{self, SelfSpace, TypeSpace}; use traits; use ty::{self, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable}; diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index d4d61ec0244..a0d6f5f912b 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -23,7 +23,7 @@ use super::VtableClosureData; use super::VtableImplData; use super::util; -use middle::def_id::DefId; +use hir::def_id::DefId; use infer::{self, InferOk, TypeOrigin}; use ty::subst::Subst; use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt}; diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 97c9caadd52..8d7df6e44ae 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -36,7 +36,7 @@ use super::{VtableImplData, VtableObjectData, VtableBuiltinData, use super::object_safety; use super::util; -use middle::def_id::DefId; +use hir::def_id::DefId; use infer; use infer::{InferCtxt, InferOk, TypeFreshener, TypeOrigin}; use ty::subst::{Subst, Substs, TypeSpace}; diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 88f4129d886..63647515a97 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -21,7 +21,7 @@ use super::{SelectionContext, FulfillmentContext}; use super::util::{fresh_type_vars_for_impl, impl_trait_ref_and_oblig}; use middle::cstore::CrateStore; -use middle::def_id::DefId; +use hir::def_id::DefId; use infer::{self, InferCtxt, TypeOrigin}; use middle::region; use ty::subst::{Subst, Substs}; diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index d3146697ee6..51b0b6b8b38 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -14,7 +14,7 @@ use std::rc::Rc; use super::{Overlap, specializes}; use middle::cstore::CrateStore; -use middle::def_id::DefId; +use hir::def_id::DefId; use infer; use traits::{self, ProjectionMode}; use ty::{self, TyCtxt, ImplOrTraitItem, TraitDef, TypeFoldable}; diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index befca878bc0..7668b8bf202 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def_id::DefId; +use hir::def_id::DefId; use infer::InferCtxt; use ty::subst::{Subst, Substs}; use ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef}; diff --git a/src/librustc/ty/contents.rs b/src/librustc/ty/contents.rs index ba237184a9f..f5dedb13248 100644 --- a/src/librustc/ty/contents.rs +++ b/src/librustc/ty/contents.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def_id::{DefId}; +use hir::def_id::{DefId}; use ty::{self, Ty, TyCtxt}; use util::common::MemoizationMap; use util::nodemap::FnvHashMap; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index fa5a7f3ca69..14ffeadbb3a 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -16,8 +16,8 @@ use session::Session; use lint; use middle; use middle::cstore::{CrateStore, LOCAL_CRATE}; -use middle::def::DefMap; -use middle::def_id::DefId; +use hir::def::DefMap; +use hir::def_id::DefId; use middle::free_region::FreeRegionMap; use middle::region::RegionMaps; use middle::resolve_lifetime; diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index e6b7b49ea57..73bafc5e850 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst; use infer::type_variable; use ty::{self, BoundRegion, Region, Ty, TyCtxt}; diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs index 0865e059f59..29647253ad2 100644 --- a/src/librustc/ty/fast_reject.rs +++ b/src/librustc/ty/fast_reject.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::{self, Ty, TyCtxt}; use syntax::ast; diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 0648450d833..4d88b697416 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -10,7 +10,7 @@ use hir::map::DefPathData; use middle::cstore::LOCAL_CRATE; -use middle::def_id::{DefId, CRATE_DEF_INDEX}; +use hir::def_id::{DefId, CRATE_DEF_INDEX}; use ty::{self, Ty, TyCtxt}; use syntax::ast; diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 77b6b03e48f..65a96e79ff4 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -9,7 +9,7 @@ // except according to those terms. use dep_graph::{DepNode, DepTrackingMapConfig}; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty; use std::marker::PhantomData; use std::rc::Rc; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 69a6a6aa920..2f0b520d842 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -23,8 +23,8 @@ use hir::map as ast_map; use hir::map::LinkedPath; use middle; use middle::cstore::{self, CrateStore, LOCAL_CRATE}; -use middle::def::{self, Def, ExportMap}; -use middle::def_id::DefId; +use hir::def::{self, Def, ExportMap}; +use hir::def_id::DefId; use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; use middle::region::{CodeExtent}; use traits; diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index b1bff9b43cc..f14e680e9e0 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -13,7 +13,7 @@ //! can be other things. Examples of type relations are subtyping, //! type equality, etc. -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst::{ParamSpace, Substs}; use ty::{self, Ty, TyCtxt, TypeFoldable}; use ty::error::{ExpectedFound, TypeError}; diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 101c8501bd3..c0fb60d4dd3 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -11,7 +11,7 @@ //! This module contains TypeVariants and its major components use middle::cstore; -use middle::def_id::DefId; +use hir::def_id::DefId; use middle::region; use ty::subst::{self, Substs}; use traits; diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 93157f28482..dd547da59e9 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -13,7 +13,7 @@ pub use self::ParamSpace::*; use middle::cstore; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::{self, Ty, TyCtxt}; use ty::fold::{TypeFoldable, TypeFolder}; diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 0eb70f93bed..94f4e31efc6 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -9,7 +9,7 @@ // except according to those terms. use dep_graph::DepNode; -use middle::def_id::DefId; +use hir::def_id::DefId; use traits::{self, specialization_graph}; use ty; use ty::fast_reject; diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 710cd2e301c..354744b2787 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -11,10 +11,10 @@ //! misc. type-system utilities too small to deserve their own file use hir::svh::Svh; -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst; use infer; -use middle::pat_util; +use hir::pat_util; use traits::{self, ProjectionMode}; use ty::{self, Ty, TyCtxt, TypeAndMut, TypeFlags, TypeFoldable}; use ty::{Disr, ParameterEnvironment}; diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index e6c4e90babb..9ea634bb41c 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def_id::DefId; +use hir::def_id::DefId; use infer::InferCtxt; use ty::outlives::{self, Component}; use ty::subst::Substs; diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index 4a45797602d..69bcc9cbfff 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -12,7 +12,7 @@ #![allow(non_snake_case)] -use middle::def_id::DefId; +use hir::def_id::DefId; use syntax::ast; pub use rustc_data_structures::fnv::FnvHashMap; diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index c386a670ba2..a84a42fc2b5 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -9,7 +9,7 @@ // except according to those terms. -use middle::def_id::DefId; +use hir::def_id::DefId; use ty::subst::{self, Subst}; use ty::{BrAnon, BrEnv, BrFresh, BrNamed}; use ty::{TyBool, TyChar, TyStruct, TyEnum}; diff --git a/src/librustc_borrowck/borrowck/fragments.rs b/src/librustc_borrowck/borrowck/fragments.rs index d1b30bb2746..0b1c4efa9ac 100644 --- a/src/librustc_borrowck/borrowck/fragments.rs +++ b/src/librustc_borrowck/borrowck/fragments.rs @@ -20,7 +20,7 @@ use borrowck::LoanPathKind::{LpVar, LpUpvar, LpDowncast, LpExtend}; use borrowck::LoanPathElem::{LpDeref, LpInterior}; use borrowck::move_data::InvalidMovePathIndex; use borrowck::move_data::{MoveData, MovePathIndex}; -use rustc::middle::def_id::{DefId}; +use rustc::hir::def_id::{DefId}; use rustc::ty::{self, TyCtxt}; use rustc::middle::mem_categorization as mc; diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 789d7dd9fef..d7c928b8d6e 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -28,7 +28,7 @@ use rustc::middle::dataflow::DataFlowContext; use rustc::middle::dataflow::BitwiseOperator; use rustc::middle::dataflow::DataFlowOperator; use rustc::middle::dataflow::KillFrom; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::middle::expr_use_visitor as euv; use rustc::middle::free_region::FreeRegionMap; use rustc::middle::mem_categorization as mc; diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index 797580319b2..1e662d456d1 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -17,14 +17,14 @@ use rustc::middle::const_val::ConstVal; use ::{eval_const_expr, eval_const_expr_partial, compare_const_vals}; use ::{const_expr_to_pat, lookup_const_by_id}; use ::EvalHint::ExprTypeChecked; -use rustc::middle::def::*; -use rustc::middle::def_id::{DefId}; +use rustc::hir::def::*; +use rustc::hir::def_id::{DefId}; use rustc::middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor}; use rustc::middle::expr_use_visitor::{LoanCause, MutateMode}; use rustc::middle::expr_use_visitor as euv; use rustc::infer; use rustc::middle::mem_categorization::{cmt}; -use rustc::middle::pat_util::*; +use rustc::hir::pat_util::*; use rustc::traits::ProjectionMode; use rustc::ty::*; use rustc::ty; diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index dba31ddef95..45a90bf0068 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -19,9 +19,9 @@ use rustc::hir::map as ast_map; use rustc::hir::map::blocks::FnLikeNode; use rustc::middle::cstore::{self, CrateStore, InlinedItem}; use rustc::{infer, traits}; -use rustc::middle::def::Def; -use rustc::middle::def_id::DefId; -use rustc::middle::pat_util::def_to_path; +use rustc::hir::def::Def; +use rustc::hir::def_id::DefId; +use rustc::hir::pat_util::def_to_path; use rustc::ty::{self, Ty, TyCtxt, subst}; use rustc::ty::util::IntTypeExt; use rustc::traits::ProjectionMode; diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index ed9c66a1882..d10691d12ed 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def::Def; +use rustc::hir::def::Def; use rustc::ty; use lint::{LateContext, LintContext, LintArray}; use lint::{LintPass, LateLintPass}; diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 6f11ebafa86..fe10ca87b75 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -28,9 +28,9 @@ //! Use the former for unit-like structs and the latter for structs with //! a `pub fn new()`. -use middle::def::Def; +use rustc::hir::def::Def; use middle::cstore::CrateStore; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use middle::stability; use rustc::{cfg, infer}; use rustc::ty::subst::Substs; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 574c7af4cfc..891731cb296 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -10,7 +10,7 @@ #![allow(non_snake_case)] -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TyCtxt}; diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index f531628601b..d1595f243c9 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::pat_util; +use rustc::hir::pat_util; use rustc::ty; use rustc::ty::adjustment; use util::nodemap::FnvHashMap; diff --git a/src/librustc_metadata/astencode.rs b/src/librustc_metadata/astencode.rs index 61f35a12df7..df60e35d0f3 100644 --- a/src/librustc_metadata/astencode.rs +++ b/src/librustc_metadata/astencode.rs @@ -31,8 +31,8 @@ use middle::cstore::{InlinedItem, InlinedItemRef}; use rustc::ty::adjustment; use rustc::ty::cast; use middle::const_qualif::ConstQualif; -use middle::def::{self, Def}; -use middle::def_id::DefId; +use rustc::hir::def::{self, Def}; +use rustc::hir::def_id::DefId; use middle::region; use rustc::ty::subst; use rustc::ty::{self, Ty, TyCtxt}; diff --git a/src/librustc_metadata/csearch.rs b/src/librustc_metadata/csearch.rs index c9e661dec51..bb691cebccd 100644 --- a/src/librustc_metadata/csearch.rs +++ b/src/librustc_metadata/csearch.rs @@ -15,10 +15,10 @@ use loader; use middle::cstore::{CrateStore, CrateSource, ChildItem, ExternCrate, FoundAst, DefLike}; use middle::cstore::{NativeLibraryKind, LinkMeta, LinkagePreference}; -use middle::def; +use rustc::hir::def; use middle::lang_items; use rustc::ty::{self, Ty, TyCtxt, VariantKind}; -use middle::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; +use rustc::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; use rustc::hir::map as hir_map; use rustc::mir::repr::Mir; diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs index 3a6cd4d832b..d5a9adafe7d 100644 --- a/src/librustc_metadata/cstore.rs +++ b/src/librustc_metadata/cstore.rs @@ -20,10 +20,10 @@ use decoder; use index; use loader; +use rustc::hir::def_id::DefId; use rustc::hir::svh::Svh; use rustc::middle::cstore::{ExternCrate}; use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap}; -use rustc::middle::def_id::DefId; use std::cell::{RefCell, Ref, Cell}; use std::rc::Rc; diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 5aafd015f9a..e6f538255ac 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -29,8 +29,8 @@ use rustc::hir; use middle::cstore::{LOCAL_CRATE, FoundAst, InlinedItem, LinkagePreference}; use middle::cstore::{DefLike, DlDef, DlField, DlImpl, tls}; -use middle::def::Def; -use middle::def_id::{DefId, DefIndex}; +use rustc::hir::def::Def; +use rustc::hir::def_id::{DefId, DefIndex}; use middle::lang_items; use rustc::ty::subst; use rustc::ty::{ImplContainer, TraitContainer}; diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index dc21ebcbcfc..83ffd8afbeb 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -21,8 +21,8 @@ use tyencode; use index::{self, IndexData}; use middle::cstore::{LOCAL_CRATE, CrateStore, InlinedItemRef, LinkMeta, tls}; -use middle::def; -use middle::def_id::{CRATE_DEF_INDEX, DefId}; +use rustc::hir::def; +use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId}; use middle::dependency_format::Linkage; use middle::stability; use rustc::ty::subst; diff --git a/src/librustc_metadata/index.rs b/src/librustc_metadata/index.rs index 60bbdaddd75..9c066f9f5f1 100644 --- a/src/librustc_metadata/index.rs +++ b/src/librustc_metadata/index.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def_id::{DefId, DefIndex}; +use rustc::hir::def_id::{DefId, DefIndex}; use rbml; use std::io::{Cursor, Write}; use std::slice; diff --git a/src/librustc_metadata/tls_context.rs b/src/librustc_metadata/tls_context.rs index 6ecd7a7f50a..782c7cba26e 100644 --- a/src/librustc_metadata/tls_context.rs +++ b/src/librustc_metadata/tls_context.rs @@ -14,7 +14,7 @@ use rbml::opaque::Encoder as OpaqueEncoder; use rbml::opaque::Decoder as OpaqueDecoder; use rustc::middle::cstore::tls; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::ty::subst::Substs; use rustc::ty::{self, TyCtxt}; diff --git a/src/librustc_metadata/tydecode.rs b/src/librustc_metadata/tydecode.rs index cd63b58372b..3004246d1d7 100644 --- a/src/librustc_metadata/tydecode.rs +++ b/src/librustc_metadata/tydecode.rs @@ -18,7 +18,7 @@ use rustc::hir; -use middle::def_id::{DefId, DefIndex}; +use rustc::hir::def_id::{DefId, DefIndex}; use middle::region; use rustc::ty::subst; use rustc::ty::subst::VecPerParamSpace; diff --git a/src/librustc_metadata/tyencode.rs b/src/librustc_metadata/tyencode.rs index b5079256487..f49c2e22c6a 100644 --- a/src/librustc_metadata/tyencode.rs +++ b/src/librustc_metadata/tyencode.rs @@ -17,7 +17,7 @@ use std::cell::RefCell; use std::io::Cursor; use std::io::prelude::*; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use middle::region; use rustc::ty::subst; use rustc::ty::subst::VecPerParamSpace; diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 790833f99ca..7f748ef9b1e 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -15,11 +15,11 @@ use hair::cx::Cx; use hair::cx::block; use hair::cx::to_ref::ToRef; use rustc::hir::map; -use rustc::middle::def::Def; +use rustc::hir::def::Def; use rustc::middle::const_val::ConstVal; use rustc_const_eval as const_eval; use rustc::middle::region::CodeExtent; -use rustc::middle::pat_util; +use rustc::hir::pat_util; use rustc::ty::{self, VariantDef, Ty}; use rustc::mir::repr::*; use rustc::hir; diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index f0c6887802d..c3a5fbd967c 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -20,7 +20,7 @@ use rustc::mir::repr::*; use rustc::middle::const_val::ConstVal; use rustc_const_eval as const_eval; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; use rustc::ty::subst::{Subst, Substs}; use rustc::ty::{self, Ty, TyCtxt}; diff --git a/src/librustc_mir/hair/cx/pattern.rs b/src/librustc_mir/hair/cx/pattern.rs index 673d12c3316..990ba9e786c 100644 --- a/src/librustc_mir/hair/cx/pattern.rs +++ b/src/librustc_mir/hair/cx/pattern.rs @@ -12,8 +12,8 @@ use hair::*; use hair::cx::Cx; use rustc_data_structures::fnv::FnvHashMap; use rustc_const_eval as const_eval; -use rustc::middle::def::Def; -use rustc::middle::pat_util::{pat_is_resolved_const, pat_is_binding}; +use rustc::hir::def::Def; +use rustc::hir::pat_util::{pat_is_resolved_const, pat_is_binding}; use rustc::ty::{self, Ty}; use rustc::mir::repr::*; use rustc::hir::{self, PatKind}; diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index 0ea8dece47c..51f2cc2687a 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -17,7 +17,7 @@ use rustc::mir::repr::{BinOp, BorrowKind, Field, Literal, Mutability, UnOp, TypedConstVal}; use rustc::middle::const_val::ConstVal; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::middle::region::CodeExtent; use rustc::ty::subst::Substs; use rustc::ty::{self, AdtDef, ClosureSubsts, Region, Ty}; diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index 38784191a78..4659bb389dc 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -30,8 +30,8 @@ use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs}; use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id}; use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal}; use rustc_const_eval::EvalHint::ExprTypeChecked; -use rustc::middle::def::Def; -use rustc::middle::def_id::DefId; +use rustc::hir::def::Def; +use rustc::hir::def_id::DefId; use rustc::middle::expr_use_visitor as euv; use rustc::infer; use rustc::middle::mem_categorization as mc; diff --git a/src/librustc_passes/static_recursion.rs b/src/librustc_passes/static_recursion.rs index 2766d13d7b8..245960a04f0 100644 --- a/src/librustc_passes/static_recursion.rs +++ b/src/librustc_passes/static_recursion.rs @@ -14,7 +14,7 @@ use rustc::dep_graph::DepNode; use rustc::hir::map as ast_map; use rustc::session::{Session, CompileResult}; -use rustc::middle::def::{Def, DefMap}; +use rustc::hir::def::{Def, DefMap}; use rustc::util::nodemap::NodeMap; use syntax::{ast}; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 908a7869c42..8840bd42717 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -35,8 +35,8 @@ use rustc::hir::intravisit::{self, Visitor}; use rustc::dep_graph::DepNode; use rustc::lint; use rustc::middle::cstore::CrateStore; -use rustc::middle::def::{self, Def}; -use rustc::middle::def_id::DefId; +use rustc::hir::def::{self, Def}; +use rustc::hir::def_id::DefId; use rustc::middle::privacy::{AccessLevel, AccessLevels}; use rustc::ty::{self, TyCtxt}; use rustc::util::nodemap::NodeSet; diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 470fd88025e..a422b09f96b 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -24,8 +24,8 @@ use {resolve_error, resolve_struct_error, ResolutionError}; use rustc::middle::cstore::{CrateStore, ChildItem, DlDef}; use rustc::lint; -use rustc::middle::def::*; -use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId}; +use rustc::hir::def::*; +use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId}; use rustc::ty::VariantKind; use syntax::ast::Name; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c0b8aad1c09..502b45c9453 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -52,9 +52,9 @@ use rustc::hir::map as hir_map; use rustc::session::Session; use rustc::lint; use rustc::middle::cstore::CrateStore; -use rustc::middle::def::*; -use rustc::middle::def_id::DefId; -use rustc::middle::pat_util::pat_bindings; +use rustc::hir::def::*; +use rustc::hir::def_id::DefId; +use rustc::hir::pat_util::pat_bindings; use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace}; use rustc::ty::{Freevar, FreevarMap, TraitMap, GlobMap}; use rustc::util::nodemap::{NodeMap, FnvHashMap}; @@ -2570,7 +2570,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } /// Skips `path_depth` trailing segments, which is also reflected in the - /// returned value. See `middle::def::PathResolution` for more info. + /// returned value. See `hir::def::PathResolution` for more info. fn resolve_path(&mut self, id: NodeId, path: &Path, path_depth: usize, namespace: Namespace) -> Option { let span = path.span; diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 2aa8925fb54..738a99fbe92 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -22,7 +22,7 @@ use {names_to_string, module_to_string}; use {resolve_error, ResolutionError}; use rustc::lint; -use rustc::middle::def::*; +use rustc::hir::def::*; use syntax::ast::{NodeId, Name}; use syntax::attr::AttrMetaMethods; diff --git a/src/librustc_save_analysis/csv_dumper.rs b/src/librustc_save_analysis/csv_dumper.rs index 3021d4e9820..0e02830db7a 100644 --- a/src/librustc_save_analysis/csv_dumper.rs +++ b/src/librustc_save_analysis/csv_dumper.rs @@ -10,7 +10,7 @@ use std::io::Write; -use rustc::middle::def_id::{DefId, DefIndex}; +use rustc::hir::def_id::{DefId, DefIndex}; use syntax::codemap::Span; use super::data::*; diff --git a/src/librustc_save_analysis/data.rs b/src/librustc_save_analysis/data.rs index 649c8387eb3..7f2f2618c3c 100644 --- a/src/librustc_save_analysis/data.rs +++ b/src/librustc_save_analysis/data.rs @@ -15,7 +15,7 @@ use std::hash::Hasher; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::ty; use syntax::ast::{CrateNum, NodeId}; use syntax::codemap::Span; diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 310747c8991..c724091a2ec 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -27,8 +27,8 @@ //! is used for recording the output in a format-agnostic way (see CsvDumper //! for an example). -use rustc::middle::def::Def; -use rustc::middle::def_id::DefId; +use rustc::hir::def::Def; +use rustc::hir::def_id::DefId; use rustc::session::Session; use rustc::ty::{self, TyCtxt}; diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index a4f9720bbe2..98c0be1c93c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -29,8 +29,8 @@ use rustc::hir::{self, lowering}; use rustc::hir::map::NodeItem; -use rustc::middle::def::Def; -use rustc::middle::def_id::DefId; +use rustc::hir::def::Def; +use rustc::hir::def_id::DefId; use rustc::session::config::CrateType::CrateTypeExecutable; use rustc::ty::{self, TyCtxt}; diff --git a/src/librustc_trans/_match.rs b/src/librustc_trans/_match.rs index 3bbead9847b..d8b8f9f0806 100644 --- a/src/librustc_trans/_match.rs +++ b/src/librustc_trans/_match.rs @@ -191,14 +191,14 @@ use self::FailureHandler::*; use llvm::{ValueRef, BasicBlockRef}; use rustc_const_eval::check_match::{self, StaticInliner}; use rustc_const_eval::{compare_lit_exprs, eval_const_expr}; -use middle::def::{Def, DefMap}; -use middle::def_id::DefId; +use rustc::hir::def::{Def, DefMap}; +use rustc::hir::def_id::DefId; use middle::expr_use_visitor as euv; use rustc::infer; use middle::lang_items::StrEqFnLangItem; use middle::mem_categorization as mc; use middle::mem_categorization::Categorization; -use middle::pat_util::*; +use rustc::hir::pat_util::*; use rustc::ty::subst::Substs; use adt; use base::*; diff --git a/src/librustc_trans/assert_dep_graph.rs b/src/librustc_trans/assert_dep_graph.rs index ecbb5049443..932f66f17cc 100644 --- a/src/librustc_trans/assert_dep_graph.rs +++ b/src/librustc_trans/assert_dep_graph.rs @@ -39,7 +39,7 @@ use graphviz as dot; use rustc::dep_graph::{DepGraphQuery, DepNode}; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::ty::TyCtxt; use rustc_data_structures::fnv::{FnvHashMap, FnvHashSet}; use rustc_data_structures::graph::{Direction, INCOMING, OUTGOING, NodeIndex}; diff --git a/src/librustc_trans/back/symbol_names.rs b/src/librustc_trans/back/symbol_names.rs index 949a10297c1..8127d1c0e29 100644 --- a/src/librustc_trans/back/symbol_names.rs +++ b/src/librustc_trans/back/symbol_names.rs @@ -102,7 +102,7 @@ use monomorphize::Instance; use util::sha2::{Digest, Sha256}; use rustc::middle::cstore; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::ty::{self, TypeFoldable}; use rustc::ty::item_path::{ItemPathBuffer, RootMode}; use rustc::hir::map::definitions::{DefPath, DefPathData}; diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 6714f6440ee..4f1585eeaca 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -36,11 +36,11 @@ use llvm::{BasicBlockRef, Linkage, ValueRef, Vector, get_param}; use llvm; use rustc::cfg; use middle::cstore::CrateStore; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem}; use middle::weak_lang_items; -use middle::pat_util::simple_name; +use rustc::hir::pat_util::simple_name; use rustc::ty::subst::{self, Substs}; use rustc::traits; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; diff --git a/src/librustc_trans/callee.rs b/src/librustc_trans/callee.rs index 2da9acf3250..392c40a6015 100644 --- a/src/librustc_trans/callee.rs +++ b/src/librustc_trans/callee.rs @@ -21,7 +21,7 @@ use arena::TypedArena; use back::symbol_names; use llvm::{self, ValueRef, get_params}; use middle::cstore::LOCAL_CRATE; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; use rustc::ty::subst; use rustc::ty::subst::{Substs}; diff --git a/src/librustc_trans/closure.rs b/src/librustc_trans/closure.rs index 579848919ec..6bd5fd355a7 100644 --- a/src/librustc_trans/closure.rs +++ b/src/librustc_trans/closure.rs @@ -11,7 +11,7 @@ use arena::TypedArena; use back::symbol_names; use llvm::{ValueRef, get_param, get_params}; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; use rustc::traits::ProjectionMode; use abi::{Abi, FnType}; diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 4f197dbee13..c72a1a6bef3 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -192,7 +192,7 @@ use rustc::hir; use rustc::hir::intravisit as hir_visit; use rustc::hir::map as hir_map; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::middle::lang_items::{ExchangeFreeFnLangItem, ExchangeMallocFnLangItem}; use rustc::traits; use rustc::ty::subst::{self, Substs, Subst}; diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index 1f48eb91603..5ce7caf5deb 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -17,8 +17,8 @@ use llvm; use llvm::{ValueRef, BasicBlockRef, BuilderRef, ContextRef, TypeKind}; use llvm::{True, False, Bool, OperandBundleDef}; use rustc::cfg; -use middle::def::Def; -use middle::def_id::DefId; +use rustc::hir::def::Def; +use rustc::hir::def_id::DefId; use rustc::infer; use middle::lang_items::LangItem; use rustc::ty::subst::Substs; diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs index 7945639f86b..89f3b295c8d 100644 --- a/src/librustc_trans/consts.rs +++ b/src/librustc_trans/consts.rs @@ -15,8 +15,8 @@ use llvm::{InternalLinkage, ValueRef, Bool, True}; use middle::const_qualif::ConstQualif; use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, lookup_const_by_id, ErrKind}; use rustc_const_eval::eval_repeat_count; -use middle::def::Def; -use middle::def_id::DefId; +use rustc::hir::def::Def; +use rustc::hir::def_id::DefId; use rustc::hir::map as hir_map; use {abi, adt, closure, debuginfo, expr, machine}; use base::{self, exported_name, imported_name, push_ctxt}; diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 3574883c5f5..9bbc72eba36 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -12,8 +12,8 @@ use llvm; use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef}; use rustc::dep_graph::{DepNode, DepTrackingMap, DepTrackingMapConfig}; use middle::cstore::LinkMeta; -use middle::def::ExportMap; -use middle::def_id::DefId; +use rustc::hir::def::ExportMap; +use rustc::hir::def_id::DefId; use rustc::traits; use rustc::mir::mir_map::MirMap; use rustc::mir::repr as mir; diff --git a/src/librustc_trans/controlflow.rs b/src/librustc_trans/controlflow.rs index f3cb4d5001a..58971dec8a9 100644 --- a/src/librustc_trans/controlflow.rs +++ b/src/librustc_trans/controlflow.rs @@ -9,7 +9,7 @@ // except according to those terms. use llvm::ValueRef; -use middle::def::Def; +use rustc::hir::def::Def; use middle::lang_items::{PanicFnLangItem, PanicBoundsCheckFnLangItem}; use rustc::ty::subst::Substs; use base::*; diff --git a/src/librustc_trans/debuginfo/create_scope_map.rs b/src/librustc_trans/debuginfo/create_scope_map.rs index b98b9881350..b1cfeb8125b 100644 --- a/src/librustc_trans/debuginfo/create_scope_map.rs +++ b/src/librustc_trans/debuginfo/create_scope_map.rs @@ -14,7 +14,7 @@ use super::utils::DIB; use llvm; use llvm::debuginfo::{DIScope, DISubprogram}; use common::CrateContext; -use middle::pat_util; +use rustc::hir::pat_util; use rustc::util::nodemap::NodeMap; use libc::c_uint; diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index acfafc6e329..822155f8c36 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -23,9 +23,9 @@ use super::{declare_local, VariableKind, VariableAccess}; use llvm::{self, ValueRef}; use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType}; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; -use middle::pat_util; +use rustc::hir::pat_util; use rustc::ty::subst; use rustc::hir::map as hir_map; use rustc::hir::{self, PatKind}; diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs index 7e9c8228f29..bb999c31ffb 100644 --- a/src/librustc_trans/debuginfo/mod.rs +++ b/src/librustc_trans/debuginfo/mod.rs @@ -26,7 +26,7 @@ use llvm; use llvm::{ModuleRef, ContextRef, ValueRef}; use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIDescriptor, FlagPrototyped}; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer::normalize_associated_type; use rustc::ty::subst::{self, Substs}; use rustc::hir; diff --git a/src/librustc_trans/debuginfo/namespace.rs b/src/librustc_trans/debuginfo/namespace.rs index 1feb47a3a7d..c1487f56956 100644 --- a/src/librustc_trans/debuginfo/namespace.rs +++ b/src/librustc_trans/debuginfo/namespace.rs @@ -14,7 +14,7 @@ use super::utils::{DIB, debug_context}; use llvm; use llvm::debuginfo::DIScope; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::hir::map as hir_map; use common::CrateContext; diff --git a/src/librustc_trans/debuginfo/type_names.rs b/src/librustc_trans/debuginfo/type_names.rs index f5bb1677f29..0169734ad3b 100644 --- a/src/librustc_trans/debuginfo/type_names.rs +++ b/src/librustc_trans/debuginfo/type_names.rs @@ -13,7 +13,7 @@ use super::namespace::crate_root_namespace; use common::CrateContext; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; use rustc::ty::subst; use rustc::ty::{self, Ty}; diff --git a/src/librustc_trans/debuginfo/utils.rs b/src/librustc_trans/debuginfo/utils.rs index 61dc3dc3f8f..bef7af3aec6 100644 --- a/src/librustc_trans/debuginfo/utils.rs +++ b/src/librustc_trans/debuginfo/utils.rs @@ -13,7 +13,7 @@ use super::{FunctionDebugContext, CrateDebugContext}; use super::namespace::namespace_for_item; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use llvm; use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray}; diff --git a/src/librustc_trans/expr.rs b/src/librustc_trans/expr.rs index fce8656fb93..beca81da05f 100644 --- a/src/librustc_trans/expr.rs +++ b/src/librustc_trans/expr.rs @@ -53,7 +53,7 @@ use self::lazy_binop_ty::*; use llvm::{self, ValueRef, TypeKind}; use middle::const_qualif::ConstQualif; -use middle::def::Def; +use rustc::hir::def::Def; use rustc::ty::subst::Substs; use {_match, abi, adt, asm, base, closure, consts, controlflow}; use base::*; diff --git a/src/librustc_trans/inline.rs b/src/librustc_trans/inline.rs index 36dfbec115e..1eff09d67f9 100644 --- a/src/librustc_trans/inline.rs +++ b/src/librustc_trans/inline.rs @@ -10,7 +10,7 @@ use llvm::{AvailableExternallyLinkage, InternalLinkage, SetLinkage}; use middle::cstore::{CrateStore, FoundAst, InlinedItem}; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::ty::subst::Substs; use base::{push_ctxt, trans_item, trans_fn}; use callee::Callee; diff --git a/src/librustc_trans/meth.rs b/src/librustc_trans/meth.rs index 82b61e15f2b..478094c2b87 100644 --- a/src/librustc_trans/meth.rs +++ b/src/librustc_trans/meth.rs @@ -13,7 +13,7 @@ use std::rc::Rc; use arena::TypedArena; use back::symbol_names; use llvm::{ValueRef, get_params}; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; use rustc::ty::subst::{FnSpace, Subst, Substs}; use rustc::ty::subst; diff --git a/src/librustc_trans/monomorphize.rs b/src/librustc_trans/monomorphize.rs index de66951d091..ef0da37f0b2 100644 --- a/src/librustc_trans/monomorphize.rs +++ b/src/librustc_trans/monomorphize.rs @@ -11,7 +11,7 @@ use back::symbol_names; use llvm::ValueRef; use llvm; -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer::normalize_associated_type; use rustc::ty::subst; use rustc::ty::subst::{Subst, Substs}; diff --git a/src/librustc_trans/type_of.rs b/src/librustc_trans/type_of.rs index 8b1aaafab58..500eda2624c 100644 --- a/src/librustc_trans/type_of.rs +++ b/src/librustc_trans/type_of.rs @@ -10,7 +10,7 @@ #![allow(non_camel_case_types)] -use middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::infer; use rustc::ty::subst; use abi::FnType; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a52b8cad108..21122e7095d 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -52,8 +52,8 @@ use middle::astconv_util::{prim_ty_to_ty, prohibit_type_params, prohibit_project use middle::const_val::ConstVal; use rustc_const_eval::eval_const_expr_partial; use rustc_const_eval::EvalHint::UncheckedExprHint; -use middle::def::{self, Def}; -use middle::def_id::DefId; +use hir::def::{self, Def}; +use hir::def_id::DefId; use middle::resolve_lifetime as rl; use rustc::ty::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs, ParamSpace}; use rustc::traits; diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index eaf8479585f..8dbd6496b6f 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use middle::def::{self, Def}; +use hir::def::{self, Def}; use rustc::infer::{self, InferOk, TypeOrigin}; -use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding}; -use middle::pat_util::pat_is_resolved_const; +use hir::pat_util::{PatIdMap, pat_id_map, pat_is_binding}; +use hir::pat_util::pat_is_resolved_const; use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TypeFoldable, LvaluePreference}; use check::{check_expr, check_expr_has_type, check_expr_with_expectation}; diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 460230c60c6..21800d91d94 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -26,8 +26,8 @@ use super::write_call; use CrateCtxt; use middle::cstore::LOCAL_CRATE; -use middle::def::Def; -use middle::def_id::DefId; +use hir::def::Def; +use hir::def_id::DefId; use rustc::infer; use rustc::ty::{self, LvaluePreference, Ty}; use syntax::codemap::Span; diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 00a73a062fe..91cdb8d966d 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -44,7 +44,7 @@ use super::FnCtxt; use super::structurally_resolved_type; use lint; -use middle::def_id::DefId; +use hir::def_id::DefId; use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::cast::{CastKind, CastTy}; use syntax::codemap::Span; diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 1f1bba509e0..368b826b1bb 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -10,7 +10,7 @@ use check::regionck::{self, Rcx}; -use middle::def_id::DefId; +use hir::def_id::DefId; use middle::free_region::FreeRegionMap; use rustc::infer; use middle::region; diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index cc12b2e0515..b98f1884f01 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -12,7 +12,7 @@ use super::probe; use check::{self, FnCtxt, callee, demand}; use check::UnresolvedTypeAction; -use middle::def_id::DefId; +use hir::def_id::DefId; use rustc::ty::subst::{self}; use rustc::traits; use rustc::ty::{self, NoPreference, PreferMutLvalue, Ty, TyCtxt}; diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 72ca73aac94..3f069a68316 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -12,8 +12,8 @@ use astconv::AstConv; use check::FnCtxt; -use middle::def::Def; -use middle::def_id::DefId; +use hir::def::Def; +use hir::def_id::DefId; use rustc::ty::subst; use rustc::traits; use rustc::ty::{self, TyCtxt, ToPredicate, ToPolyTraitRef, TraitRef, TypeFoldable}; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index c907a6dc640..7d98eac30c5 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -15,8 +15,8 @@ use super::suggest; use check; use check::{FnCtxt, UnresolvedTypeAction}; -use middle::def_id::DefId; -use middle::def::Def; +use hir::def_id::DefId; +use hir::def::Def; use rustc::ty::subst; use rustc::ty::subst::Subst; use rustc::traits; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 620863a7a2e..c5195cf8787 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -18,8 +18,8 @@ use check::{self, FnCtxt, UnresolvedTypeAction, autoderef}; use rustc::hir::map as hir_map; use rustc::ty::{self, Ty, ToPolyTraitRef, ToPredicate, TypeFoldable}; use middle::cstore::{self, CrateStore}; -use middle::def::Def; -use middle::def_id::DefId; +use hir::def::Def; +use hir::def_id::DefId; use middle::lang_items::FnOnceTraitLangItem; use rustc::ty::subst::Substs; use rustc::ty::LvaluePreference; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c3a42826dbc..e7159e65eeb 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -86,10 +86,10 @@ use dep_graph::DepNode; use fmt_macros::{Parser, Piece, Position}; use middle::astconv_util::prohibit_type_params; use middle::cstore::LOCAL_CRATE; -use middle::def::{self, Def}; -use middle::def_id::DefId; +use hir::def::{self, Def}; +use hir::def_id::DefId; use rustc::infer::{self, InferOk, TypeOrigin, TypeTrace, type_variable}; -use middle::pat_util::{self, pat_id_map}; +use hir::pat_util::{self, pat_id_map}; use rustc::ty::subst::{self, Subst, Substs, VecPerParamSpace, ParamSpace}; use rustc::traits::{self, report_fulfillment_errors, ProjectionMode}; use rustc::ty::{GenericPredicates, TypeScheme}; diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index f7f40e6077f..debf9258757 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -18,7 +18,7 @@ use super::{ method, FnCtxt, }; -use middle::def_id::DefId; +use hir::def_id::DefId; use rustc::ty::{Ty, TypeFoldable, PreferMutLvalue}; use syntax::ast; use syntax::parse::token; diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 02114c170c4..2a4de6e091b 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -93,7 +93,7 @@ use rustc::ty::subst::Substs; use rustc::traits; use rustc::ty::{self, Ty, TyCtxt, MethodCall, TypeFoldable}; use rustc::infer::{self, GenericKind, InferCtxt, InferOk, SubregionOrigin, TypeOrigin, VerifyBound}; -use middle::pat_util; +use hir::pat_util; use rustc::ty::adjustment; use rustc::ty::wf::ImpliedBound; diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 0ed0b64b970..1b21e6ce9eb 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -12,7 +12,7 @@ use astconv::AstConv; use check::{FnCtxt, Inherited, blank_fn_ctxt, regionck}; use constrained_type_params::{identify_constrained_type_params, Parameter}; use CrateCtxt; -use middle::def_id::DefId; +use hir::def_id::DefId; use middle::region::{CodeExtent}; use rustc::ty::subst::{self, TypeSpace, FnSpace, ParamSpace, SelfSpace}; use rustc::traits; diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 50f2f27b3d2..68327ccd39a 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -15,8 +15,8 @@ use self::ResolveReason::*; use astconv::AstConv; use check::FnCtxt; -use middle::def_id::DefId; -use middle::pat_util; +use hir::def_id::DefId; +use hir::pat_util; use rustc::ty::{self, Ty, TyCtxt, MethodCall, MethodCallee}; use rustc::ty::adjustment; use rustc::ty::fold::{TypeFolder,TypeFoldable}; diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 1f7fc453279..9c8c9ba5056 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -15,7 +15,7 @@ // done by the orphan and overlap modules. Then we build up various // mappings. That mapping code resides here. -use middle::def_id::DefId; +use hir::def_id::DefId; use middle::lang_items::UnsizeTraitLangItem; use rustc::ty::subst::{self, Subst}; use rustc::ty::{self, TyCtxt, TypeFoldable}; diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 0821d5582bd..f3d63957018 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -12,7 +12,7 @@ //! crate or pertains to a type defined in this crate. use middle::cstore::LOCAL_CRATE; -use middle::def_id::DefId; +use hir::def_id::DefId; use rustc::traits; use rustc::ty::{self, TyCtxt}; use syntax::ast; diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index d99c5d52f4a..a05167dbe43 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -13,7 +13,7 @@ //! constructor provide a method with the same name. use middle::cstore::CrateStore; -use middle::def_id::DefId; +use hir::def_id::DefId; use rustc::traits::{self, ProjectionMode}; use rustc::infer; use rustc::ty::{self, TyCtxt}; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 53126d3494a..9d76b4c5284 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -60,8 +60,8 @@ There are some shortcomings in this design: use astconv::{self, AstConv, ty_of_arg, ast_ty_to_ty, ast_region_to_region}; use lint; -use middle::def::Def; -use middle::def_id::DefId; +use hir::def::Def; +use hir::def_id::DefId; use constrained_type_params as ctp; use coherence; use middle::lang_items::SizedTraitLangItem; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index af32026d47e..ab2276c324b 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -103,7 +103,7 @@ pub use rustc::util; use dep_graph::DepNode; use hir::map as hir_map; -use middle::def::Def; +use hir::def::Def; use rustc::infer::{self, TypeOrigin}; use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index fa3ee80c6da..3b03a713a5b 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -14,7 +14,7 @@ //! We walk the set of items and, for each member, generate new constraints. use dep_graph::DepTrackingMapConfig; -use middle::def_id::DefId; +use hir::def_id::DefId; use middle::resolve_lifetime as rl; use rustc::ty::subst; use rustc::ty::subst::ParamSpace; diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 2f080dae370..70997a1a6ee 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -17,8 +17,8 @@ use syntax::attr::AttrMetaMethods; use rustc::hir; use rustc::middle::cstore::{self, CrateStore}; -use rustc::middle::def::Def; -use rustc::middle::def_id::DefId; +use rustc::hir::def::Def; +use rustc::hir::def_id::DefId; use rustc::ty::{self, TyCtxt}; use rustc::ty::subst; use rustc::middle::stability; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 715d0e759c3..4895022cfac 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -35,8 +35,8 @@ use syntax::ptr::P; use rustc_trans::back::link; use rustc::middle::cstore::{self, CrateStore}; -use rustc::middle::def::Def; -use rustc::middle::def_id::{DefId, DefIndex}; +use rustc::hir::def::Def; +use rustc::hir::def_id::{DefId, DefIndex}; use rustc::ty::subst::{self, ParamSpace, VecPerParamSpace}; use rustc::ty; use rustc::middle::stability; diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index e6a4d882c04..4ba412cdc85 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -29,7 +29,7 @@ use std::mem; use std::collections::HashMap; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::ty::subst; use clean::PathParameters as PP; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 4686e60be87..6b7aa103e1d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -13,7 +13,7 @@ use rustc_lint; use rustc_driver::{driver, target_features, abort_on_err}; use rustc::dep_graph::DepGraph; use rustc::session::{self, config}; -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::middle::privacy::AccessLevels; use rustc::ty::{self, TyCtxt}; use rustc::hir::map as hir_map; diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 9f0b636227f..a43711a3273 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -19,7 +19,7 @@ use std::fmt; use std::iter::repeat; use rustc::middle::cstore::LOCAL_CRATE; -use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId}; +use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId}; use syntax::abi::Abi; use rustc::hir; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index f97d4fee053..d63e704e06b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -56,7 +56,7 @@ use serialize::json::{ToJson, Json, as_json}; use syntax::{abi, ast}; use syntax::feature_gate::UnstableFeatures; use rustc::middle::cstore::LOCAL_CRATE; -use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId}; +use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId}; use rustc::middle::privacy::AccessLevels; use rustc::middle::stability; use rustc::session::config::get_unstable_features_setting; diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 31f00caee43..ff2a9f13e8a 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use rustc::middle::def_id::DefId; +use rustc::hir::def_id::DefId; use rustc::middle::privacy::AccessLevels; use rustc::util::nodemap::DefIdSet; use std::cmp; -- cgit 1.4.1-3-g733a5 From e8a8dfb056fb3654bacd6aaa6acbc4536358df23 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Wed, 6 Apr 2016 13:51:55 +0300 Subject: rustc: retire hir::map's paths. --- src/librustc/hir/map/collector.rs | 3 +- src/librustc/hir/map/mod.rs | 239 +++++---------------- src/librustc/hir/pat_util.rs | 10 +- src/librustc/infer/error_reporting.rs | 10 +- src/librustc/middle/cstore.rs | 5 - src/librustc/ty/item_path.rs | 5 + src/librustc/ty/mod.rs | 33 +-- src/librustc_driver/pretty.rs | 19 +- src/librustc_lint/builtin.rs | 5 +- src/librustc_metadata/astencode.rs | 17 +- src/librustc_metadata/common.rs | 9 +- src/librustc_metadata/csearch.rs | 16 -- src/librustc_metadata/decoder.rs | 26 --- src/librustc_metadata/encoder.rs | 101 +-------- src/librustc_mir/graphviz.rs | 2 +- src/librustc_mir/pretty.rs | 2 +- src/librustc_save_analysis/dump_visitor.rs | 8 +- src/librustc_save_analysis/lib.rs | 12 +- src/librustc_trans/base.rs | 11 +- src/librustc_trans/debuginfo/namespace.rs | 140 ++++++------ src/librustc_trans/debuginfo/type_names.rs | 34 +-- src/librustdoc/clean/inline.rs | 8 +- .../pretty-print-path-suffix/foo_method.pp | 2 +- 23 files changed, 192 insertions(+), 525 deletions(-) (limited to 'src/librustc_metadata/decoder.rs') diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index b1a084ac799..94fa393ae3d 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -14,6 +14,7 @@ use super::MapEntry::*; use hir::*; use hir::intravisit::Visitor; use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex}; +use middle::cstore::InlinedItem; use std::iter::repeat; use syntax::ast::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID}; use syntax::codemap::Span; @@ -46,7 +47,7 @@ impl<'ast> NodeCollector<'ast> { } pub fn extend(krate: &'ast Crate, - parent: &'ast InlinedParent, + parent: &'ast InlinedItem, parent_node: NodeId, parent_def_path: DefPath, parent_def_id: DefId, diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 4096606b001..e1b7afda58b 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -9,7 +9,6 @@ // except according to those terms. pub use self::Node::*; -pub use self::PathElem::*; use self::MapEntry::*; use self::collector::NodeCollector; pub use self::definitions::{Definitions, DefKey, DefPath, DefPathData, @@ -25,7 +24,6 @@ use syntax::abi::Abi; use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID}; use syntax::attr::ThinAttributesExt; use syntax::codemap::{Span, Spanned}; -use syntax::parse::token; use hir::*; use hir::fold::Folder; @@ -33,85 +31,13 @@ use hir::print as pprust; use arena::TypedArena; use std::cell::RefCell; -use std::fmt; use std::io; -use std::iter; use std::mem; -use std::slice; pub mod blocks; mod collector; pub mod definitions; -#[derive(Clone, Copy, PartialEq, Debug)] -pub enum PathElem { - PathMod(Name), - PathName(Name) -} - -impl PathElem { - pub fn name(&self) -> Name { - match *self { - PathMod(name) | PathName(name) => name - } - } -} - -impl fmt::Display for PathElem { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.name()) - } -} - -#[derive(Clone)] -pub struct LinkedPathNode<'a> { - node: PathElem, - next: LinkedPath<'a>, -} - -#[derive(Copy, Clone)] -pub struct LinkedPath<'a>(Option<&'a LinkedPathNode<'a>>); - -impl<'a> LinkedPath<'a> { - pub fn empty() -> LinkedPath<'a> { - LinkedPath(None) - } - - pub fn from(node: &'a LinkedPathNode) -> LinkedPath<'a> { - LinkedPath(Some(node)) - } -} - -impl<'a> Iterator for LinkedPath<'a> { - type Item = PathElem; - - fn next(&mut self) -> Option { - match self.0 { - Some(node) => { - *self = node.next; - Some(node.node) - } - None => None - } - } -} - -/// The type of the iterator used by with_path. -pub type PathElems<'a, 'b> = iter::Chain>, LinkedPath<'b>>; - -pub fn path_to_string>(path: PI) -> String { - let itr = token::get_ident_interner(); - - path.fold(String::new(), |mut s, e| { - let e = itr.get(e.name()); - if !s.is_empty() { - s.push_str("::"); - } - s.push_str(&e[..]); - s - }) -} - #[derive(Copy, Clone, Debug)] pub enum Node<'ast> { NodeItem(&'ast Item), @@ -156,7 +82,7 @@ pub enum MapEntry<'ast> { /// Roots for node trees. RootCrate, - RootInlinedParent(&'ast InlinedParent) + RootInlinedParent(&'ast InlinedItem) } impl<'ast> Clone for MapEntry<'ast> { @@ -165,12 +91,6 @@ impl<'ast> Clone for MapEntry<'ast> { } } -#[derive(Debug)] -pub struct InlinedParent { - path: Vec, - ii: InlinedItem -} - impl<'ast> MapEntry<'ast> { fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> { match node { @@ -233,7 +153,7 @@ impl<'ast> MapEntry<'ast> { pub struct Forest { krate: Crate, pub dep_graph: DepGraph, - inlined_items: TypedArena + inlined_items: TypedArena } impl Forest { @@ -351,8 +271,10 @@ impl<'ast> Map<'ast> { self.definitions.borrow().def_key(def_id.index) } - pub fn def_path_from_id(&self, id: NodeId) -> DefPath { - self.def_path(self.local_def_id(id)) + pub fn def_path_from_id(&self, id: NodeId) -> Option { + self.opt_local_def_id(id).map(|def_id| { + self.def_path(def_id) + }) } pub fn def_path(&self, def_id: DefId) -> DefPath { @@ -551,8 +473,8 @@ impl<'ast> Map<'ast> { pub fn get_parent_did(&self, id: NodeId) -> DefId { let parent = self.get_parent(id); match self.find_entry(parent) { - Some(RootInlinedParent(&InlinedParent {ii: II::TraitItem(did, _), ..})) => did, - Some(RootInlinedParent(&InlinedParent {ii: II::ImplItem(did, _), ..})) => did, + Some(RootInlinedParent(&II::TraitItem(did, _))) | + Some(RootInlinedParent(&II::ImplItem(did, _))) => did, _ => self.local_def_id(parent) } } @@ -634,80 +556,21 @@ impl<'ast> Map<'ast> { } } - /// returns the name associated with the given NodeId's AST - pub fn get_path_elem(&self, id: NodeId) -> PathElem { - let node = self.get(id); - match node { - NodeItem(item) => { - match item.node { - ItemMod(_) | ItemForeignMod(_) => { - PathMod(item.name) - } - _ => PathName(item.name) - } - } - NodeForeignItem(i) => PathName(i.name), - NodeImplItem(ii) => PathName(ii.name), - NodeTraitItem(ti) => PathName(ti.name), - NodeVariant(v) => PathName(v.node.name), - NodeLifetime(lt) => PathName(lt.name), - NodeTyParam(tp) => PathName(tp.name), + /// Returns the name associated with the given NodeId's AST. + pub fn name(&self, id: NodeId) -> Name { + match self.get(id) { + NodeItem(i) => i.name, + NodeForeignItem(i) => i.name, + NodeImplItem(ii) => ii.name, + NodeTraitItem(ti) => ti.name, + NodeVariant(v) => v.node.name, + NodeLifetime(lt) => lt.name, + NodeTyParam(tp) => tp.name, NodeLocal(&Pat { node: PatKind::Ident(_,l,_), .. }) => { - PathName(l.node.name) + l.node.name }, - _ => bug!("no path elem for {:?}", node) - } - } - - pub fn with_path(&self, id: NodeId, f: F) -> T where - F: FnOnce(PathElems) -> T, - { - self.with_path_next(id, LinkedPath::empty(), f) - } - - pub fn path_to_string(&self, id: NodeId) -> String { - self.with_path(id, |path| path_to_string(path)) - } - - fn path_to_str_with_name(&self, id: NodeId, name: Name) -> String { - self.with_path(id, |path| { - path_to_string(path.chain(Some(PathName(name)))) - }) - } - - fn with_path_next(&self, id: NodeId, next: LinkedPath, f: F) -> T where - F: FnOnce(PathElems) -> T, - { - // This function reveals the name of the item and hence is a - // kind of read. This is inefficient, since it walks ancestors - // and we are walking them anyhow, but whatever. - self.read(id); - - let parent = self.get_parent(id); - let parent = match self.find_entry(id) { - Some(EntryForeignItem(..)) => { - // Anonymous extern items go in the parent scope. - self.get_parent(parent) - } - // But tuple struct ctors don't have names, so use the path of its - // parent, the struct item. Similarly with closure expressions. - Some(EntryStructCtor(..)) | Some(EntryExpr(..)) => { - return self.with_path_next(parent, next, f); - } - _ => parent - }; - if parent == id { - match self.find_entry(id) { - Some(RootInlinedParent(data)) => { - f(data.path.iter().cloned().chain(next)) - } - _ => f([].iter().cloned().chain(next)) - } - } else { - self.with_path_next(parent, LinkedPath::from(&LinkedPathNode { - node: self.get_path_elem(id), - next: next - }), f) + NodeStructCtor(_) => self.name(self.get_parent(id)), + _ => bug!("no name for {}", self.node_to_string(id)) } } @@ -958,7 +821,6 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest) -> Map<'ast> { /// Used for items loaded from external crate that are being inlined into this /// crate. pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>, - parent_path: Vec, parent_def_path: DefPath, parent_def_id: DefId, ii: InlinedItem, @@ -978,27 +840,24 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>, II::Foreign(i) => II::Foreign(i.map(|i| fld.fold_foreign_item(i))) }; - let ii_parent = map.forest.inlined_items.alloc(InlinedParent { - path: parent_path, - ii: ii - }); + let ii = map.forest.inlined_items.alloc(ii); let ii_parent_id = fld.new_id(DUMMY_NODE_ID); let mut collector = NodeCollector::extend( map.krate(), - ii_parent, + ii, ii_parent_id, parent_def_path, parent_def_id, mem::replace(&mut *map.map.borrow_mut(), vec![]), mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new())); - ii_parent.ii.visit(&mut collector); + ii.visit(&mut collector); *map.map.borrow_mut() = collector.map; *map.definitions.borrow_mut() = collector.definitions; - &ii_parent.ii + ii } pub trait NodePrinter { @@ -1032,9 +891,24 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { let id_str = format!(" (id={})", id); let id_str = if include_id { &id_str[..] } else { "" }; + let path_str = || { + // This functionality is used for debugging, try to use TyCtxt to get + // the user-friendly path, otherwise fall back to stringifying DefPath. + ::ty::tls::with_opt(|tcx| { + if let Some(tcx) = tcx { + tcx.node_path_str(id) + } else if let Some(path) = map.def_path_from_id(id) { + path.data.into_iter().map(|elem| { + elem.data.to_string() + }).collect::>().join("::") + } else { + String::from("") + } + }) + }; + match map.find(id) { Some(NodeItem(item)) => { - let path_str = map.path_to_str_with_name(id, item.name); let item_str = match item.node { ItemExternCrate(..) => "extern crate", ItemUse(..) => "use", @@ -1050,30 +924,21 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { ItemImpl(..) => "impl", ItemDefaultImpl(..) => "default impl", }; - format!("{} {}{}", item_str, path_str, id_str) + format!("{} {}{}", item_str, path_str(), id_str) } - Some(NodeForeignItem(item)) => { - let path_str = map.path_to_str_with_name(id, item.name); - format!("foreign item {}{}", path_str, id_str) + Some(NodeForeignItem(_)) => { + format!("foreign item {}{}", path_str(), id_str) } Some(NodeImplItem(ii)) => { match ii.node { ImplItemKind::Const(..) => { - format!("assoc const {} in {}{}", - ii.name, - map.path_to_string(id), - id_str) + format!("assoc const {} in {}{}", ii.name, path_str(), id_str) } ImplItemKind::Method(..) => { - format!("method {} in {}{}", - ii.name, - map.path_to_string(id), id_str) + format!("method {} in {}{}", ii.name, path_str(), id_str) } ImplItemKind::Type(_) => { - format!("assoc type {} in {}{}", - ii.name, - map.path_to_string(id), - id_str) + format!("assoc type {} in {}{}", ii.name, path_str(), id_str) } } } @@ -1084,16 +949,12 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { TypeTraitItem(..) => "assoc type", }; - format!("{} {} in {}{}", - kind, - ti.name, - map.path_to_string(id), - id_str) + format!("{} {} in {}{}", kind, ti.name, path_str(), id_str) } Some(NodeVariant(ref variant)) => { format!("variant {} in {}{}", variant.node.name, - map.path_to_string(id), id_str) + path_str(), id_str) } Some(NodeExpr(ref expr)) => { format!("expr {}{}", pprust::expr_to_string(&expr), id_str) @@ -1111,7 +972,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String { format!("block {}{}", pprust::block_to_string(&block), id_str) } Some(NodeStructCtor(_)) => { - format!("struct_ctor {}{}", map.path_to_string(id), id_str) + format!("struct_ctor {}{}", path_str(), id_str) } Some(NodeLifetime(ref l)) => { format!("lifetime {}{}", diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index 5eb4d53ea6a..6cc5a29062f 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -210,14 +210,8 @@ pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option { } pub fn def_to_path(tcx: &TyCtxt, id: DefId) -> hir::Path { - tcx.with_path(id, |path| hir::Path { - global: false, - segments: path.last().map(|elem| hir::PathSegment { - identifier: hir::Ident::from_name(elem.name()), - parameters: hir::PathParameters::none(), - }).into_iter().collect(), - span: DUMMY_SP, - }) + let name = tcx.item_name(id); + hir::Path::from_ident(DUMMY_SP, hir::Ident::from_name(name)) } /// Return variants that are necessary to exist for the pattern to match. diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 5a0d9ec1332..a7553f4eb1f 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -587,13 +587,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { // Only external crates, if either is from a local // module we could have false positives if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate { - let exp_path = self.tcx.with_path(did1, - |p| p.map(|x| x.to_string()) - .collect::>()); - let found_path = self.tcx.with_path(did2, - |p| p.map(|x| x.to_string()) - .collect::>()); - // We compare strings because PathMod and PathName can be different + let exp_path = self.tcx.item_path_str(did1); + let found_path = self.tcx.item_path_str(did2); + // We compare strings because DefPath can be different // for imported and non-imported crates if exp_path == found_path { let crate_name = self.tcx.sess.cstore.crate_name(did1.krate); diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 027792b7439..1f6328187a5 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -166,9 +166,7 @@ pub trait CrateStore<'tcx> : Any { fn repr_attrs(&self, def: DefId) -> Vec; fn item_type(&self, tcx: &TyCtxt<'tcx>, def: DefId) -> ty::TypeScheme<'tcx>; - fn relative_item_path(&self, def: DefId) -> Vec; fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap>; - fn extern_item_path(&self, def: DefId) -> Vec; fn item_name(&self, def: DefId) -> ast::Name; fn item_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId) -> ty::GenericPredicates<'tcx>; @@ -345,12 +343,9 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore { fn repr_attrs(&self, def: DefId) -> Vec { bug!("repr_attrs") } fn item_type(&self, tcx: &TyCtxt<'tcx>, def: DefId) -> ty::TypeScheme<'tcx> { bug!("item_type") } - fn relative_item_path(&self, def: DefId) - -> Vec { bug!("relative_item_path") } fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap> { bug!("visible_parent_map") } - fn extern_item_path(&self, def: DefId) -> Vec { bug!("extern_item_path") } fn item_name(&self, def: DefId) -> ast::Name { bug!("item_name") } fn item_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId) -> ty::GenericPredicates<'tcx> { bug!("item_predicates") } diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 4d88b697416..5c1e19aee7b 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -24,6 +24,11 @@ impl<'tcx> TyCtxt<'tcx> { buffer.into_string() } + /// Returns a string identifying this local node-id. + pub fn node_path_str(&self, id: ast::NodeId) -> String { + self.item_path_str(self.map.local_def_id(id)) + } + /// Returns a string identifying this def-id. This string is /// suitable for user output. It always begins with a crate identifier. pub fn absolute_item_path_str(&self, def_id: DefId) -> String { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 4ff859f5a94..444fea0918f 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -20,7 +20,6 @@ pub use self::fold::TypeFoldable; use dep_graph::{self, DepNode}; use hir::map as ast_map; -use hir::map::LinkedPath; use middle; use middle::cstore::{self, CrateStore, LOCAL_CRATE}; use hir::def::{self, Def, ExportMap}; @@ -2231,39 +2230,9 @@ impl<'tcx> TyCtxt<'tcx> { } } - pub fn with_path(&self, id: DefId, f: F) -> T where - F: FnOnce(ast_map::PathElems) -> T, - { - if let Some(id) = self.map.as_local_node_id(id) { - self.map.with_path(id, f) - } else { - let mut path: Vec<_>; - if let Some(extern_crate) = self.sess.cstore.extern_crate(id.krate) { - if !extern_crate.direct { - // this comes from some crate that we don't have a direct - // path to; we'll settle for just prepending the name of - // the crate. - path = self.sess.cstore.extern_item_path(id) - } else { - // start with the path to the extern crate, then - // add the relative path to the actual item - fn collector(elems: ast_map::PathElems) -> Vec { - elems.collect() - } - path = self.with_path(extern_crate.def_id, collector); - path.extend(self.sess.cstore.relative_item_path(id)); - } - } else { - // if this was injected, just make a path with name of crate - path = self.sess.cstore.extern_item_path(id); - } - f(path.iter().cloned().chain(LinkedPath::empty())) - } - } - pub fn item_name(&self, id: DefId) -> ast::Name { if let Some(id) = self.map.as_local_node_id(id) { - self.map.get_path_elem(id).name() + self.map.name(id) } else { self.sess.cstore.item_name(id) } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index cda5595c102..cde5ba19859 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -256,6 +256,15 @@ trait HirPrinterSupport<'ast>: pprust_hir::PpAnn { /// (Rust does not yet support upcasting from a trait object to /// an object for one of its super-traits.) fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn; + + /// Computes an user-readable representation of a path, if possible. + fn node_path(&self, id: ast::NodeId) -> Option { + self.ast_map().and_then(|map| map.def_path_from_id(id)).map(|path| { + path.data.into_iter().map(|elem| { + elem.data.to_string() + }).collect::>().join("::") + }) + } } struct NoAnn<'ast> { @@ -452,6 +461,10 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> { fn pp_ann<'a>(&'a self) -> &'a pprust_hir::PpAnn { self } + + fn node_path(&self, id: ast::NodeId) -> Option { + Some(self.tcx.node_path_str(id)) + } } impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> { @@ -794,7 +807,7 @@ pub fn pretty_print_input(sess: Session, |annotation, (out,uii), _| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); - let ast_map = annotation.ast_map().expect("--pretty missing ast_map"); + let ast_map = annotation.ast_map().expect("--unpretty missing HIR map"); let mut pp_state = pprust_hir::State::new_from_input(sess.codemap(), sess.diagnostic(), @@ -808,7 +821,9 @@ pub fn pretty_print_input(sess: Session, let node = ast_map.get(node_id); pp_state.print_node(&node)?; pp::space(&mut pp_state.s)?; - pp_state.synth_comment(ast_map.path_to_string(node_id))?; + let path = annotation.node_path(node_id) + .expect("--unpretty missing node paths"); + pp_state.synth_comment(path)?; pp::hardbreak(&mut pp_state.s)?; } pp::eof(&mut pp_state.s) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index fe10ca87b75..5e3a47701eb 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1087,10 +1087,7 @@ impl LateLintPass for MutableTransmutes { ty::TyFnDef(_, _, ref bfty) if bfty.abi == RustIntrinsic => (), _ => return false } - cx.tcx.with_path(def_id, |path| match path.last() { - Some(ref last) => last.name().as_str() == "transmute", - _ => false - }) + cx.tcx.item_name(def_id).as_str() == "transmute" } } } diff --git a/src/librustc_metadata/astencode.rs b/src/librustc_metadata/astencode.rs index 3becc93f8a4..6fd9f27f0fb 100644 --- a/src/librustc_metadata/astencode.rs +++ b/src/librustc_metadata/astencode.rs @@ -85,7 +85,7 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext, InlinedItemRef::ImplItem(_, ii) => ii.id, }; debug!("> Encoding inlined item: {} ({:?})", - ecx.tcx.map.path_to_string(id), + ecx.tcx.node_path_str(id), rbml_w.writer.seek(SeekFrom::Current(0))); // Folding could be avoided with a smarter encoder. @@ -99,7 +99,7 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext, rbml_w.end_tag(); debug!("< Encoded inlined fn: {} ({:?})", - ecx.tcx.map.path_to_string(id), + ecx.tcx.node_path_str(id), rbml_w.writer.seek(SeekFrom::Current(0))); } @@ -124,20 +124,12 @@ impl<'a, 'b, 'c, 'tcx> ast_map::FoldOps for &'a DecodeContext<'b, 'c, 'tcx> { /// ast-map. pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata, tcx: &TyCtxt<'tcx>, - parent_path: Vec, parent_def_path: ast_map::DefPath, parent_did: DefId, ast_doc: rbml::Doc, orig_did: DefId) -> &'tcx InlinedItem { - let mut path_as_str = None; - debug!("> Decoding inlined fn: {:?}::?", - { - // Do an Option dance to use the path after it is moved below. - let s = ast_map::path_to_string(parent_path.iter().cloned()); - path_as_str = Some(s); - path_as_str.as_ref().map(|x| &x[..]) - }); + debug!("> Decoding inlined fn: {:?}", tcx.item_path_str(orig_did)); let mut ast_dsr = reader::Decoder::new(ast_doc); let from_id_range = Decodable::decode(&mut ast_dsr).unwrap(); let to_id_range = reserve_id_range(&tcx.sess, from_id_range); @@ -149,7 +141,6 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata, last_filemap_index: Cell::new(0) }; let ii = ast_map::map_decoded_item(&dcx.tcx.map, - parent_path, parent_def_path, parent_did, decode_ast(ast_doc), @@ -162,7 +153,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata, }; debug!("Fn named: {}", name); debug!("< Decoded inlined fn: {}::{}", - path_as_str.unwrap(), + tcx.item_path_str(parent_did), name); region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, ii); decode_side_tables(dcx, ast_doc); diff --git a/src/librustc_metadata/common.rs b/src/librustc_metadata/common.rs index 22a5289f02b..ea4e2575420 100644 --- a/src/librustc_metadata/common.rs +++ b/src/librustc_metadata/common.rs @@ -86,13 +86,10 @@ pub const tag_item_trait_ref: usize = 0x3b; // discriminator value for variants pub const tag_disr_val: usize = 0x3c; -// used to encode ast_map::PathElem -pub const tag_path: usize = 0x3d; -pub const tag_path_len: usize = 0x3e; -pub const tag_path_elem_mod: usize = 0x3f; -pub const tag_path_elem_name: usize = 0x40; -pub const tag_item_field: usize = 0x41; +// GAP 0x3d, 0x3e, 0x3f, 0x40 +pub const tag_item_field: usize = 0x41; +// GAP 0x42 pub const tag_item_variances: usize = 0x43; /* trait items contain tag_item_trait_item elements, diff --git a/src/librustc_metadata/csearch.rs b/src/librustc_metadata/csearch.rs index bb691cebccd..0b90ad5b4e2 100644 --- a/src/librustc_metadata/csearch.rs +++ b/src/librustc_metadata/csearch.rs @@ -128,22 +128,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore { decoder::get_method_arg_names(&cdata, did.index) } - fn relative_item_path(&self, def: DefId) -> Vec { - let cdata = self.get_crate_data(def.krate); - decoder::get_item_path(&cdata, def.index) - } - - fn extern_item_path(&self, def: DefId) -> Vec { - let cdata = self.get_crate_data(def.krate); - let path = decoder::get_item_path(&cdata, def.index); - - let mut r = Vec::with_capacity(path.len() + 1); - let crate_name = hir_map::PathMod(token::intern(&cdata.name)); - r.push(crate_name); - r.extend_from_slice(&path); - r - } - fn item_name(&self, def: DefId) -> ast::Name { let cdata = self.get_crate_data(def.krate); decoder::get_item_name(&self.intr, &cdata, def.index) diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index e6f538255ac..6b53edbbff1 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -255,22 +255,6 @@ fn item_trait_ref<'tcx>(doc: rbml::Doc, tcx: &TyCtxt<'tcx>, cdata: Cmd) doc_trait_ref(tp, tcx, cdata) } -fn item_path(item_doc: rbml::Doc) -> Vec { - let path_doc = reader::get_doc(item_doc, tag_path); - reader::docs(path_doc).filter_map(|(tag, elt_doc)| { - if tag == tag_path_elem_mod { - let s = elt_doc.as_str_slice(); - Some(hir_map::PathMod(token::intern(s))) - } else if tag == tag_path_elem_name { - let s = elt_doc.as_str_slice(); - Some(hir_map::PathName(token::intern(s))) - } else { - // ignore tag_path_len element - None - } - }).collect() -} - fn item_name(intr: &IdentInterner, item: rbml::Doc) -> ast::Name { let name = reader::get_doc(item, tag_paths_data_name); let string = name.as_str_slice(); @@ -786,10 +770,6 @@ pub fn each_top_level_item_of_crate(intr: Rc, callback) } -pub fn get_item_path(cdata: Cmd, id: DefIndex) -> Vec { - item_path(cdata.lookup_item(id)) -} - pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex) -> ast::Name { item_name(intr, cdata.lookup_item(id)) } @@ -803,14 +783,11 @@ pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &TyCtxt<'tcx>, id: DefIndex) krate: cdata.cnum, index: def_key(cdata, id).parent.unwrap() }; - let mut parent_path = item_path(item_doc); - parent_path.pop(); let mut parent_def_path = def_path(cdata, id); parent_def_path.data.pop(); if let Some(ast_doc) = reader::maybe_get_doc(item_doc, tag_ast as usize) { let ii = decode_inlined_item(cdata, tcx, - parent_path, parent_def_path, parent_def_id, ast_doc, @@ -823,15 +800,12 @@ pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &TyCtxt<'tcx>, id: DefIndex) krate: cdata.cnum, index: def_key(cdata, parent_def_id.index).parent.unwrap() }; - let mut grandparent_path = parent_path; - grandparent_path.pop(); let mut grandparent_def_path = parent_def_path; grandparent_def_path.data.pop(); let parent_doc = cdata.lookup_item(parent_did.index); if let Some(ast_doc) = reader::maybe_get_doc(parent_doc, tag_ast as usize) { let ii = decode_inlined_item(cdata, tcx, - grandparent_path, grandparent_def_path, grandparent_def_id, ast_doc, diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 83ffd8afbeb..d45650159e3 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -31,8 +31,6 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::util::IntTypeExt; use rustc::hir::svh::Svh; -use rustc::hir::map::{LinkedPath, PathElem, PathElems}; -use rustc::hir::map as ast_map; use rustc::mir::mir_map::MirMap; use rustc::session::config; use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet}; @@ -300,26 +298,11 @@ fn encode_enum_variant_info<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, } encode_bounds_and_type_for_item(rbml_w, ecx, index, variant_node_id); - ecx.tcx.map.with_path(variant_node_id, |path| encode_path(rbml_w, path)); rbml_w.end_tag(); disr_val = disr_val.wrap_incr(); } } -fn encode_path>(rbml_w: &mut Encoder, path: PI) { - let path = path.collect::>(); - rbml_w.start_tag(tag_path); - rbml_w.wr_tagged_u32(tag_path_len, path.len() as u32); - for pe in &path { - let tag = match *pe { - ast_map::PathMod(_) => tag_path_elem_mod, - ast_map::PathName(_) => tag_path_elem_name - }; - rbml_w.wr_tagged_str(tag, &pe.name().as_str()); - } - rbml_w.end_tag(); -} - /// Iterates through "auxiliary node IDs", which are node IDs that describe /// top-level items that are sub-items of the given item. Specifically: /// @@ -371,7 +354,6 @@ fn encode_info_for_mod(ecx: &EncodeContext, md: &hir::Mod, attrs: &[ast::Attribute], id: NodeId, - path: PathElems, name: Name, vis: hir::Visibility) { rbml_w.start_tag(tag_items_data_item); @@ -393,7 +375,6 @@ fn encode_info_for_mod(ecx: &EncodeContext, }); } - encode_path(rbml_w, path.clone()); encode_visibility(rbml_w, vis); let stab = stability::lookup_stability(ecx.tcx, ecx.tcx.map.local_def_id(id)); @@ -521,7 +502,6 @@ fn encode_info_for_struct_ctor<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, }); encode_bounds_and_type_for_item(rbml_w, ecx, index, ctor_id); encode_name(rbml_w, name); - ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path)); encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(struct_id)); if ecx.item_symbols.borrow().contains_key(&ctor_id) { @@ -637,7 +617,6 @@ fn encode_info_for_associated_const<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w: &mut Encoder, index: &mut CrateIndex<'tcx>, associated_const: &ty::AssociatedConst, - impl_path: PathElems, parent_id: NodeId, impl_item_opt: Option<&hir::ImplItem>) { debug!("encode_info_for_associated_const({:?},{:?})", @@ -663,9 +642,6 @@ fn encode_info_for_associated_const<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_stability(rbml_w, stab); encode_deprecation(rbml_w, depr); - let elem = ast_map::PathName(associated_const.name); - encode_path(rbml_w, impl_path.chain(Some(elem))); - if let Some(ii) = impl_item_opt { encode_attributes(rbml_w, &ii.attrs); encode_defaultness(rbml_w, ii.defaultness); @@ -683,7 +659,6 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w: &mut Encoder, index: &mut CrateIndex<'tcx>, m: &ty::Method<'tcx>, - impl_path: PathElems, is_default_impl: bool, parent_id: NodeId, impl_item_opt: Option<&hir::ImplItem>) { @@ -705,8 +680,6 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, let m_node_id = ecx.local_id(m.def_id); encode_bounds_and_type_for_item(rbml_w, ecx, index, m_node_id); - let elem = ast_map::PathName(m.name); - encode_path(rbml_w, impl_path.chain(Some(elem))); if let Some(impl_item) = impl_item_opt { if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { encode_attributes(rbml_w, &impl_item.attrs); @@ -738,7 +711,6 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w: &mut Encoder, index: &mut CrateIndex<'tcx>, associated_type: &ty::AssociatedType<'tcx>, - impl_path: PathElems, parent_id: NodeId, impl_item_opt: Option<&hir::ImplItem>) { debug!("encode_info_for_associated_type({:?},{:?})", @@ -760,9 +732,6 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_stability(rbml_w, stab); encode_deprecation(rbml_w, depr); - let elem = ast_map::PathName(associated_type.name); - encode_path(rbml_w, impl_path.chain(Some(elem))); - if let Some(ii) = impl_item_opt { encode_attributes(rbml_w, &ii.attrs); encode_defaultness(rbml_w, ii.defaultness); @@ -886,14 +855,13 @@ fn encode_xrefs<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w: &mut Encoder, item: &hir::Item, - index: &mut CrateIndex<'tcx>, - path: PathElems, - vis: hir::Visibility) { + index: &mut CrateIndex<'tcx>) { let tcx = ecx.tcx; debug!("encoding info for item at {}", tcx.sess.codemap().span_to_string(item.span)); + let vis = item.vis; let def_id = ecx.tcx.map.local_def_id(item.id); let stab = stability::lookup_stability(tcx, ecx.tcx.map.local_def_id(item.id)); let depr = stability::lookup_deprecation(tcx, ecx.tcx.map.local_def_id(item.id)); @@ -911,7 +879,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_bounds_and_type_for_item(rbml_w, ecx, index, item.id); encode_symbol(ecx, rbml_w, item.id); encode_name(rbml_w, item.name); - encode_path(rbml_w, path); encode_visibility(rbml_w, vis); encode_stability(rbml_w, stab); encode_deprecation(rbml_w, depr); @@ -925,7 +892,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_family(rbml_w, 'C'); encode_bounds_and_type_for_item(rbml_w, ecx, index, item.id); encode_name(rbml_w, item.name); - encode_path(rbml_w, path); encode_attributes(rbml_w, &item.attrs); encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item)); encode_mir(ecx, rbml_w, item.id); @@ -942,7 +908,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, let tps_len = generics.ty_params.len(); encode_bounds_and_type_for_item(rbml_w, ecx, index, item.id); encode_name(rbml_w, item.name); - encode_path(rbml_w, path); encode_attributes(rbml_w, &item.attrs); let needs_inline = tps_len > 0 || attr::requests_inline(&item.attrs); if needs_inline || constness == hir::Constness::Const { @@ -966,7 +931,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, m, &item.attrs, item.id, - path, item.name, item.vis); } @@ -976,7 +940,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_def_id_and_key(ecx, rbml_w, def_id); encode_family(rbml_w, 'n'); encode_name(rbml_w, item.name); - encode_path(rbml_w, path); // Encode all the items in this module. for foreign_item in &fm.items { @@ -995,7 +958,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_family(rbml_w, 'y'); encode_bounds_and_type_for_item(rbml_w, ecx, index, item.id); encode_name(rbml_w, item.name); - encode_path(rbml_w, path); encode_visibility(rbml_w, vis); encode_stability(rbml_w, stab); encode_deprecation(rbml_w, depr); @@ -1017,7 +979,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, } encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item)); encode_mir(ecx, rbml_w, item.id); - encode_path(rbml_w, path); // Encode inherent implementations for this enumeration. encode_inherent_implementations(ecx, rbml_w, def_id); @@ -1053,7 +1014,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_item_variances(rbml_w, ecx, item.id); encode_name(rbml_w, item.name); encode_attributes(rbml_w, &item.attrs); - encode_path(rbml_w, path.clone()); encode_stability(rbml_w, stab); encode_deprecation(rbml_w, depr); encode_visibility(rbml_w, vis); @@ -1156,7 +1116,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, }); encode_parent_impl(rbml_w, parent); } - encode_path(rbml_w, path.clone()); encode_stability(rbml_w, stab); encode_deprecation(rbml_w, depr); rbml_w.end_tag(); @@ -1179,7 +1138,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w, index, &associated_const, - path.clone(), item.id, ast_item) } @@ -1188,7 +1146,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w, index, &method_type, - path.clone(), false, item.id, ast_item) @@ -1198,7 +1155,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w, index, &associated_type, - path.clone(), item.id, ast_item) } @@ -1250,7 +1206,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w.wr_tagged_u64(tag_mod_child, def_to_u64(method_def_id.def_id())); } - encode_path(rbml_w, path.clone()); // Encode inherent implementations for this trait. encode_inherent_implementations(ecx, rbml_w, def_id); @@ -1281,10 +1236,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_def_id_and_key(ecx, rbml_w, associated_const.def_id); encode_visibility(rbml_w, associated_const.vis); - let elem = ast_map::PathName(associated_const.name); - encode_path(rbml_w, - path.clone().chain(Some(elem))); - encode_family(rbml_w, 'C'); encode_bounds_and_type_for_item(rbml_w, ecx, index, @@ -1297,10 +1248,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_method_ty_fields(ecx, rbml_w, index, &method_ty); - let elem = ast_map::PathName(method_ty.name); - encode_path(rbml_w, - path.clone().chain(Some(elem))); - match method_ty.explicit_self { ty::ExplicitSelfCategory::Static => { encode_family(rbml_w, @@ -1320,11 +1267,6 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, ty::TypeTraitItem(associated_type) => { encode_name(rbml_w, associated_type.name); encode_def_id_and_key(ecx, rbml_w, associated_type.def_id); - - let elem = ast_map::PathName(associated_type.name); - encode_path(rbml_w, - path.clone().chain(Some(elem))); - encode_item_sort(rbml_w, 't'); encode_family(rbml_w, 'y'); @@ -1386,10 +1328,10 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, fn encode_info_for_foreign_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, rbml_w: &mut Encoder, nitem: &hir::ForeignItem, - index: &mut CrateIndex<'tcx>, - path: PathElems, - abi: Abi) { + index: &mut CrateIndex<'tcx>) { + debug!("writing foreign item {}", ecx.tcx.node_path_str(nitem.id)); let def_id = ecx.tcx.map.local_def_id(nitem.id); + let abi = ecx.tcx.map.get_foreign_abi(nitem.id); index.record(def_id, rbml_w); rbml_w.start_tag(tag_items_data_item); @@ -1429,7 +1371,6 @@ fn encode_info_for_foreign_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_name(rbml_w, nitem.name); } } - encode_path(rbml_w, path); rbml_w.end_tag(); } @@ -1454,8 +1395,6 @@ fn my_visit_expr(expr: &hir::Expr, ecx.tcx.closure_kind(def_id).encode(rbml_w).unwrap(); rbml_w.end_tag(); - ecx.tcx.map.with_path(expr.id, |path| encode_path(rbml_w, path)); - assert!(ecx.mir_map.map.contains_key(&expr.id)); encode_mir(ecx, rbml_w, expr.id); @@ -1465,31 +1404,6 @@ fn my_visit_expr(expr: &hir::Expr, } } -fn my_visit_item<'a, 'tcx>(i: &hir::Item, - rbml_w: &mut Encoder, - ecx: &EncodeContext<'a, 'tcx>, - index: &mut CrateIndex<'tcx>) { - ecx.tcx.map.with_path(i.id, |path| { - encode_info_for_item(ecx, rbml_w, i, index, path, i.vis); - }); -} - -fn my_visit_foreign_item<'a, 'tcx>(ni: &hir::ForeignItem, - rbml_w: &mut Encoder, - ecx: &EncodeContext<'a, 'tcx>, - index: &mut CrateIndex<'tcx>) { - debug!("writing foreign item {}::{}", - ecx.tcx.map.path_to_string(ni.id), - ni.name); - - let abi = ecx.tcx.map.get_foreign_abi(ni.id); - ecx.tcx.map.with_path(ni.id, |path| { - encode_info_for_foreign_item(ecx, rbml_w, - ni, index, - path, abi); - }); -} - struct EncodeVisitor<'a, 'b:'a, 'c:'a, 'tcx:'c> { rbml_w_for_visit_item: &'a mut Encoder<'b>, ecx: &'a EncodeContext<'c,'tcx>, @@ -1503,11 +1417,11 @@ impl<'a, 'b, 'c, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'c, 'tcx> { } fn visit_item(&mut self, i: &'tcx hir::Item) { intravisit::walk_item(self, i); - my_visit_item(i, self.rbml_w_for_visit_item, self.ecx, self.index); + encode_info_for_item(self.ecx, self.rbml_w_for_visit_item, i, self.index); } fn visit_foreign_item(&mut self, ni: &'tcx hir::ForeignItem) { intravisit::walk_foreign_item(self, ni); - my_visit_foreign_item(ni, self.rbml_w_for_visit_item, self.ecx, self.index); + encode_info_for_foreign_item(self.ecx, self.rbml_w_for_visit_item, ni, self.index); } } @@ -1528,7 +1442,6 @@ fn encode_info_for_items<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, &krate.module, &[], CRATE_NODE_ID, - [].iter().cloned().chain(LinkedPath::empty()), syntax::parse::token::intern(&ecx.link_meta.crate_name), hir::Public); diff --git a/src/librustc_mir/graphviz.rs b/src/librustc_mir/graphviz.rs index 959b1fdef52..069bd7826bc 100644 --- a/src/librustc_mir/graphviz.rs +++ b/src/librustc_mir/graphviz.rs @@ -118,7 +118,7 @@ fn write_edges(source: BasicBlock, mir: &Mir, w: &mut W) -> io::Result /// all the variables and temporaries. fn write_graph_label(tcx: &ty::TyCtxt, nid: NodeId, mir: &Mir, w: &mut W) -> io::Result<()> { - write!(w, " label= io::Result<()> { - write!(w, "fn {}(", tcx.map.path_to_string(nid))?; + write!(w, "fn {}(", tcx.node_path_str(nid))?; // fn argument types. for (i, arg) in mir.arg_decls.iter().enumerate() { diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index c724091a2ec..da0e8ba78cf 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -519,7 +519,7 @@ where D: Dump span: Span, typ: &ast::Ty, expr: &ast::Expr) { - let qualname = format!("::{}", self.tcx.map.path_to_string(id)); + let qualname = format!("::{}", self.tcx.node_path_str(id)); let sub_span = self.span.sub_span_after_keyword(span, keywords::Const); @@ -544,7 +544,7 @@ where D: Dump item: &ast::Item, def: &ast::VariantData, ty_params: &ast::Generics) { - let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); + let qualname = format!("::{}", self.tcx.node_path_str(item.id)); let val = self.span.snippet(item.span); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Struct); @@ -677,7 +677,7 @@ where D: Dump generics: &ast::Generics, trait_refs: &ast::TyParamBounds, methods: &[ast::TraitItem]) { - let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); + let qualname = format!("::{}", self.tcx.node_path_str(item.id)); let val = self.span.snippet(item.span); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Trait); if !self.span.filter_generated(sub_span, item.span) { @@ -1108,7 +1108,7 @@ impl<'l, 'tcx, 'v, D: Dump + 'l> Visitor<'v> for DumpVisitor<'l, 'tcx, D> { self.nest(item.id, |v| visit::walk_mod(v, m)); } Ty(ref ty, ref ty_params) => { - let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); + let qualname = format!("::{}", self.tcx.node_path_str(item.id)); let value = ty_to_string(&ty); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type); if !self.span.filter_generated(sub_span, item.span) { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 98c0be1c93c..da4c8770b7e 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -116,7 +116,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { pub fn get_item_data(&self, item: &ast::Item) -> Option { match item.node { ast::ItemKind::Fn(..) => { - let name = self.tcx.map.path_to_string(item.id); + let name = self.tcx.node_path_str(item.id); let qualname = format!("::{}", name); let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Fn); filter!(self.span_utils, sub_span, item.span, None); @@ -130,7 +130,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { })) } ast::ItemKind::Static(ref typ, mt, ref expr) => { - let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); + let qualname = format!("::{}", self.tcx.node_path_str(item.id)); // If the variable is immutable, save the initialising expression. let (value, keyword) = match mt { @@ -153,7 +153,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { })) } ast::ItemKind::Const(ref typ, ref expr) => { - let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); + let qualname = format!("::{}", self.tcx.node_path_str(item.id)); let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Const); filter!(self.span_utils, sub_span, item.span, None); Some(Data::VariableData(VariableData { @@ -167,7 +167,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { })) } ast::ItemKind::Mod(ref m) => { - let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); + let qualname = format!("::{}", self.tcx.node_path_str(item.id)); let cm = self.tcx.sess.codemap(); let filename = cm.span_to_filename(m.inner); @@ -184,7 +184,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { })) } ast::ItemKind::Enum(..) => { - let enum_name = format!("::{}", self.tcx.map.path_to_string(item.id)); + let enum_name = format!("::{}", self.tcx.node_path_str(item.id)); let val = self.span_utils.snippet(item.span); let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Enum); filter!(self.span_utils, sub_span, item.span, None); @@ -246,7 +246,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { scope: NodeId) -> Option { match field.node.kind { ast::NamedField(ident, _) => { - let qualname = format!("::{}::{}", self.tcx.map.path_to_string(scope), ident); + let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident); let typ = self.tcx.node_types().get(&field.node.id).unwrap().to_string(); let sub_span = self.span_utils.sub_span_before_token(field.span, token::Colon); filter!(self.span_utils, sub_span, field.span, None); diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 4f1585eeaca..c8ed4e629e4 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -1351,7 +1351,7 @@ fn build_cfg(tcx: &TyCtxt, id: ast::NodeId) -> (ast::NodeId, Option) { None if id == ast::DUMMY_NODE_ID => return (ast::DUMMY_NODE_ID, None), _ => bug!("unexpected variant in has_nested_returns: {}", - tcx.map.path_to_string(id)), + tcx.node_path_str(id)), }; (blk.id, Some(cfg::CFG::new(tcx, blk))) @@ -1412,9 +1412,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> { let local_id = def_id.and_then(|id| ccx.tcx().map.as_local_node_id(id)); debug!("FunctionContext::new(path={}, def_id={:?}, param_substs={:?})", - inlined_id.map_or(String::new(), |id| { - ccx.tcx().map.path_to_string(id).to_string() - }), + inlined_id.map_or(String::new(), |id| ccx.tcx().node_path_str(id)), def_id, param_substs); @@ -1906,7 +1904,7 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, llfndecl: ValueRef, param_substs: &'tcx Substs<'tcx>, id: ast::NodeId) { - let _s = StatRecorder::new(ccx, ccx.tcx().map.path_to_string(id).to_string()); + let _s = StatRecorder::new(ccx, ccx.tcx().node_path_str(id)); debug!("trans_fn(param_substs={:?})", param_substs); let _icx = push_ctxt("trans_fn"); let fn_ty = ccx.tcx().node_id_to_type(id); @@ -2446,8 +2444,7 @@ pub fn exported_name<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, _ => { if attr::contains_name(attrs, "no_mangle") { // Don't mangle - let path = ccx.tcx().map.def_path_from_id(id); - path.data.last().unwrap().data.to_string() + ccx.tcx().map.name(id).as_str().to_string() } else { match weak_lang_items::link_name(attrs) { Some(name) => name.to_string(), diff --git a/src/librustc_trans/debuginfo/namespace.rs b/src/librustc_trans/debuginfo/namespace.rs index c1487f56956..5272a4fbbb7 100644 --- a/src/librustc_trans/debuginfo/namespace.rs +++ b/src/librustc_trans/debuginfo/namespace.rs @@ -19,6 +19,7 @@ use rustc::hir::map as hir_map; use common::CrateContext; use std::ffi::CString; +use std::iter::once; use std::ptr; use std::rc::{Rc, Weak}; use syntax::ast; @@ -51,85 +52,76 @@ impl NamespaceTreeNode { } } -pub fn crate_root_namespace<'a>(cx: &'a CrateContext) -> &'a str { - &cx.link_meta().crate_name -} - pub fn namespace_for_item(cx: &CrateContext, def_id: DefId) -> Rc { - cx.tcx().with_path(def_id, |path| { - // prepend crate name if not already present - let krate = if def_id.is_local() { - let crate_namespace_name = token::intern(crate_root_namespace(cx)); - Some(hir_map::PathMod(crate_namespace_name)) - } else { - None + // prepend crate name. + // This shouldn't need a roundtrip through InternedString. + let krate = token::intern(&cx.tcx().crate_name(def_id.krate)); + let krate = hir_map::DefPathData::TypeNs(krate); + let path = cx.tcx().def_path(def_id).data; + let mut path = once(krate).chain(path.into_iter().map(|e| e.data)).peekable(); + + let mut current_key = Vec::new(); + let mut parent_node: Option> = None; + + // Create/Lookup namespace for each element of the path. + loop { + // Emulate a for loop so we can use peek below. + let path_element = match path.next() { + Some(e) => e, + None => break }; - let mut path = krate.into_iter().chain(path).peekable(); - - let mut current_key = Vec::new(); - let mut parent_node: Option> = None; - - // Create/Lookup namespace for each element of the path. - loop { - // Emulate a for loop so we can use peek below. - let path_element = match path.next() { - Some(e) => e, - None => break - }; - // Ignore the name of the item (the last path element). - if path.peek().is_none() { - break; - } - - let name = path_element.name(); - current_key.push(name); - - let existing_node = debug_context(cx).namespace_map.borrow() - .get(¤t_key).cloned(); - let current_node = match existing_node { - Some(existing_node) => existing_node, - None => { - // create and insert - let parent_scope = match parent_node { - Some(ref node) => node.scope, - None => ptr::null_mut() - }; - let namespace_name = name.as_str(); - let namespace_name = CString::new(namespace_name.as_bytes()).unwrap(); - let scope = unsafe { - llvm::LLVMDIBuilderCreateNameSpace( - DIB(cx), - parent_scope, - namespace_name.as_ptr(), - // cannot reconstruct file ... - ptr::null_mut(), - // ... or line information, but that's not so important. - 0) - }; - - let node = Rc::new(NamespaceTreeNode { - name: name, - scope: scope, - parent: parent_node.map(|parent| Rc::downgrade(&parent)), - }); - - debug_context(cx).namespace_map.borrow_mut() - .insert(current_key.clone(), node.clone()); - - node - } - }; - - parent_node = Some(current_node); + // Ignore the name of the item (the last path element). + if path.peek().is_none() { + break; } - match parent_node { - Some(node) => node, + // This shouldn't need a roundtrip through InternedString. + let namespace_name = path_element.as_interned_str(); + let name = token::intern(&namespace_name); + current_key.push(name); + + let existing_node = debug_context(cx).namespace_map.borrow() + .get(¤t_key).cloned(); + let current_node = match existing_node { + Some(existing_node) => existing_node, None => { - bug!("debuginfo::namespace_for_item(): \ - path too short for {:?}", - def_id); + // create and insert + let parent_scope = match parent_node { + Some(ref node) => node.scope, + None => ptr::null_mut() + }; + let namespace_name = CString::new(namespace_name.as_bytes()).unwrap(); + let scope = unsafe { + llvm::LLVMDIBuilderCreateNameSpace( + DIB(cx), + parent_scope, + namespace_name.as_ptr(), + // cannot reconstruct file ... + ptr::null_mut(), + // ... or line information, but that's not so important. + 0) + }; + + let node = Rc::new(NamespaceTreeNode { + name: name, + scope: scope, + parent: parent_node.map(|parent| Rc::downgrade(&parent)), + }); + + debug_context(cx).namespace_map.borrow_mut() + .insert(current_key.clone(), node.clone()); + + node } + }; + + parent_node = Some(current_node); + } + + match parent_node { + Some(node) => node, + None => { + bug!("debuginfo::namespace_for_item: path too short for {:?}", def_id); } - }) + } } diff --git a/src/librustc_trans/debuginfo/type_names.rs b/src/librustc_trans/debuginfo/type_names.rs index 0169734ad3b..6fdd6a2c1d1 100644 --- a/src/librustc_trans/debuginfo/type_names.rs +++ b/src/librustc_trans/debuginfo/type_names.rs @@ -10,8 +10,6 @@ // Type Names for Debug Info. -use super::namespace::crate_root_namespace; - use common::CrateContext; use rustc::hir::def_id::DefId; use rustc::infer; @@ -163,31 +161,15 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, def_id: DefId, qualified: bool, output: &mut String) { - cx.tcx().with_path(def_id, |path| { - if qualified { - if def_id.is_local() { - output.push_str(crate_root_namespace(cx)); - output.push_str("::"); - } - - let mut path_element_count = 0; - for path_element in path { - output.push_str(&path_element.name().as_str()); - output.push_str("::"); - path_element_count += 1; - } - - if path_element_count == 0 { - bug!("debuginfo: Encountered empty item path!"); - } - - output.pop(); - output.pop(); - } else { - let name = path.last().expect("debuginfo: Empty item path?").name(); - output.push_str(&name.as_str()); + if qualified { + output.push_str(&cx.tcx().crate_name(def_id.krate)); + for path_element in cx.tcx().def_path(def_id).data { + output.push_str("::"); + output.push_str(&path_element.data.as_interned_str()); } - }); + } else { + output.push_str(&cx.tcx().item_name(def_id).as_str()); + } } // Pushes the type parameters in the given `Substs` to the output string. diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 70997a1a6ee..8c65eb8dbd3 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -11,6 +11,7 @@ //! Support for inlining external documentation into the current AST. use std::collections::HashSet; +use std::iter::once; use syntax::ast; use syntax::attr::AttrMetaMethods; @@ -140,8 +141,11 @@ pub fn load_attrs(cx: &DocContext, tcx: &TyCtxt, /// source links back to the original item. pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) { if let Some(tcx) = cx.tcx_opt() { - let fqn = tcx.sess.cstore.extern_item_path(did); - let fqn = fqn.into_iter().map(|i| i.to_string()).collect(); + let crate_name = tcx.sess.cstore.crate_name(did.krate).to_string(); + let relative = tcx.def_path(did).data.into_iter().map(|elem| { + elem.data.to_string() + }); + let fqn = once(crate_name).chain(relative).collect(); cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind)); } } diff --git a/src/test/run-make/pretty-print-path-suffix/foo_method.pp b/src/test/run-make/pretty-print-path-suffix/foo_method.pp index 4879fbfe6d3..696e0544fdc 100644 --- a/src/test/run-make/pretty-print-path-suffix/foo_method.pp +++ b/src/test/run-make/pretty-print-path-suffix/foo_method.pp @@ -13,4 +13,4 @@ fn foo_method(&self) -> &'static str { return "i am very similar to foo."; } -/* nest::S::foo_method */ +/* nest::{{impl}}::foo_method */ -- cgit 1.4.1-3-g733a5