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 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