From bcb98bdc348ba58f2f8ba936412001eb9ebbeb14 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 13:55:08 +0100 Subject: [PATCH 01/11] canonicalize imports in map::block --- src/librustc/hir/map/blocks.rs | 106 ++++++++++++++++----------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 2cd44770b02cb..990acad2d50b2 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -12,8 +12,8 @@ //! for the `Code` associated with a particular NodeId. use crate::hir::intravisit::FnKind; -use crate::hir::map; -use rustc_hir as ast; +use crate::hir::map::Map; +use rustc_hir as hir; use rustc_hir::{Expr, FnDecl, Node}; use rustc_span::Span; use syntax::ast::{Attribute, Ident}; @@ -39,37 +39,37 @@ trait MaybeFnLike { fn is_fn_like(&self) -> bool; } -impl MaybeFnLike for ast::Item<'_> { +impl MaybeFnLike for hir::Item<'_> { fn is_fn_like(&self) -> bool { match self.kind { - ast::ItemKind::Fn(..) => true, + hir::ItemKind::Fn(..) => true, _ => false, } } } -impl MaybeFnLike for ast::ImplItem<'_> { +impl MaybeFnLike for hir::ImplItem<'_> { fn is_fn_like(&self) -> bool { match self.kind { - ast::ImplItemKind::Method(..) => true, + hir::ImplItemKind::Method(..) => true, _ => false, } } } -impl MaybeFnLike for ast::TraitItem<'_> { +impl MaybeFnLike for hir::TraitItem<'_> { fn is_fn_like(&self) -> bool { match self.kind { - ast::TraitItemKind::Method(_, ast::TraitMethod::Provided(_)) => true, + hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true, _ => false, } } } -impl MaybeFnLike for ast::Expr<'_> { +impl MaybeFnLike for hir::Expr<'_> { fn is_fn_like(&self) -> bool { match self.kind { - ast::ExprKind::Closure(..) => true, + hir::ExprKind::Closure(..) => true, _ => false, } } @@ -85,7 +85,7 @@ pub enum Code<'a> { } impl<'a> Code<'a> { - pub fn id(&self) -> ast::HirId { + pub fn id(&self) -> hir::HirId { match *self { Code::FnLike(node) => node.id(), Code::Expr(block) => block.hir_id, @@ -93,13 +93,13 @@ impl<'a> Code<'a> { } /// Attempts to construct a Code from presumed FnLike or Expr node input. - pub fn from_node(map: &map::Map<'a>, id: ast::HirId) -> Option> { + pub fn from_node(map: &Map<'a>, id: hir::HirId) -> Option> { match map.get(id) { - map::Node::Block(_) => { + Node::Block(_) => { // Use the parent, hopefully an expression node. Code::from_node(map, map.get_parent_node(id)) } - map::Node::Expr(expr) => Some(Code::Expr(expr)), + Node::Expr(expr) => Some(Code::Expr(expr)), node => FnLikeNode::from_node(node).map(Code::FnLike), } } @@ -109,12 +109,12 @@ impl<'a> Code<'a> { /// use when implementing FnLikeNode operations. struct ItemFnParts<'a> { ident: Ident, - decl: &'a ast::FnDecl<'a>, - header: ast::FnHeader, - vis: &'a ast::Visibility<'a>, - generics: &'a ast::Generics<'a>, - body: ast::BodyId, - id: ast::HirId, + decl: &'a hir::FnDecl<'a>, + header: hir::FnHeader, + vis: &'a hir::Visibility<'a>, + generics: &'a hir::Generics<'a>, + body: hir::BodyId, + id: hir::HirId, span: Span, attrs: &'a [Attribute], } @@ -123,8 +123,8 @@ struct ItemFnParts<'a> { /// for use when implementing FnLikeNode operations. struct ClosureParts<'a> { decl: &'a FnDecl<'a>, - body: ast::BodyId, - id: ast::HirId, + body: hir::BodyId, + id: hir::HirId, span: Span, attrs: &'a [Attribute], } @@ -132,8 +132,8 @@ struct ClosureParts<'a> { impl<'a> ClosureParts<'a> { fn new( d: &'a FnDecl<'a>, - b: ast::BodyId, - id: ast::HirId, + b: hir::BodyId, + id: hir::HirId, s: Span, attrs: &'a [Attribute], ) -> Self { @@ -145,19 +145,19 @@ impl<'a> FnLikeNode<'a> { /// Attempts to construct a FnLikeNode from presumed FnLike node input. pub fn from_node(node: Node<'_>) -> Option> { let fn_like = match node { - map::Node::Item(item) => item.is_fn_like(), - map::Node::TraitItem(tm) => tm.is_fn_like(), - map::Node::ImplItem(it) => it.is_fn_like(), - map::Node::Expr(e) => e.is_fn_like(), + Node::Item(item) => item.is_fn_like(), + Node::TraitItem(tm) => tm.is_fn_like(), + Node::ImplItem(it) => it.is_fn_like(), + Node::Expr(e) => e.is_fn_like(), _ => false, }; fn_like.then_some(FnLikeNode { node }) } - pub fn body(self) -> ast::BodyId { + pub fn body(self) -> hir::BodyId { self.handle( |i: ItemFnParts<'a>| i.body, - |_, _, _: &'a ast::FnSig<'a>, _, body: ast::BodyId, _, _| body, + |_, _, _: &'a hir::FnSig<'a>, _, body: hir::BodyId, _, _| body, |c: ClosureParts<'a>| c.body, ) } @@ -165,7 +165,7 @@ impl<'a> FnLikeNode<'a> { pub fn decl(self) -> &'a FnDecl<'a> { self.handle( |i: ItemFnParts<'a>| &*i.decl, - |_, _, sig: &'a ast::FnSig<'a>, _, _, _, _| &sig.decl, + |_, _, sig: &'a hir::FnSig<'a>, _, _, _, _| &sig.decl, |c: ClosureParts<'a>| c.decl, ) } @@ -173,29 +173,29 @@ impl<'a> FnLikeNode<'a> { pub fn span(self) -> Span { self.handle( |i: ItemFnParts<'_>| i.span, - |_, _, _: &'a ast::FnSig<'a>, _, _, span, _| span, + |_, _, _: &'a hir::FnSig<'a>, _, _, span, _| span, |c: ClosureParts<'_>| c.span, ) } - pub fn id(self) -> ast::HirId { + pub fn id(self) -> hir::HirId { self.handle( |i: ItemFnParts<'_>| i.id, - |id, _, _: &'a ast::FnSig<'a>, _, _, _, _| id, + |id, _, _: &'a hir::FnSig<'a>, _, _, _, _| id, |c: ClosureParts<'_>| c.id, ) } - pub fn constness(self) -> ast::Constness { - self.kind().header().map_or(ast::Constness::NotConst, |header| header.constness) + pub fn constness(self) -> hir::Constness { + self.kind().header().map_or(hir::Constness::NotConst, |header| header.constness) } - pub fn asyncness(self) -> ast::IsAsync { - self.kind().header().map_or(ast::IsAsync::NotAsync, |header| header.asyncness) + pub fn asyncness(self) -> hir::IsAsync { + self.kind().header().map_or(hir::IsAsync::NotAsync, |header| header.asyncness) } - pub fn unsafety(self) -> ast::Unsafety { - self.kind().header().map_or(ast::Unsafety::Normal, |header| header.unsafety) + pub fn unsafety(self) -> hir::Unsafety { + self.kind().header().map_or(hir::Unsafety::Normal, |header| header.unsafety) } pub fn kind(self) -> FnKind<'a> { @@ -203,7 +203,7 @@ impl<'a> FnLikeNode<'a> { FnKind::ItemFn(p.ident, p.generics, p.header, p.vis, p.attrs) }; let closure = |c: ClosureParts<'a>| FnKind::Closure(c.attrs); - let method = |_, ident: Ident, sig: &'a ast::FnSig<'a>, vis, _, _, attrs| { + let method = |_, ident: Ident, sig: &'a hir::FnSig<'a>, vis, _, _, attrs| { FnKind::Method(ident, sig, vis, attrs) }; self.handle(item, method, closure) @@ -213,19 +213,19 @@ impl<'a> FnLikeNode<'a> { where I: FnOnce(ItemFnParts<'a>) -> A, M: FnOnce( - ast::HirId, + hir::HirId, Ident, - &'a ast::FnSig<'a>, - Option<&'a ast::Visibility<'a>>, - ast::BodyId, + &'a hir::FnSig<'a>, + Option<&'a hir::Visibility<'a>>, + hir::BodyId, Span, &'a [Attribute], ) -> A, C: FnOnce(ClosureParts<'a>) -> A, { match self.node { - map::Node::Item(i) => match i.kind { - ast::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts { + Node::Item(i) => match i.kind { + hir::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts { id: i.hir_id, ident: i.ident, decl: &sig.decl, @@ -238,20 +238,20 @@ impl<'a> FnLikeNode<'a> { }), _ => bug!("item FnLikeNode that is not fn-like"), }, - map::Node::TraitItem(ti) => match ti.kind { - ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => { + Node::TraitItem(ti) => match ti.kind { + hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs) } _ => bug!("trait method FnLikeNode that is not fn-like"), }, - map::Node::ImplItem(ii) => match ii.kind { - ast::ImplItemKind::Method(ref sig, body) => { + Node::ImplItem(ii) => match ii.kind { + hir::ImplItemKind::Method(ref sig, body) => { method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs) } _ => bug!("impl method FnLikeNode that is not fn-like"), }, - map::Node::Expr(e) => match e.kind { - ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) => { + Node::Expr(e) => match e.kind { + hir::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) => { closure(ClosureParts::new(&decl, block, e.hir_id, e.span, &e.attrs)) } _ => bug!("expr FnLikeNode that is not fn-like"), From adaa521feb09dbb40e5e2143bc3ce62112c8ce04 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 14:19:35 +0100 Subject: [PATCH 02/11] collector: extract upstream_crates --- src/librustc/hir/map/collector.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 6879e8fd76348..a7d5cb6cbe3c6 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::{CrateNum, DefIndex, LOCAL_CRATE}; use rustc_index::vec::IndexVec; use rustc_session::{CrateDisambiguator, Session}; use rustc_span::source_map::SourceMap; -use rustc_span::Span; +use rustc_span::{Span, Symbol}; use std::iter::repeat; use syntax::ast::NodeId; @@ -98,6 +98,21 @@ where (sig, full) } +fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(Symbol, Fingerprint, Svh)> { + let mut upstream_crates: Vec<_> = cstore + .crates_untracked() + .iter() + .map(|&cnum| { + let name = cstore.crate_name_untracked(cnum); + let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint(); + let hash = cstore.crate_hash_untracked(cnum); + (name, disambiguator, hash) + }) + .collect(); + upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis)); + upstream_crates +} + impl<'a, 'hir> NodeCollector<'a, 'hir> { pub(super) fn root( sess: &'a Session, @@ -190,18 +205,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { }, ); - let mut upstream_crates: Vec<_> = cstore - .crates_untracked() - .iter() - .map(|&cnum| { - let name = cstore.crate_name_untracked(cnum); - let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint(); - let hash = cstore.crate_hash_untracked(cnum); - (name, disambiguator, hash) - }) - .collect(); - - upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis)); + let upstream_crates = upstream_crates(cstore); // We hash the final, remapped names of all local source files so we // don't have to include the path prefix remapping commandline args. From 3eb83f2bccff55e62a5bdb98009b6d79436683f2 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 14:22:44 +0100 Subject: [PATCH 03/11] collector: use impl Trait --- src/librustc/hir/map/collector.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index a7d5cb6cbe3c6..edb2e69b79cae 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -49,15 +49,12 @@ pub(super) struct NodeCollector<'a, 'hir> { hir_body_nodes: Vec<(DefPathHash, Fingerprint)>, } -fn input_dep_node_and_hash( +fn input_dep_node_and_hash( dep_graph: &DepGraph, hcx: &mut StableHashingContext<'_>, dep_node: DepNode, - input: I, -) -> (DepNodeIndex, Fingerprint) -where - I: for<'a> HashStable>, -{ + input: impl for<'a> HashStable>, +) -> (DepNodeIndex, Fingerprint) { let dep_node_index = dep_graph.input_task(dep_node, &mut *hcx, &input).1; let hash = if dep_graph.is_fully_enabled() { @@ -71,16 +68,13 @@ where (dep_node_index, hash) } -fn alloc_hir_dep_nodes( +fn alloc_hir_dep_nodes( dep_graph: &DepGraph, hcx: &mut StableHashingContext<'_>, def_path_hash: DefPathHash, - item_like: I, + item_like: impl for<'a> HashStable>, hir_body_nodes: &mut Vec<(DefPathHash, Fingerprint)>, -) -> (DepNodeIndex, DepNodeIndex) -where - I: for<'a> HashStable>, -{ +) -> (DepNodeIndex, DepNodeIndex) { let sig = dep_graph .input_task( def_path_hash.to_dep_node(DepKind::Hir), From 41453d2f744e6ae6bf95867e29387f098c988265 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 14:38:27 +0100 Subject: [PATCH 04/11] collector: clarify dependencies --- src/librustc/hir/map/collector.rs | 20 +++++++++++--------- src/librustc/hir/map/definitions.rs | 5 +++-- src/librustc/hir/map/mod.rs | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index edb2e69b79cae..7dca5451a3013 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -1,22 +1,24 @@ -use super::*; -use crate::dep_graph::{DepGraph, DepKind, DepNodeIndex}; -use crate::hir::intravisit::{NestedVisitorMap, Visitor}; -use crate::hir::map::HirEntryMap; -use crate::ich::Fingerprint; +use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex}; +use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use crate::hir::map::definitions::{self, DefPathHash}; +use crate::hir::map::{Entry, HirEntryMap}; +use crate::ich::StableHashingContext; use crate::middle::cstore::CrateStore; +use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::svh::Svh; use rustc_hir as hir; +use rustc_hir::def_id::CRATE_DEF_INDEX; use rustc_hir::def_id::{CrateNum, DefIndex, LOCAL_CRATE}; +use rustc_hir::*; use rustc_index::vec::IndexVec; use rustc_session::{CrateDisambiguator, Session}; use rustc_span::source_map::SourceMap; -use rustc_span::{Span, Symbol}; -use std::iter::repeat; +use rustc_span::{Span, Symbol, DUMMY_SP}; use syntax::ast::NodeId; -use crate::ich::StableHashingContext; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use std::iter::repeat; /// A visitor that walks over the HIR and collects `Node`s into a HIR map. pub(super) struct NodeCollector<'a, 'hir> { diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 67d29b38db2a5..ac2d7a9a8dc2a 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -4,7 +4,7 @@ //! There are also some rather random cases (like const initializer //! expressions) that are mostly just leftovers. -use crate::ich::Fingerprint; +use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; use rustc_hir as hir; @@ -15,10 +15,11 @@ use rustc_session::CrateDisambiguator; use rustc_span::hygiene::ExpnId; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; +use syntax::ast; + use std::borrow::Borrow; use std::fmt::Write; use std::hash::Hash; -use syntax::ast; /// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa. /// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey` diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 0a165accb7d52..8fedcac9e23a4 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -18,7 +18,7 @@ use rustc_index::vec::IndexVec; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::Spanned; use rustc_span::symbol::kw; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::Span; use rustc_target::spec::abi::Abi; use syntax::ast::{self, Name, NodeId}; From 3f13ba8523e8aefa670c061b0d0d5e551b47fb45 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 15:06:39 +0100 Subject: [PATCH 05/11] hir::map: elide & simplify --- src/librustc/hir/map/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 8fedcac9e23a4..05b0c8e36fdf6 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -186,12 +186,12 @@ struct ParentHirIterator<'map, 'hir> { } impl<'map, 'hir> ParentHirIterator<'map, 'hir> { - fn new(current_id: HirId, map: &'map Map<'hir>) -> ParentHirIterator<'map, 'hir> { - ParentHirIterator { current_id, map } + fn new(current_id: HirId, map: &'map Map<'hir>) -> Self { + Self { current_id, map } } } -impl<'map, 'hir> Iterator for ParentHirIterator<'map, 'hir> { +impl<'hir> Iterator for ParentHirIterator<'_, 'hir> { type Item = (HirId, Node<'hir>); fn next(&mut self) -> Option { From 4b08c7e9748dafa9c38f090ca046a2f372739792 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 15:13:47 +0100 Subject: [PATCH 06/11] NestedVisitorMap: reduce visibilities --- src/librustc/hir/intravisit.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index edecfd335fbb7..e1245dbb66580 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -159,7 +159,7 @@ pub enum NestedVisitorMap<'this, 'tcx> { impl<'this, 'tcx> NestedVisitorMap<'this, 'tcx> { /// Returns the map to use for an "intra item-like" thing (if any). /// E.g., function body. - pub fn intra(self) -> Option<&'this Map<'tcx>> { + fn intra(self) -> Option<&'this Map<'tcx>> { match self { NestedVisitorMap::None => None, NestedVisitorMap::OnlyBodies(map) => Some(map), @@ -169,7 +169,7 @@ impl<'this, 'tcx> NestedVisitorMap<'this, 'tcx> { /// Returns the map to use for an "item-like" thing (if any). /// E.g., item, impl-item. - pub fn inter(self) -> Option<&'this Map<'tcx>> { + fn inter(self) -> Option<&'this Map<'tcx>> { match self { NestedVisitorMap::None => None, NestedVisitorMap::OnlyBodies(_) => None, @@ -214,7 +214,7 @@ pub trait Visitor<'v>: Sized { /// `panic!()`. This way, if a new `visit_nested_XXX` variant is /// added in the future, we will see the panic in your code and /// fix it appropriately. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v>; + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, 'v>; /// Invoked when a nested item is encountered. By default does /// nothing unless you override `nested_visit_map` to return other than From 62e9ccbe28f0d10d838de5b302a8afa06d571a2e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 15:51:38 +0100 Subject: [PATCH 07/11] intravisit: .expect_item -> .item --- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/map/mod.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index e1245dbb66580..9d6acbda62e42 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -226,7 +226,7 @@ pub trait Visitor<'v>: Sized { /// but cannot supply a `Map`; see `nested_visit_map` for advice. #[allow(unused_variables)] fn visit_nested_item(&mut self, id: ItemId) { - let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item(id.id)); + let opt_item = self.nested_visit_map().inter().map(|map| map.item(id.id)); if let Some(item) = opt_item { self.visit_item(item); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 05b0c8e36fdf6..69978efd81d3d 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -405,6 +405,14 @@ impl<'hir> Map<'hir> { self.forest.krate() } + pub fn item(&self, id: HirId) -> &'hir Item<'hir> { + self.read(id); + + // N.B., intentionally bypass `self.forest.krate()` so that we + // do not trigger a read of the whole krate here + self.forest.krate.item(id) + } + pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { self.read(id.hir_id); From 8351667091af662fe5cb22341e6c631a136a000b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 17:25:33 +0100 Subject: [PATCH 08/11] intravisit: abstract over HIR Map --- src/librustc/hir/check_attr.rs | 5 ++- src/librustc/hir/intravisit.rs | 42 +++++++++---------- src/librustc/hir/map/collector.rs | 6 ++- src/librustc/hir/map/hir_id_validator.rs | 4 +- src/librustc/hir/map/mod.rs | 18 ++++++++ src/librustc/hir/upvars.rs | 9 +++- .../infer/error_reporting/need_type_info.rs | 4 +- .../nice_region_error/find_anon_type.rs | 9 +++- src/librustc/middle/weak_lang_items.rs | 5 ++- src/librustc_ast_lowering/lib.rs | 7 +++- src/librustc_incremental/assert_dep_graph.rs | 5 ++- .../persist/dirty_clean.rs | 5 ++- src/librustc_lint/builtin.rs | 5 ++- src/librustc_lint/late.rs | 5 ++- src/librustc_lint/levels.rs | 5 ++- src/librustc_metadata/rmeta/encoder.rs | 5 ++- src/librustc_mir/hair/pattern/check_match.rs | 9 +++- src/librustc_mir/transform/check_unsafety.rs | 5 ++- src/librustc_mir/transform/mod.rs | 4 +- src/librustc_passes/check_const.rs | 4 +- src/librustc_passes/dead.rs | 9 +++- src/librustc_passes/hir_stats.rs | 5 ++- src/librustc_passes/intrinsicck.rs | 14 ++++--- src/librustc_passes/lib_features.rs | 5 ++- src/librustc_passes/liveness.rs | 9 +++- src/librustc_passes/loops.rs | 4 +- src/librustc_passes/reachable.rs | 5 ++- src/librustc_passes/region.rs | 5 ++- src/librustc_passes/stability.rs | 13 ++++-- src/librustc_privacy/lib.rs | 29 +++++++++---- src/librustc_resolve/lifetimes.rs | 24 ++++++++--- src/librustc_traits/lowering/mod.rs | 5 ++- src/librustc_typeck/check/compare_method.rs | 8 ++-- .../check/generator_interior.rs | 5 ++- src/librustc_typeck/check/method/suggest.rs | 5 ++- src/librustc_typeck/check/mod.rs | 5 ++- src/librustc_typeck/check/regionck.rs | 5 ++- src/librustc_typeck/check/upvar.rs | 5 ++- src/librustc_typeck/check/writeback.rs | 5 ++- src/librustc_typeck/collect.rs | 17 ++++++-- src/librustdoc/test.rs | 4 +- 41 files changed, 258 insertions(+), 89 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index d525f36459336..75f78104b488e 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -5,6 +5,7 @@ //! item. use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use crate::hir::map::Map; use crate::lint::builtin::UNUSED_ATTRIBUTES; use crate::ty::query::Providers; use crate::ty::TyCtxt; @@ -519,7 +520,9 @@ impl CheckAttrVisitor<'tcx> { } impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 9d6acbda62e42..13b5be08d8a55 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -31,8 +31,6 @@ //! This order consistency is required in a few places in rustc, for //! example generator inference, and possibly also HIR borrowck. -use crate::hir::map::Map; - use rustc_hir::itemlikevisit::{ItemLikeVisitor, ParItemLikeVisitor}; use rustc_hir::*; use rustc_span::Span; @@ -42,10 +40,7 @@ pub struct DeepVisitor<'v, V> { visitor: &'v mut V, } -impl<'v, 'hir, V> DeepVisitor<'v, V> -where - V: Visitor<'hir> + 'v, -{ +impl<'v, V> DeepVisitor<'v, V> { pub fn new(base: &'v mut V) -> Self { DeepVisitor { visitor: base } } @@ -122,6 +117,14 @@ impl<'a> FnKind<'a> { } } +/// An abstract representation of the HIR `rustc::hir::map::Map`. +pub trait Map<'hir> { + fn body(&self, id: BodyId) -> &'hir Body<'hir>; + fn item(&self, id: HirId) -> &'hir Item<'hir>; + fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>; + fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>; +} + /// Specifies what nested things a visitor wants to visit. The most /// common choice is `OnlyBodies`, which will cause the visitor to /// visit fn bodies for fns that it encounters, but skip over nested @@ -129,7 +132,7 @@ impl<'a> FnKind<'a> { /// /// See the comments on `ItemLikeVisitor` for more details on the overall /// visit strategy. -pub enum NestedVisitorMap<'this, 'tcx> { +pub enum NestedVisitorMap<'this, M> { /// Do not visit any nested things. When you add a new /// "non-nested" thing, you will want to audit such uses to see if /// they remain valid. @@ -146,20 +149,20 @@ pub enum NestedVisitorMap<'this, 'tcx> { /// to use `visit_all_item_likes()` as an outer loop, /// and to have the visitor that visits the contents of each item /// using this setting. - OnlyBodies(&'this Map<'tcx>), + OnlyBodies(&'this M), /// Visits all nested things, including item-likes. /// /// **This is an unusual choice.** It is used when you want to /// process everything within their lexical context. Typically you /// kick off the visit by doing `walk_krate()`. - All(&'this Map<'tcx>), + All(&'this M), } -impl<'this, 'tcx> NestedVisitorMap<'this, 'tcx> { +impl<'this, M> NestedVisitorMap<'this, M> { /// Returns the map to use for an "intra item-like" thing (if any). /// E.g., function body. - fn intra(self) -> Option<&'this Map<'tcx>> { + fn intra(self) -> Option<&'this M> { match self { NestedVisitorMap::None => None, NestedVisitorMap::OnlyBodies(map) => Some(map), @@ -169,7 +172,7 @@ impl<'this, 'tcx> NestedVisitorMap<'this, 'tcx> { /// Returns the map to use for an "item-like" thing (if any). /// E.g., item, impl-item. - fn inter(self) -> Option<&'this Map<'tcx>> { + fn inter(self) -> Option<&'this M> { match self { NestedVisitorMap::None => None, NestedVisitorMap::OnlyBodies(_) => None, @@ -195,6 +198,8 @@ impl<'this, 'tcx> NestedVisitorMap<'this, 'tcx> { /// to monitor future changes to `Visitor` in case a new method with a /// new default implementation gets introduced.) pub trait Visitor<'v>: Sized { + type Map: Map<'v>; + /////////////////////////////////////////////////////////////////////////// // Nested items. @@ -214,7 +219,7 @@ pub trait Visitor<'v>: Sized { /// `panic!()`. This way, if a new `visit_nested_XXX` variant is /// added in the future, we will see the panic in your code and /// fix it appropriately. - fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, 'v>; + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map>; /// Invoked when a nested item is encountered. By default does /// nothing unless you override `nested_visit_map` to return other than @@ -496,21 +501,16 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime } } -pub fn walk_poly_trait_ref<'v, V>( +pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>( visitor: &mut V, trait_ref: &'v PolyTraitRef<'v>, _modifier: TraitBoundModifier, -) where - V: Visitor<'v>, -{ +) { walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params); visitor.visit_trait_ref(&trait_ref.trait_ref); } -pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) -where - V: Visitor<'v>, -{ +pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) { visitor.visit_id(trait_ref.hir_ref_id); visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id) } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 7dca5451a3013..6aa1b6da36830 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -1,7 +1,7 @@ use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex}; use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::map::definitions::{self, DefPathHash}; -use crate::hir::map::{Entry, HirEntryMap}; +use crate::hir::map::{Entry, HirEntryMap, Map}; use crate::ich::StableHashingContext; use crate::middle::cstore::CrateStore; use rustc_data_structures::fingerprint::Fingerprint; @@ -336,11 +336,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { } impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { + type Map = Map<'hir>; + /// Because we want to track parent items and so forth, enable /// deep walking so that we walk nested items in the context of /// their outer items. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { panic!("`visit_nested_xxx` must be manually implemented in this visitor"); } diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 6329970759203..2499acae5e656 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -133,7 +133,9 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> { } impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'hir> { + type Map = Map<'hir>; + + fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, Self::Map> { intravisit::NestedVisitorMap::OnlyBodies(self.hir_map) } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 69978efd81d3d..f7b654eae1ead 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -1093,6 +1093,24 @@ impl<'hir> Map<'hir> { } } +impl<'hir> intravisit::Map<'hir> for Map<'hir> { + fn body(&self, id: BodyId) -> &'hir Body<'hir> { + self.body(id) + } + + fn item(&self, id: HirId) -> &'hir Item<'hir> { + self.item(id) + } + + fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { + self.trait_item(id) + } + + fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { + self.impl_item(id) + } +} + pub struct NodesMatchingSuffix<'a> { map: &'a Map<'a>, item_name: &'a String, diff --git a/src/librustc/hir/upvars.rs b/src/librustc/hir/upvars.rs index df02a79ef4cc2..b61a54a643f70 100644 --- a/src/librustc/hir/upvars.rs +++ b/src/librustc/hir/upvars.rs @@ -1,6 +1,7 @@ //! Upvar (closure capture) collection from cross-body HIR uses of `Res::Local`s. use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use crate::hir::map::Map; use crate::ty::query::Providers; use crate::ty::TyCtxt; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; @@ -43,7 +44,9 @@ struct LocalCollector { } impl Visitor<'tcx> for LocalCollector { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { NestedVisitorMap::None } @@ -70,7 +73,9 @@ impl CaptureCollector<'_, '_> { } impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 4dedf0a23e827..9c7bf261d9bd4 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -66,7 +66,9 @@ impl<'a, 'tcx> FindLocalByTypeVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { NestedVisitorMap::OnlyBodies(&self.hir_map) } diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index 6edf8f1e78755..6ec956f15dd34 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -1,4 +1,5 @@ use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use crate::hir::map::Map; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::middle::resolve_lifetime as rl; use crate::ty::{self, Region, TyCtxt}; @@ -90,7 +91,9 @@ struct FindNestedTypeVisitor<'tcx> { } impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } @@ -207,7 +210,9 @@ struct TyPathVisitor<'tcx> { } impl Visitor<'tcx> for TyPathVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Map<'tcx>> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index e9e35b7617c89..71abbd8bcb131 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -5,6 +5,7 @@ use crate::session::config; use crate::hir::intravisit; use crate::hir::intravisit::{NestedVisitorMap, Visitor}; +use crate::hir::map::Map; use crate::ty::TyCtxt; use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; @@ -136,7 +137,9 @@ impl<'a, 'tcx> Context<'a, 'tcx> { } impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Map<'v>> { NestedVisitorMap::None } diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 8b79d9b4f478e..6c4d7ec3a8a9f 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -37,7 +37,8 @@ use rustc::arena::Arena; use rustc::dep_graph::DepGraph; use rustc::hir::intravisit; -use rustc::hir::map::{DefKey, DefPathData, Definitions}; +use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions}; +use rustc::hir::map::Map; use rustc::lint; use rustc::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS}; use rustc::middle::cstore::CrateStore; @@ -1484,7 +1485,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } impl<'r, 'a, 'v, 'hir> intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a, 'hir> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index 64547845e74f1..e59a52923d9fb 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -37,6 +37,7 @@ use graphviz as dot; use rustc::dep_graph::debug::{DepNodeFilter, EdgeFilter}; use rustc::dep_graph::{DepGraphQuery, DepKind, DepNode}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::ty::TyCtxt; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING}; @@ -159,7 +160,9 @@ impl IfThisChanged<'tcx> { } impl Visitor<'tcx> for IfThisChanged<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index 40dd4c88a02b2..a7f915b833d92 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -15,6 +15,7 @@ use rustc::dep_graph::{label_strs, DepNode}; use rustc::hir::intravisit; +use rustc::hir::map::Map; use rustc::ty::TyCtxt; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashSet; @@ -547,7 +548,9 @@ impl FindAllAttrs<'tcx> { } impl intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, Self::Map> { intravisit::NestedVisitorMap::All(&self.tcx.hir()) } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c2e20d5cf758e..213ca308d5636 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -25,6 +25,7 @@ use std::fmt::Write; use lint::{EarlyContext, EarlyLintPass, LateLintPass, LintPass}; use lint::{LateContext, LintArray, LintContext}; +use rustc::hir::map::Map; use rustc::lint; use rustc::lint::FutureIncompatibleInfo; use rustc::traits::misc::can_type_implement_copy; @@ -1093,7 +1094,9 @@ impl TypeAliasBounds { err: &'a mut DiagnosticBuilder<'db>, } impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } diff --git a/src/librustc_lint/late.rs b/src/librustc_lint/late.rs index 2e0a201fa98e9..da27e9225d787 100644 --- a/src/librustc_lint/late.rs +++ b/src/librustc_lint/late.rs @@ -16,6 +16,7 @@ use rustc::hir::intravisit as hir_visit; use rustc::hir::intravisit::Visitor; +use rustc::hir::map::Map; use rustc::lint::LateContext; use rustc::lint::LintPass; use rustc::lint::{LateLintPass, LateLintPassObject}; @@ -86,10 +87,12 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> { impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPass<'a, 'tcx, T> { + type Map = Map<'tcx>; + /// Because lints are scoped lexically, we want to walk nested /// items in the context of the outer item, so enable /// deep-walking. - fn nested_visit_map<'this>(&'this mut self) -> hir_visit::NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map<'this>(&'this mut self) -> hir_visit::NestedVisitorMap<'this, Self::Map> { hir_visit::NestedVisitorMap::All(&self.context.tcx.hir()) } diff --git a/src/librustc_lint/levels.rs b/src/librustc_lint/levels.rs index e060d6b551ca7..f6f1ae2a08a6f 100644 --- a/src/librustc_lint/levels.rs +++ b/src/librustc_lint/levels.rs @@ -1,4 +1,5 @@ use rustc::hir::intravisit; +use rustc::hir::map::Map; use rustc::lint::{LintLevelMap, LintLevelSets, LintLevelsBuilder, LintStore}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; @@ -50,7 +51,9 @@ impl LintLevelMapBuilder<'_, '_> { } impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, Self::Map> { intravisit::NestedVisitorMap::All(&self.tcx.hir()) } diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 92bfc51d9d5f0..390472940c764 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -2,6 +2,7 @@ use crate::rmeta::table::FixedSizeEncoding; use crate::rmeta::*; use rustc::hir::map::definitions::DefPathTable; +use rustc::hir::map::Map; use rustc::middle::cstore::{EncodedMetadata, ForeignModule, LinkagePreference, NativeLibrary}; use rustc::middle::dependency_format::Linkage; use rustc::middle::exported_symbols::{metadata_symbol_name, ExportedSymbol, SymbolExportLevel}; @@ -1520,7 +1521,9 @@ impl EncodeContext<'tcx> { // FIXME(eddyb) make metadata encoding walk over all definitions, instead of HIR. impl Visitor<'tcx> for EncodeContext<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) { diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 07bb87f7b543f..ab76f010a0f0a 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -5,6 +5,7 @@ use super::_match::{expand_pattern, is_useful, MatchCheckCtxt, Matrix, PatStack} use super::{PatCtxt, PatKind, PatternError}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint; use rustc::session::Session; use rustc::ty::subst::{InternalSubsts, SubstsRef}; @@ -49,7 +50,9 @@ struct MatchVisitor<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -730,7 +733,9 @@ fn check_legality_of_bindings_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pa } impl<'v> Visitor<'v> for AtBindingPatternVisitor<'_, '_, '_> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 5cf5c54dd4878..830609f7911ac 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -1,4 +1,5 @@ use rustc::hir::intravisit; +use rustc::hir::map::Map; use rustc::lint::builtin::{SAFE_PACKED_BORROWS, UNUSED_UNSAFE}; use rustc::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc::mir::*; @@ -475,7 +476,9 @@ struct UnusedUnsafeVisitor<'a> { } impl<'a, 'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, Self::Map> { intravisit::NestedVisitorMap::None } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 82c31a09ce377..50abf919f9daa 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -1,5 +1,6 @@ use crate::{build, shim}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::mir::{BodyAndCache, ConstQualifs, MirPhase, Promoted}; use rustc::ty::query::Providers; use rustc::ty::steal::Steal; @@ -85,7 +86,8 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet { } intravisit::walk_struct_def(self, v) } - fn nested_visit_map<'b>(&'b mut self) -> NestedVisitorMap<'b, 'tcx> { + type Map = Map<'tcx>; + fn nested_visit_map<'b>(&'b mut self) -> NestedVisitorMap<'b, Self::Map> { NestedVisitorMap::None } } diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index f6a9d1cace15f..072a51391c877 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -200,7 +200,9 @@ impl<'tcx> CheckConstVisitor<'tcx> { } impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index 0c435a1666363..5441a8bf717a0 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -3,6 +3,7 @@ // from live codes are live, and everything else is dead. use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint; use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc::middle::privacy; @@ -210,7 +211,9 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -563,11 +566,13 @@ impl DeadVisitor<'tcx> { } impl Visitor<'tcx> for DeadVisitor<'tcx> { + type Map = Map<'tcx>; + /// Walk nested items in place so that we don't report dead-code /// on inner functions when the outer function is already getting /// an error. We could do this also by checking the parents, but /// this is how the code is setup and it seems harmless enough. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 3eca602cf8603..2c36181ce4b40 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -3,6 +3,7 @@ // completely accurate (some things might be counted twice, others missed). use rustc::hir::intravisit as hir_visit; +use rustc::hir::map::Map; use rustc::util::common::to_readable_str; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; @@ -92,7 +93,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_param(self, param) } - fn nested_visit_map<'this>(&'this mut self) -> hir_visit::NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> hir_visit::NestedVisitorMap<'_, Self::Map> { panic!("visit_nested_xxx must be manually implemented in this visitor") } diff --git a/src/librustc_passes/intrinsicck.rs b/src/librustc_passes/intrinsicck.rs index 2b9a692117cc7..68d9ba7f90e9a 100644 --- a/src/librustc_passes/intrinsicck.rs +++ b/src/librustc_passes/intrinsicck.rs @@ -1,12 +1,12 @@ use errors::struct_span_err; +use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx}; use rustc::ty::query::Providers; use rustc::ty::{self, Ty, TyCtxt}; +use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; - -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; -use rustc_hir as hir; use rustc_index::vec::Idx; use rustc_span::{sym, Span}; use rustc_target::spec::abi::Abi::RustIntrinsic; @@ -124,7 +124,9 @@ impl ExprVisitor<'tcx> { } impl Visitor<'tcx> for ItemVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -139,7 +141,9 @@ impl Visitor<'tcx> for ItemVisitor<'tcx> { } impl Visitor<'tcx> for ExprVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs index df56bcff81f6f..9d5e8080055a8 100644 --- a/src/librustc_passes/lib_features.rs +++ b/src/librustc_passes/lib_features.rs @@ -6,6 +6,7 @@ use errors::struct_span_err; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::middle::lib_features::LibFeatures; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; @@ -113,7 +114,9 @@ impl LibFeatureCollector<'tcx> { } impl Visitor<'tcx> for LibFeatureCollector<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 3ae5e4f72b744..4b5b2148cd984 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -98,6 +98,7 @@ use self::VarKind::*; use errors::Applicability; use rustc::hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; @@ -153,7 +154,9 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String { } impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } @@ -1348,7 +1351,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // Checking for error conditions impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 262f2382da3a4..54ea73f1d3d21 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -44,7 +44,9 @@ pub(crate) fn provide(providers: &mut Providers<'_>) { } impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> { + type Map = Map<'hir>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.hir_map) } diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index 9b529401049b0..016cab9d11446 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -7,6 +7,7 @@ use rustc::hir::intravisit; use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::middle::privacy; use rustc::session::config; @@ -82,7 +83,9 @@ struct ReachableContext<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index 75c74c4f923c2..a8a56ee7f0938 100644 --- a/src/librustc_passes/region.rs +++ b/src/librustc_passes/region.rs @@ -7,6 +7,7 @@ //! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/borrowck.html use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::middle::region::*; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; @@ -695,7 +696,9 @@ impl<'tcx> RegionResolutionVisitor<'tcx> { } impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 33c985bd66b18..7891fab0aa6c6 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -3,6 +3,7 @@ use errors::struct_span_err; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint; use rustc::middle::privacy::AccessLevels; use rustc::middle::stability::{DeprecationEntry, Index}; @@ -204,7 +205,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { /// Because stability levels are scoped lexically, we want to walk /// nested items in the context of the outer item, so enable /// deep-walking. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } @@ -293,7 +296,9 @@ impl<'a, 'tcx> MissingStabilityAnnotations<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } @@ -429,10 +434,12 @@ struct Checker<'tcx> { } impl Visitor<'tcx> for Checker<'tcx> { + type Map = Map<'tcx>; + /// Because stability levels are scoped lexically, we want to walk /// nested items in the context of the outer item, so enable /// deep-walking. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 17e56129247f3..3d0d4070a251a 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -5,6 +5,7 @@ use rustc::bug; use rustc::hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::lint; use rustc::middle::privacy::{AccessLevel, AccessLevels}; use rustc::ty::fold::TypeVisitor; @@ -372,7 +373,9 @@ struct PubRestrictedVisitor<'tcx> { } impl Visitor<'tcx> for PubRestrictedVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } fn visit_vis(&mut self, vis: &'tcx hir::Visibility<'tcx>) { @@ -670,9 +673,11 @@ impl EmbargoVisitor<'tcx> { } impl Visitor<'tcx> for EmbargoVisitor<'tcx> { + type Map = Map<'tcx>; + /// We want to visit items in the context of their containing /// module and so forth, so supply a crate for doing a deep walk. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } @@ -1039,9 +1044,11 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + /// We want to visit items in the context of their containing /// module and so forth, so supply a crate for doing a deep walk. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } @@ -1179,9 +1186,11 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + /// We want to visit items in the context of their containing /// module and so forth, so supply a crate for doing a deep walk. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } @@ -1437,7 +1446,9 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } impl<'a, 'b, 'tcx, 'v> Visitor<'v> for ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -1463,9 +1474,11 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for ObsoleteCheckTypeForPrivatenessVisitor<'a } impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + /// We want to visit items in the context of their containing /// module and so forth, so supply a crate for doing a deep walk. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } @@ -1906,7 +1919,9 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index 15858f7d8abc8..215ab0fde026e 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -361,7 +361,9 @@ fn sub_items_have_self_param(node: &hir::ItemKind<'_>) -> bool { } impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::All(&self.tcx.hir()) } @@ -1086,7 +1088,9 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) { gather.visit_body(body); impl<'v, 'a, 'tcx> Visitor<'v> for GatherLabels<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -2129,7 +2133,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } impl<'a> Visitor<'a> for SelfVisitor<'a> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'a> { + type Map = Map<'a>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -2217,7 +2223,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } impl<'v, 'a> Visitor<'v> for GatherLifetimes<'a> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -2802,7 +2810,9 @@ fn insert_late_bound_lifetimes( } impl<'v> Visitor<'v> for ConstrainedCollector { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -2843,7 +2853,9 @@ fn insert_late_bound_lifetimes( } impl<'v> Visitor<'v> for AllCollector { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index 47009ac41232f..647d32d45f6be 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -2,6 +2,7 @@ mod environment; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::definitions::DefPathData; +use rustc::hir::map::Map; use rustc::traits::{ Clause, Clauses, DomainGoal, FromEnv, GoalKind, PolyDomainGoal, ProgramClause, ProgramClauseCategory, WellFormed, WhereClause, @@ -600,7 +601,9 @@ impl ClauseDumper<'tcx> { } impl Visitor<'tcx> for ClauseDumper<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index e1f2950469b86..031f6e15d0dc9 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -1,5 +1,6 @@ use errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; use rustc::hir::intravisit; +use rustc::hir::map::Map; use rustc::infer::{self, InferOk}; use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal}; use rustc::ty::error::{ExpectedFound, TypeError}; @@ -890,9 +891,10 @@ fn compare_synthetic_generics<'tcx>( } } } - fn nested_visit_map<'this>( - &'this mut self, - ) -> intravisit::NestedVisitorMap<'this, 'v> + type Map = Map<'v>; + fn nested_visit_map( + &mut self, + ) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index f004d04fdfeba..5936fe9b2a486 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -5,6 +5,7 @@ use super::FnCtxt; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::middle::region::{self, YieldData}; use rustc::ty::{self, Ty}; use rustc_data_structures::fx::FxHashMap; @@ -193,7 +194,9 @@ pub fn resolve_interior<'a, 'tcx>( // librustc/middle/region.rs since `expr_count` is compared against the results // there. impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 8bf9f488e5977..35e5588273b26 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -7,6 +7,7 @@ use crate::namespace::Namespace; use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::intravisit; use rustc::hir::map as hir_map; +use rustc::hir::map::Map; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::traits::Obligation; use rustc::ty::print::with_crate_prefix; @@ -1124,7 +1125,9 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> { } } - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::None } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e6fbae09ba1a0..a977ecd8dafca 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -92,6 +92,7 @@ use crate::middle::lang_items; use crate::namespace::Namespace; use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc::infer::opaque_types::OpaqueTypeDecl; @@ -1170,7 +1171,9 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 3b2f3d17e8da6..b4fed3fe4e245 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -77,6 +77,7 @@ use crate::check::FnCtxt; use crate::mem_categorization as mc; use crate::middle::region; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{self, RegionObligation, SuppressRegionErrors}; use rustc::ty::adjustment; @@ -414,7 +415,9 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> { // hierarchy, and in particular the relationships between free // regions, until regionck, as described in #3238. - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index be912b6bcafc0..8c107db21502b 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -36,6 +36,7 @@ use crate::expr_use_visitor as euv; use crate::mem_categorization as mc; use crate::mem_categorization::PlaceBase; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::infer::UpvarRegion; use rustc::ty::{self, Ty, TyCtxt, UpvarSubsts}; use rustc_data_structures::fx::FxIndexMap; @@ -59,7 +60,9 @@ struct InferBorrowKindVisitor<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for InferBorrowKindVisitor<'a, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index ad9a2f2e2b45e..f03bc21aef79d 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -5,6 +5,7 @@ use crate::check::FnCtxt; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc::infer::InferCtxt; use rustc::ty::adjustment::{Adjust, Adjustment, PointerCast}; @@ -242,7 +243,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // traffic in node-ids or update tables in the type context etc. impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 35c380612d2fb..50cd059fe8ddb 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -22,6 +22,7 @@ use crate::middle::resolve_lifetime as rl; use crate::middle::weak_lang_items; use errors::{struct_span_err, Applicability, StashKey}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::hir::map::Map; use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::mir::mono::Linkage; use rustc::traits; @@ -104,7 +105,9 @@ pub struct ItemCtxt<'tcx> { crate struct PlaceholderHirTyCollector(crate Vec); impl<'v> Visitor<'v> for PlaceholderHirTyCollector { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> { + type Map = Map<'v>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } fn visit_ty(&mut self, t: &'v hir::Ty<'v>) { @@ -185,7 +188,9 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir } impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::OnlyBodies(&self.tcx.hir()) } @@ -885,7 +890,9 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option for LateBoundRegionsDetector<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { NestedVisitorMap::None } @@ -1715,7 +1722,9 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } impl<'tcx> intravisit::Visitor<'tcx> for ConstraintLocator<'tcx> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> { + type Map = Map<'tcx>; + + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::All(&self.tcx.hir()) } fn visit_item(&mut self, it: &'tcx Item<'tcx>) { diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index d94e940a7f72c..cbef4f8ae692a 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -899,7 +899,9 @@ impl<'a, 'hir> HirCollector<'a, 'hir> { } impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> { - fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'hir> { + type Map = Map<'hir>; + + fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> { intravisit::NestedVisitorMap::All(&self.map) } From 37d76dc2f793ba6317efbcd45f2d998565bfa0d6 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 17:30:29 +0100 Subject: [PATCH 09/11] {rustc::hir -> rustc_hir}::intravisit --- src/librustc/hir/mod.rs | 3 ++- src/{librustc/hir => librustc_hir}/intravisit.rs | 6 ++++-- src/librustc_hir/lib.rs | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) rename src/{librustc/hir => librustc_hir}/intravisit.rs (99%) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 3087fc3c1f2e6..abbff7b65f2e0 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -4,10 +4,11 @@ pub mod check_attr; pub mod exports; -pub mod intravisit; pub mod map; pub mod upvars; +pub use rustc_hir::intravisit; + use crate::ty::query::Providers; pub fn provide(providers: &mut Providers<'_>) { diff --git a/src/librustc/hir/intravisit.rs b/src/librustc_hir/intravisit.rs similarity index 99% rename from src/librustc/hir/intravisit.rs rename to src/librustc_hir/intravisit.rs index 13b5be08d8a55..f4348add4d677 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc_hir/intravisit.rs @@ -31,10 +31,12 @@ //! This order consistency is required in a few places in rustc, for //! example generator inference, and possibly also HIR borrowck. -use rustc_hir::itemlikevisit::{ItemLikeVisitor, ParItemLikeVisitor}; -use rustc_hir::*; +use crate::hir::*; +use crate::hir_id::CRATE_HIR_ID; +use crate::itemlikevisit::{ItemLikeVisitor, ParItemLikeVisitor}; use rustc_span::Span; use syntax::ast::{Attribute, Ident, Label, Name}; +use syntax::walk_list; pub struct DeepVisitor<'v, V> { visitor: &'v mut V, diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs index 8bf2e6299a9d3..66494d0fa736c 100644 --- a/src/librustc_hir/lib.rs +++ b/src/librustc_hir/lib.rs @@ -15,6 +15,7 @@ pub mod def; pub mod def_id; mod hir; pub mod hir_id; +pub mod intravisit; pub mod itemlikevisit; pub mod pat_util; pub mod print; From 922f8b70f2201279d711d255610b8410729e22c7 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 17:38:38 +0100 Subject: [PATCH 10/11] intravisit: use walk_list! more --- src/librustc_hir/intravisit.rs | 36 +++++++++------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/librustc_hir/intravisit.rs b/src/librustc_hir/intravisit.rs index f4348add4d677..4664340b15fb7 100644 --- a/src/librustc_hir/intravisit.rs +++ b/src/librustc_hir/intravisit.rs @@ -234,9 +234,7 @@ pub trait Visitor<'v>: Sized { #[allow(unused_variables)] fn visit_nested_item(&mut self, id: ItemId) { let opt_item = self.nested_visit_map().inter().map(|map| map.item(id.id)); - if let Some(item) = opt_item { - self.visit_item(item); - } + walk_list!(self, visit_item, opt_item); } /// Like `visit_nested_item()`, but for trait items. See @@ -245,9 +243,7 @@ pub trait Visitor<'v>: Sized { #[allow(unused_variables)] fn visit_nested_trait_item(&mut self, id: TraitItemId) { let opt_item = self.nested_visit_map().inter().map(|map| map.trait_item(id)); - if let Some(item) = opt_item { - self.visit_trait_item(item); - } + walk_list!(self, visit_trait_item, opt_item); } /// Like `visit_nested_item()`, but for impl items. See @@ -256,9 +252,7 @@ pub trait Visitor<'v>: Sized { #[allow(unused_variables)] fn visit_nested_impl_item(&mut self, id: ImplItemId) { let opt_item = self.nested_visit_map().inter().map(|map| map.impl_item(id)); - if let Some(item) = opt_item { - self.visit_impl_item(item); - } + walk_list!(self, visit_impl_item, opt_item); } /// Invoked to visit the body of a function, method or closure. Like @@ -267,9 +261,7 @@ pub trait Visitor<'v>: Sized { /// the body. fn visit_nested_body(&mut self, id: BodyId) { let opt_body = self.nested_visit_map().intra().map(|map| map.body(id)); - if let Some(body) = opt_body { - self.visit_body(body); - } + walk_list!(self, visit_body, opt_body); } fn visit_param(&mut self, param: &'v Param<'v>) { @@ -690,9 +682,7 @@ pub fn walk_qpath<'v, V: Visitor<'v>>( ) { match *qpath { QPath::Resolved(ref maybe_qself, ref path) => { - if let Some(ref qself) = *maybe_qself { - visitor.visit_ty(qself); - } + walk_list!(visitor, visit_ty, maybe_qself); visitor.visit_path(path, id) } QPath::TypeRelative(ref qself, ref segment) => { @@ -714,9 +704,7 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>( segment: &'v PathSegment<'v>, ) { visitor.visit_ident(segment.ident); - if let Some(id) = segment.hir_id { - visitor.visit_id(id); - } + walk_list!(visitor, visit_id, segment.hir_id); if let Some(ref args) = segment.args { visitor.visit_generic_args(path_span, args); } @@ -1005,9 +993,7 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>( visitor: &mut V, struct_definition: &'v VariantData<'v>, ) { - if let Some(ctor_hir_id) = struct_definition.ctor_hir_id() { - visitor.visit_id(ctor_hir_id); - } + walk_list!(visitor, visit_id, struct_definition.ctor_hir_id()); walk_list!(visitor, visit_struct_field, struct_definition.fields()); } @@ -1127,15 +1113,11 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) visitor.visit_qpath(qpath, expression.hir_id, expression.span); } ExprKind::Break(ref destination, ref opt_expr) => { - if let Some(ref label) = destination.label { - visitor.visit_label(label); - } + walk_list!(visitor, visit_label, &destination.label); walk_list!(visitor, visit_expr, opt_expr); } ExprKind::Continue(ref destination) => { - if let Some(ref label) = destination.label { - visitor.visit_label(label); - } + walk_list!(visitor, visit_label, &destination.label); } ExprKind::Ret(ref optional_expression) => { walk_list!(visitor, visit_expr, optional_expression); From 0997388b8719cda70c73758056496ab210726572 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 7 Jan 2020 18:12:06 +0100 Subject: [PATCH 11/11] normalize rustc::hir::intravisit imports --- src/librustc/hir/check_attr.rs | 2 +- src/librustc/hir/map/blocks.rs | 2 +- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/hir_id_validator.rs | 2 +- src/librustc/hir/map/mod.rs | 2 +- src/librustc/hir/mod.rs | 2 -- src/librustc/hir/upvars.rs | 2 +- src/librustc/infer/error_reporting/need_type_info.rs | 2 +- .../error_reporting/nice_region_error/find_anon_type.rs | 2 +- src/librustc/lint/mod.rs | 7 +++---- src/librustc/middle/weak_lang_items.rs | 3 +-- src/librustc_ast_lowering/lib.rs | 2 +- src/librustc_incremental/assert_dep_graph.rs | 2 +- src/librustc_incremental/persist/dirty_clean.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/late.rs | 4 ++-- src/librustc_lint/levels.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 3 +-- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_mir/lints.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_mir/transform/mod.rs | 2 +- src/librustc_passes/check_const.rs | 2 +- src/librustc_passes/dead.rs | 2 +- src/librustc_passes/hir_stats.rs | 2 +- src/librustc_passes/intrinsicck.rs | 2 +- src/librustc_passes/lib_features.rs | 2 +- src/librustc_passes/liveness.rs | 2 +- src/librustc_passes/loops.rs | 2 +- src/librustc_passes/reachable.rs | 4 ++-- src/librustc_passes/region.rs | 2 +- src/librustc_passes/stability.rs | 2 +- src/librustc_privacy/lib.rs | 2 +- src/librustc_resolve/lifetimes.rs | 2 +- src/librustc_traits/lowering/mod.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 2 +- src/librustc_typeck/check/generator_interior.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/check/regionck.rs | 2 +- src/librustc_typeck/check/upvar.rs | 2 +- src/librustc_typeck/check/writeback.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- src/librustdoc/test.rs | 2 +- src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs | 2 +- 47 files changed, 50 insertions(+), 55 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 75f78104b488e..06b7b3194defd 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -4,7 +4,6 @@ //! conflicts between multiple such attributes attached to the same //! item. -use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::map::Map; use crate::lint::builtin::UNUSED_ATTRIBUTES; use crate::ty::query::Providers; @@ -14,6 +13,7 @@ use errors::struct_span_err; use rustc_error_codes::*; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::DUMMY_HIR_ID; use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind}; use rustc_span::symbol::sym; diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 990acad2d50b2..016fc939a7a17 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -11,9 +11,9 @@ //! nested within a uniquely determined `FnLike`), and users can ask //! for the `Code` associated with a particular NodeId. -use crate::hir::intravisit::FnKind; use crate::hir::map::Map; use rustc_hir as hir; +use rustc_hir::intravisit::FnKind; use rustc_hir::{Expr, FnDecl, Node}; use rustc_span::Span; use syntax::ast::{Attribute, Ident}; diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 6aa1b6da36830..b6be4bb001996 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -1,5 +1,4 @@ use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex}; -use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::map::definitions::{self, DefPathHash}; use crate::hir::map::{Entry, HirEntryMap, Map}; use crate::ich::StableHashingContext; @@ -11,6 +10,7 @@ use rustc_data_structures::svh::Svh; use rustc_hir as hir; use rustc_hir::def_id::CRATE_DEF_INDEX; use rustc_hir::def_id::{CrateNum, DefIndex, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_index::vec::IndexVec; use rustc_session::{CrateDisambiguator, Session}; diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 2499acae5e656..76e42b8af2874 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -1,9 +1,9 @@ -use crate::hir::intravisit; use crate::hir::map::Map; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; +use rustc_hir::intravisit; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{HirId, ItemLocalId}; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index f7b654eae1ead..e18ab7848feaa 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -4,13 +4,13 @@ pub use self::definitions::{ }; use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex}; -use crate::hir::intravisit; use crate::middle::cstore::CrateStoreDyn; use crate::ty::query::Providers; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::intravisit; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::print::Nested; use rustc_hir::*; diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index abbff7b65f2e0..97c14dd7e0054 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -7,8 +7,6 @@ pub mod exports; pub mod map; pub mod upvars; -pub use rustc_hir::intravisit; - use crate::ty::query::Providers; pub fn provide(providers: &mut Providers<'_>) { diff --git a/src/librustc/hir/upvars.rs b/src/librustc/hir/upvars.rs index b61a54a643f70..4ca294f486155 100644 --- a/src/librustc/hir/upvars.rs +++ b/src/librustc/hir/upvars.rs @@ -1,12 +1,12 @@ //! Upvar (closure capture) collection from cross-body HIR uses of `Res::Local`s. -use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::map::Map; use crate::ty::query::Providers; use crate::ty::TyCtxt; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_hir as hir; use rustc_hir::def::Res; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{self, HirId}; use rustc_span::Span; diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 9c7bf261d9bd4..16cfaec5ee91b 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -1,4 +1,3 @@ -use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::map::Map; use crate::infer::type_variable::TypeVariableOriginKind; use crate::infer::InferCtxt; @@ -7,6 +6,7 @@ use crate::ty::{self, DefIdTree, Infer, Ty, TyVar}; use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FunctionRetTy, HirId, Local, Pat}; use rustc_span::source_map::DesugaringKind; use rustc_span::symbol::kw; diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index 6ec956f15dd34..8e2592b531885 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -1,9 +1,9 @@ -use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; use crate::hir::map::Map; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::middle::resolve_lifetime as rl; use crate::ty::{self, Region, TyCtxt}; use rustc_hir as hir; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::Node; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 2147ff1a24592..3f43800590353 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -21,11 +21,10 @@ pub use self::Level::*; pub use self::LintSource::*; -use rustc_data_structures::sync; - use crate::lint::builtin::BuiltinLintDiagnostics; use crate::ty::TyCtxt; use errors::{DiagnosticBuilder, DiagnosticId}; +use rustc_data_structures::sync; use rustc_hir as hir; use rustc_session::node_id::NodeMap; use rustc_session::{DiagnosticMessageId, Session}; @@ -109,13 +108,13 @@ macro_rules! late_lint_methods { fn check_where_predicate(a: &$hir hir::WherePredicate<$hir>); fn check_poly_trait_ref(a: &$hir hir::PolyTraitRef<$hir>, b: hir::TraitBoundModifier); fn check_fn( - a: $crate::hir::intravisit::FnKind<$hir>, + a: rustc_hir::intravisit::FnKind<$hir>, b: &$hir hir::FnDecl<$hir>, c: &$hir hir::Body<$hir>, d: Span, e: hir::HirId); fn check_fn_post( - a: $crate::hir::intravisit::FnKind<$hir>, + a: rustc_hir::intravisit::FnKind<$hir>, b: &$hir hir::FnDecl<$hir>, c: &$hir hir::Body<$hir>, d: Span, diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index 71abbd8bcb131..89f385a51bc6a 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -3,14 +3,13 @@ use crate::middle::lang_items; use crate::session::config; -use crate::hir::intravisit; -use crate::hir::intravisit::{NestedVisitorMap, Visitor}; use crate::hir::map::Map; use crate::ty::TyCtxt; use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use rustc_target::spec::PanicStrategy; diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 6c4d7ec3a8a9f..385153b62ce82 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -36,7 +36,6 @@ use rustc::arena::Arena; use rustc::dep_graph::DepGraph; -use rustc::hir::intravisit; use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions}; use rustc::hir::map::Map; use rustc::lint; @@ -52,6 +51,7 @@ use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{DefId, DefIdMap, DefIndex, CRATE_DEF_INDEX}; +use rustc_hir::intravisit; use rustc_hir::{ConstArg, GenericArg, ParamName}; use rustc_index::vec::IndexVec; use rustc_session::config::nightly_options; diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index e59a52923d9fb..9490128e32d6a 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -36,13 +36,13 @@ use graphviz as dot; use rustc::dep_graph::debug::{DepNodeFilter, EdgeFilter}; use rustc::dep_graph::{DepGraphQuery, DepKind, DepNode}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::ty::TyCtxt; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING}; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::symbol::sym; use rustc_span::Span; use syntax::ast; diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index a7f915b833d92..ddfed53fa3349 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -14,13 +14,13 @@ //! the required condition is not met. use rustc::dep_graph::{label_strs, DepNode}; -use rustc::hir::intravisit; use rustc::hir::map::Map; use rustc::ty::TyCtxt; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::Node as HirNode; use rustc_hir::{ImplItemKind, ItemKind as HirItem, TraitItemKind}; diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 213ca308d5636..23740af525971 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1089,7 +1089,7 @@ impl TypeAliasBounds { // bound. Let's see if this type does that. // We use a HIR visitor to walk the type. - use rustc::hir::intravisit::{self, Visitor}; + use rustc_hir::intravisit::{self, Visitor}; struct WalkAssocTypes<'a, 'db> { err: &'a mut DiagnosticBuilder<'db>, } diff --git a/src/librustc_lint/late.rs b/src/librustc_lint/late.rs index da27e9225d787..a37e3be9ced92 100644 --- a/src/librustc_lint/late.rs +++ b/src/librustc_lint/late.rs @@ -14,8 +14,6 @@ //! upon. As the ast is traversed, this keeps track of the current lint level //! for all lint attributes. -use rustc::hir::intravisit as hir_visit; -use rustc::hir::intravisit::Visitor; use rustc::hir::map::Map; use rustc::lint::LateContext; use rustc::lint::LintPass; @@ -24,6 +22,8 @@ use rustc::ty::{self, TyCtxt}; use rustc_data_structures::sync::{join, par_iter, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::intravisit as hir_visit; +use rustc_hir::intravisit::Visitor; use rustc_span::Span; use std::slice; use syntax::ast; diff --git a/src/librustc_lint/levels.rs b/src/librustc_lint/levels.rs index f6f1ae2a08a6f..3d3e57fe2bae3 100644 --- a/src/librustc_lint/levels.rs +++ b/src/librustc_lint/levels.rs @@ -1,10 +1,10 @@ -use rustc::hir::intravisit; use rustc::hir::map::Map; use rustc::lint::{LintLevelMap, LintLevelSets, LintLevelsBuilder, LintStore}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; +use rustc_hir::intravisit; use syntax::ast; pub use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintId}; diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index d50c048301042..13e57ecf1469c 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -1,10 +1,10 @@ use lint::{EarlyContext, LateContext, LintArray, LintContext}; use lint::{EarlyLintPass, LateLintPass, LintPass}; -use rustc::hir::intravisit::FnKind; use rustc::lint; use rustc::ty; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; +use rustc_hir::intravisit::FnKind; use rustc_hir::{GenericParamKind, PatKind}; use rustc_span::symbol::sym; use rustc_span::{symbol::Ident, BytePos, Span}; diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 390472940c764..952d3bb858276 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -36,9 +36,8 @@ use syntax::ast; use syntax::attr; use syntax::expand::is_proc_macro_attr; -use rustc::hir::intravisit; -use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir as hir; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; struct EncodeContext<'tcx> { diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index ab76f010a0f0a..ce0c081bc1608 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -4,7 +4,6 @@ use super::_match::{expand_pattern, is_useful, MatchCheckCtxt, Matrix, PatStack} use super::{PatCtxt, PatKind, PatternError}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::lint; use rustc::session::Session; @@ -15,6 +14,7 @@ use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder use rustc_hir as hir; use rustc_hir::def::*; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{HirId, Pat}; use rustc_span::symbol::sym; use rustc_span::{MultiSpan, Span}; diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index fc7f2eb18b23a..a58d17569ef71 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -1,10 +1,10 @@ -use rustc::hir::intravisit::FnKind; use rustc::hir::map::blocks::FnLikeNode; use rustc::lint::builtin::UNCONDITIONAL_RECURSION; use rustc::mir::{self, Body, TerminatorKind}; use rustc::ty::subst::InternalSubsts; use rustc::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt}; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::FnKind; use rustc_index::bit_set::BitSet; pub fn check(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 830609f7911ac..fd0373fb29cec 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -1,4 +1,3 @@ -use rustc::hir::intravisit; use rustc::hir::map::Map; use rustc::lint::builtin::{SAFE_PACKED_BORROWS, UNUSED_UNSAFE}; use rustc::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; @@ -10,6 +9,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit; use rustc_hir::Node; use rustc_span::symbol::{sym, Symbol}; diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 50abf919f9daa..a2f76042ea72b 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -1,5 +1,4 @@ use crate::{build, shim}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::mir::{BodyAndCache, ConstQualifs, MirPhase, Promoted}; use rustc::ty::query::Providers; @@ -7,6 +6,7 @@ use rustc::ty::steal::Steal; use rustc::ty::{InstanceDef, TyCtxt, TypeFoldable}; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_index::vec::IndexVec; use rustc_span::Span; use std::borrow::Cow; diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index 072a51391c877..47e6e5ccc24fe 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -8,7 +8,6 @@ //! through, but errors for structured control flow in a `const` should be emitted here. use errors::struct_span_err; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::session::config::nightly_options; use rustc::ty::query::Providers; @@ -16,6 +15,7 @@ use rustc::ty::TyCtxt; use rustc_error_codes::*; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::{sym, Span, Symbol}; use syntax::ast::Mutability; use syntax::feature_gate::feature_err; diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index 5441a8bf717a0..f626a5f8cb0d1 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -2,7 +2,6 @@ // closely. The idea is that all reachable symbols are live, codes called // from live codes are live, and everything else is dead. -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::lint; use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags; @@ -12,6 +11,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{Node, PatKind, TyKind}; diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 2c36181ce4b40..b6ca2b3a595db 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -2,11 +2,11 @@ // pieces of AST and HIR. The resulting numbers are good approximations but not // completely accurate (some things might be counted twice, others missed). -use rustc::hir::intravisit as hir_visit; use rustc::hir::map::Map; use rustc::util::common::to_readable_str; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; +use rustc_hir::intravisit as hir_visit; use rustc_hir::HirId; use rustc_span::Span; use syntax::ast::{self, AttrId, NodeId}; diff --git a/src/librustc_passes/intrinsicck.rs b/src/librustc_passes/intrinsicck.rs index 68d9ba7f90e9a..ae8ac2e2c2e35 100644 --- a/src/librustc_passes/intrinsicck.rs +++ b/src/librustc_passes/intrinsicck.rs @@ -1,5 +1,4 @@ use errors::struct_span_err; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx}; use rustc::ty::query::Providers; @@ -7,6 +6,7 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_index::vec::Idx; use rustc_span::{sym, Span}; use rustc_target::spec::abi::Abi::RustIntrinsic; diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs index 9d5e8080055a8..e7d490d6d8ddb 100644 --- a/src/librustc_passes/lib_features.rs +++ b/src/librustc_passes/lib_features.rs @@ -5,12 +5,12 @@ // (unlike lang features), which means we need to collect them instead. use errors::struct_span_err; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::middle::lib_features::LibFeatures; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_hir::def_id::LOCAL_CRATE; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::symbol::Symbol; use rustc_span::{sym, Span}; use syntax::ast::{Attribute, MetaItem, MetaItemKind}; diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 4b5b2148cd984..5c1bc4d1eaa87 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -97,7 +97,6 @@ use self::LiveNodeKind::*; use self::VarKind::*; use errors::Applicability; -use rustc::hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::lint; use rustc::ty::query::Providers; @@ -106,6 +105,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_hir as hir; use rustc_hir::def::*; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet, Node}; use rustc_span::symbol::sym; use rustc_span::Span; diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 54ea73f1d3d21..333b39c3bb302 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -3,12 +3,12 @@ use Context::*; use rustc::session::Session; use errors::{struct_span_err, Applicability}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Destination, Movability, Node}; use rustc_span::Span; diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index 016cab9d11446..5ce677f52cea6 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -5,8 +5,6 @@ // makes all other generics or inline functions that it references // reachable as well. -use rustc::hir::intravisit; -use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::middle::privacy; @@ -19,6 +17,8 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_hir::intravisit; +use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{HirIdSet, Node}; use rustc_target::spec::abi::Abi; diff --git a/src/librustc_passes/region.rs b/src/librustc_passes/region.rs index a8a56ee7f0938..e79ca5c78d6d6 100644 --- a/src/librustc_passes/region.rs +++ b/src/librustc_passes/region.rs @@ -6,7 +6,6 @@ //! //! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/borrowck.html -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::middle::region::*; use rustc::ty::query::Providers; @@ -14,6 +13,7 @@ use rustc::ty::TyCtxt; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Arm, Block, Expr, Local, Node, Pat, PatKind, Stmt}; use rustc_index::vec::Idx; use rustc_span::source_map; diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 7891fab0aa6c6..be098543a2ff2 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -2,7 +2,6 @@ //! propagating default levels lexically from parent to children ast nodes. use errors::struct_span_err; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::lint; use rustc::middle::privacy::AccessLevels; @@ -15,6 +14,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Generics, HirId, Item, StructField, Variant}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 3d0d4070a251a..a96d59340237d 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -4,7 +4,6 @@ #![recursion_limit = "256"] use rustc::bug; -use rustc::hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::lint; use rustc::middle::privacy::{AccessLevel, AccessLevels}; @@ -17,6 +16,7 @@ use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor}; use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind}; use rustc_span::hygiene::Transparency; use rustc_span::symbol::{kw, sym}; diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index 215ab0fde026e..469e1b9aa6207 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -6,7 +6,6 @@ //! way. Therefore, we break lifetime name resolution into a separate pass. use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::lint; use rustc::middle::resolve_lifetime::*; @@ -17,6 +16,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath}; use rustc_hir::{GenericParamKind, HirIdMap, HirIdSet, LifetimeParamKind}; use rustc_span::symbol::{kw, sym}; diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index 647d32d45f6be..4b4fa4b7147fc 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -1,6 +1,5 @@ mod environment; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::definitions::DefPathData; use rustc::hir::map::Map; use rustc::traits::{ @@ -13,6 +12,7 @@ use rustc::ty::{self, List, TyCtxt}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::symbol::sym; use syntax::ast; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 4bacf9349379e..0233b68a7ce21 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -10,7 +10,6 @@ use crate::namespace::Namespace; use crate::require_c_abi_if_c_variadic; use crate::util::common::ErrorReported; use errors::{struct_span_err, Applicability, DiagnosticId}; -use rustc::hir::intravisit::Visitor; use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc::traits; use rustc::traits::astconv_object_safety_violations; @@ -23,6 +22,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::Visitor; use rustc_hir::print; use rustc_hir::{ExprKind, GenericArg, GenericArgs}; use rustc_span::symbol::sym; diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 031f6e15d0dc9..449c2e90ff202 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -1,5 +1,4 @@ use errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; -use rustc::hir::intravisit; use rustc::hir::map::Map; use rustc::infer::{self, InferOk}; use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal}; @@ -10,6 +9,7 @@ use rustc::ty::{self, GenericParamDefKind, TyCtxt}; use rustc::util::common::ErrorReported; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; +use rustc_hir::intravisit; use rustc_hir::{GenericParamKind, ImplItemKind, TraitItemKind}; use rustc_span::Span; diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index 5936fe9b2a486..9d8805f225d7e 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -4,7 +4,6 @@ //! types computed here. use super::FnCtxt; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::middle::region::{self, YieldData}; use rustc::ty::{self, Ty}; @@ -12,6 +11,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Expr, ExprKind, Pat, PatKind}; use rustc_span::Span; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 35e5588273b26..4f55d9ab70ede 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -5,7 +5,6 @@ use crate::check::FnCtxt; use crate::middle::lang_items::FnOnceTraitLangItem; use crate::namespace::Namespace; use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; -use rustc::hir::intravisit; use rustc::hir::map as hir_map; use rustc::hir::map::Map; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; @@ -16,6 +15,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::intravisit; use rustc_hir::{ExprKind, Node, QPath}; use rustc_span::{source_map, FileName, Span}; use syntax::ast; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a977ecd8dafca..f10edc1a468b4 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -91,7 +91,6 @@ use crate::astconv::{AstConv, PathSeg}; use crate::middle::lang_items; use crate::namespace::Namespace; use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; @@ -119,6 +118,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{ExprKind, GenericArg, HirIdMap, ItemKind, Node, PatKind, QPath}; use rustc_index::vec::Idx; diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index b4fed3fe4e245..967741092febe 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -76,7 +76,6 @@ use crate::check::dropck; use crate::check::FnCtxt; use crate::mem_categorization as mc; use crate::middle::region; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{self, RegionObligation, SuppressRegionErrors}; @@ -85,6 +84,7 @@ use rustc::ty::subst::{GenericArgKind, SubstsRef}; use rustc::ty::{self, Ty}; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::PatKind; use rustc_span::Span; use std::mem; diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 8c107db21502b..9b4bd6d78ff28 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -35,7 +35,6 @@ use super::FnCtxt; use crate::expr_use_visitor as euv; use crate::mem_categorization as mc; use crate::mem_categorization::PlaceBase; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::infer::UpvarRegion; use rustc::ty::{self, Ty, TyCtxt, UpvarSubsts}; @@ -43,6 +42,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::def_id::LocalDefId; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::Span; use syntax::ast; diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index f03bc21aef79d..b4798fb67f80f 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -4,7 +4,6 @@ use crate::check::FnCtxt; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc::infer::InferCtxt; @@ -14,6 +13,7 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc_data_structures::sync::Lrc; use rustc_hir as hir; use rustc_hir::def_id::{DefId, DefIdSet, DefIndex}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::symbol::sym; use rustc_span::Span; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 50cd059fe8ddb..84f2e186eaa35 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -21,7 +21,6 @@ use crate::lint; use crate::middle::resolve_lifetime as rl; use crate::middle::weak_lang_items; use errors::{struct_span_err, Applicability, StashKey}; -use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::Map; use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::mir::mono::Linkage; @@ -38,6 +37,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{GenericParamKind, Node, Unsafety}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{Span, DUMMY_SP}; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index cbef4f8ae692a..94e31108901ea 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -1,10 +1,10 @@ -use rustc::hir::intravisit; use rustc::hir::map::Map; use rustc::session::{self, config, DiagnosticOutput}; use rustc::util::common::ErrorReported; use rustc_data_structures::sync::Lrc; use rustc_feature::UnstableFeatures; use rustc_hir as hir; +use rustc_hir::intravisit; use rustc_interface::interface; use rustc_span::edition::Edition; use rustc_span::source_map::SourceMap; diff --git a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs index ee14d71573041..abb2e93757ed3 100644 --- a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs +++ b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs @@ -8,7 +8,7 @@ extern crate rustc_hir; extern crate rustc_span; extern crate syntax; -use rustc::hir::intravisit; +use rustc_hir::intravisit; use rustc_hir as hir; use rustc_hir::Node; use rustc::lint::{LateContext, LintPass, LintArray, LateLintPass, LintContext};