Skip to content

Commit 73a625b

Browse files
committed
remove unnecessary hir::map imports
1 parent 45ebd58 commit 73a625b

File tree

24 files changed

+52
-51
lines changed

24 files changed

+52
-51
lines changed

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use rustc::arena::Arena;
3838
use rustc::dep_graph::DepGraph;
3939
use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
40-
use rustc::hir::map::Map;
4140
use rustc::{bug, span_bug};
4241
use rustc_ast::ast;
4342
use rustc_ast::ast::*;
@@ -1460,7 +1459,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14601459
}
14611460

14621461
impl<'r, 'a, 'v, 'hir> intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a, 'hir> {
1463-
type Map = Map<'v>;
1462+
type Map = intravisit::ErasedMap<'v>;
14641463

14651464
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
14661465
intravisit::NestedVisitorMap::None

src/librustc_hir/intravisit.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,25 @@ pub trait Map<'hir> {
127127
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>;
128128
}
129129

130+
/// An erased version of `Map<'hir>`, using dynamic dispatch.
131+
/// NOTE: This type is effectively only usable with `NestedVisitorMap::None`.
132+
pub struct ErasedMap<'hir>(&'hir dyn Map<'hir>);
133+
134+
impl<'hir> Map<'hir> for ErasedMap<'hir> {
135+
fn body(&self, id: BodyId) -> &'hir Body<'hir> {
136+
self.0.body(id)
137+
}
138+
fn item(&self, id: HirId) -> &'hir Item<'hir> {
139+
self.0.item(id)
140+
}
141+
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> {
142+
self.0.trait_item(id)
143+
}
144+
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
145+
self.0.impl_item(id)
146+
}
147+
}
148+
130149
/// Specifies what nested things a visitor wants to visit. The most
131150
/// common choice is `OnlyBodies`, which will cause the visitor to
132151
/// visit fn bodies for fns that it encounters, but skip over nested

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
//! `late_lint_methods!` invocation in `lib.rs`.
2323
2424
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
25-
use rustc::hir::map::Map;
2625
use rustc::lint::LintDiagnosticBuilder;
2726
use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt};
2827
use rustc_ast::ast::{self, Expr};
@@ -1071,7 +1070,7 @@ impl TypeAliasBounds {
10711070
err: &'a mut DiagnosticBuilder<'db>,
10721071
}
10731072
impl<'a, 'db, 'v> Visitor<'v> for WalkAssocTypes<'a, 'db> {
1074-
type Map = Map<'v>;
1073+
type Map = intravisit::ErasedMap<'v>;
10751074

10761075
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
10771076
intravisit::NestedVisitorMap::None

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc::hir::map::Map;
21
use rustc::lint::builtin::{SAFE_PACKED_BORROWS, UNUSED_UNSAFE};
32
use rustc::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
43
use rustc::mir::*;
@@ -451,7 +450,7 @@ struct UnusedUnsafeVisitor<'a> {
451450
}
452451

453452
impl<'a, 'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> {
454-
type Map = Map<'tcx>;
453+
type Map = intravisit::ErasedMap<'tcx>;
455454

456455
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
457456
intravisit::NestedVisitorMap::None

src/librustc_mir/transform/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{shim, util};
2-
use rustc::hir::map::Map;
32
use rustc::mir::{BodyAndCache, ConstQualifs, MirPhase, Promoted};
43
use rustc::ty::query::Providers;
54
use rustc::ty::steal::Steal;
@@ -86,7 +85,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
8685
}
8786
intravisit::walk_struct_def(self, v)
8887
}
89-
type Map = Map<'tcx>;
88+
type Map = intravisit::ErasedMap<'tcx>;
9089
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
9190
NestedVisitorMap::None
9291
}

src/librustc_mir_build/hair/pattern/check_match.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::_match::{expand_pattern, is_useful, MatchCheckCtxt, Matrix, PatStack}
44

55
use super::{PatCtxt, PatKind, PatternError};
66

7-
use rustc::hir::map::Map;
87
use rustc::ty::{self, Ty, TyCtxt};
98
use rustc_ast::ast::Mutability;
109
use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder};
@@ -43,7 +42,7 @@ struct MatchVisitor<'a, 'tcx> {
4342
}
4443

4544
impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
46-
type Map = Map<'tcx>;
45+
type Map = intravisit::ErasedMap<'tcx>;
4746

4847
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
4948
NestedVisitorMap::None
@@ -753,7 +752,7 @@ fn check_legality_of_bindings_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pa
753752
}
754753

755754
impl<'v> Visitor<'v> for AtBindingPatternVisitor<'_, '_, '_> {
756-
type Map = Map<'v>;
755+
type Map = intravisit::ErasedMap<'v>;
757756

758757
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
759758
NestedVisitorMap::None

src/librustc_passes/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
210210
}
211211

212212
impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
213-
type Map = Map<'tcx>;
213+
type Map = intravisit::ErasedMap<'tcx>;
214214

215215
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
216216
NestedVisitorMap::None

src/librustc_passes/intrinsicck.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc::hir::map::Map;
21
use rustc::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx};
32
use rustc::ty::query::Providers;
43
use rustc::ty::{self, Ty, TyCtxt};
@@ -122,7 +121,7 @@ impl ExprVisitor<'tcx> {
122121
}
123122

124123
impl Visitor<'tcx> for ItemVisitor<'tcx> {
125-
type Map = Map<'tcx>;
124+
type Map = intravisit::ErasedMap<'tcx>;
126125

127126
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
128127
NestedVisitorMap::None
@@ -139,7 +138,7 @@ impl Visitor<'tcx> for ItemVisitor<'tcx> {
139138
}
140139

141140
impl Visitor<'tcx> for ExprVisitor<'tcx> {
142-
type Map = Map<'tcx>;
141+
type Map = intravisit::ErasedMap<'tcx>;
143142

144143
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
145144
NestedVisitorMap::None

src/librustc_passes/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13591359
// Checking for error conditions
13601360

13611361
impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> {
1362-
type Map = Map<'tcx>;
1362+
type Map = intravisit::ErasedMap<'tcx>;
13631363

13641364
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
13651365
NestedVisitorMap::None

src/librustc_passes/reachable.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// makes all other generics or inline functions that it references
66
// reachable as well.
77

8-
use rustc::hir::map::Map;
98
use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
109
use rustc::middle::privacy;
1110
use rustc::session::config;
@@ -17,8 +16,7 @@ use rustc_hir as hir;
1716
use rustc_hir::def::{DefKind, Res};
1817
use rustc_hir::def_id::LOCAL_CRATE;
1918
use rustc_hir::def_id::{CrateNum, DefId};
20-
use rustc_hir::intravisit;
21-
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
19+
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
2220
use rustc_hir::itemlikevisit::ItemLikeVisitor;
2321
use rustc_hir::{HirIdSet, Node};
2422
use rustc_target::spec::abi::Abi;
@@ -83,7 +81,7 @@ struct ReachableContext<'a, 'tcx> {
8381
}
8482

8583
impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
86-
type Map = Map<'tcx>;
84+
type Map = intravisit::ErasedMap<'tcx>;
8785

8886
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
8987
NestedVisitorMap::None

src/librustc_passes/region.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//!
77
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html
88
9-
use rustc::hir::map::Map;
109
use rustc::middle::region::*;
1110
use rustc::ty::query::Providers;
1211
use rustc::ty::TyCtxt;
@@ -696,7 +695,7 @@ impl<'tcx> RegionResolutionVisitor<'tcx> {
696695
}
697696

698697
impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
699-
type Map = Map<'tcx>;
698+
type Map = intravisit::ErasedMap<'tcx>;
700699

701700
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
702701
NestedVisitorMap::None

src/librustc_passes/upvars.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Upvar (closure capture) collection from cross-body HIR uses of `Res::Local`s.
22
3-
use rustc::hir::map::Map;
43
use rustc::ty::query::Providers;
54
use rustc::ty::TyCtxt;
65
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
@@ -44,7 +43,7 @@ struct LocalCollector {
4443
}
4544

4645
impl Visitor<'tcx> for LocalCollector {
47-
type Map = Map<'tcx>;
46+
type Map = intravisit::ErasedMap<'tcx>;
4847

4948
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
5049
NestedVisitorMap::None
@@ -73,7 +72,7 @@ impl CaptureCollector<'_, '_> {
7372
}
7473

7574
impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> {
76-
type Map = Map<'tcx>;
75+
type Map = intravisit::ErasedMap<'tcx>;
7776

7877
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
7978
NestedVisitorMap::None

src/librustc_passes/weak_lang_items.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc::middle::lang_items;
44
use rustc::middle::lang_items::whitelisted;
55
use rustc::session::config;
66

7-
use rustc::hir::map::Map;
87
use rustc::ty::TyCtxt;
98
use rustc_data_structures::fx::FxHashSet;
109
use rustc_errors::struct_span_err;
@@ -85,9 +84,9 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
8584
}
8685

8786
impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
88-
type Map = Map<'v>;
87+
type Map = intravisit::ErasedMap<'v>;
8988

90-
fn nested_visit_map(&mut self) -> NestedVisitorMap<Map<'v>> {
89+
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
9190
NestedVisitorMap::None
9291
}
9392

src/librustc_privacy/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
14471447
}
14481448

14491449
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
1450-
type Map = Map<'v>;
1450+
type Map = intravisit::ErasedMap<'v>;
14511451

14521452
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
14531453
NestedVisitorMap::None

src/librustc_resolve/late/lifetimes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
11231123
gather.visit_body(body);
11241124

11251125
impl<'v, 'a, 'tcx> Visitor<'v> for GatherLabels<'a, 'tcx> {
1126-
type Map = Map<'v>;
1126+
type Map = intravisit::ErasedMap<'v>;
11271127

11281128
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
11291129
NestedVisitorMap::None
@@ -2172,7 +2172,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
21722172
}
21732173

21742174
impl<'a> Visitor<'a> for SelfVisitor<'a> {
2175-
type Map = Map<'a>;
2175+
type Map = intravisit::ErasedMap<'a>;
21762176

21772177
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
21782178
NestedVisitorMap::None
@@ -2263,7 +2263,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22632263
}
22642264

22652265
impl<'v, 'a> Visitor<'v> for GatherLifetimes<'a> {
2266-
type Map = Map<'v>;
2266+
type Map = intravisit::ErasedMap<'v>;
22672267

22682268
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
22692269
NestedVisitorMap::None
@@ -2852,7 +2852,7 @@ fn insert_late_bound_lifetimes(
28522852
}
28532853

28542854
impl<'v> Visitor<'v> for ConstrainedCollector {
2855-
type Map = Map<'v>;
2855+
type Map = intravisit::ErasedMap<'v>;
28562856

28572857
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
28582858
NestedVisitorMap::None
@@ -2895,7 +2895,7 @@ fn insert_late_bound_lifetimes(
28952895
}
28962896

28972897
impl<'v> Visitor<'v> for AllCollector {
2898-
type Map = Map<'v>;
2898+
type Map = intravisit::ErasedMap<'v>;
28992899

29002900
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
29012901
NestedVisitorMap::None

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ struct ReturnsVisitor<'v> {
15671567
}
15681568

15691569
impl<'v> Visitor<'v> for ReturnsVisitor<'v> {
1570-
type Map = rustc::hir::map::Map<'v>;
1570+
type Map = hir::intravisit::ErasedMap<'v>;
15711571

15721572
fn nested_visit_map(&mut self) -> hir::intravisit::NestedVisitorMap<Self::Map> {
15731573
hir::intravisit::NestedVisitorMap::None

src/librustc_typeck/check/compare_method.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc::hir::map::Map;
21
use rustc::ty::error::{ExpectedFound, TypeError};
32
use rustc::ty::subst::{InternalSubsts, Subst};
43
use rustc::ty::util::ExplicitSelf;
@@ -890,7 +889,7 @@ fn compare_synthetic_generics<'tcx>(
890889
}
891890
}
892891
}
893-
type Map = Map<'v>;
892+
type Map = intravisit::ErasedMap<'v>;
894893
fn nested_visit_map(
895894
&mut self,
896895
) -> intravisit::NestedVisitorMap<Self::Map>

src/librustc_typeck/check/generator_interior.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! types computed here.
55
66
use super::FnCtxt;
7-
use rustc::hir::map::Map;
87
use rustc::middle::region::{self, YieldData};
98
use rustc::ty::{self, Ty};
109
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -209,7 +208,7 @@ pub fn resolve_interior<'a, 'tcx>(
209208
// librustc/middle/region.rs since `expr_count` is compared against the results
210209
// there.
211210
impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
212-
type Map = Map<'tcx>;
211+
type Map = intravisit::ErasedMap<'tcx>;
213212

214213
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
215214
NestedVisitorMap::None

src/librustc_typeck/check/method/suggest.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use crate::check::FnCtxt;
55
use crate::middle::lang_items::FnOnceTraitLangItem;
66
use rustc::hir::map as hir_map;
7-
use rustc::hir::map::Map;
87
use rustc::ty::print::with_crate_prefix;
98
use rustc::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
109
use rustc_ast::ast;
@@ -1347,7 +1346,7 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
13471346
}
13481347
}
13491348

1350-
type Map = Map<'tcx>;
1349+
type Map = intravisit::ErasedMap<'tcx>;
13511350

13521351
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
13531352
intravisit::NestedVisitorMap::None

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub mod writeback;
9090
use crate::astconv::{AstConv, GenericArgCountMismatch, PathSeg};
9191
use crate::middle::lang_items;
9292
use rustc::hir::map::blocks::FnLikeNode;
93-
use rustc::hir::map::Map;
9493
use rustc::middle::region;
9594
use rustc::mir::interpret::ConstValue;
9695
use rustc::session::parse::feature_err;
@@ -1177,7 +1176,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
11771176
}
11781177

11791178
impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
1180-
type Map = Map<'tcx>;
1179+
type Map = intravisit::ErasedMap<'tcx>;
11811180

11821181
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
11831182
NestedVisitorMap::None

src/librustc_typeck/check/regionck.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ use crate::check::dropck;
7676
use crate::check::FnCtxt;
7777
use crate::mem_categorization as mc;
7878
use crate::middle::region;
79-
use rustc::hir::map::Map;
8079
use rustc::ty::adjustment;
8180
use rustc::ty::subst::{GenericArgKind, SubstsRef};
8281
use rustc::ty::{self, Ty};
@@ -417,7 +416,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
417416
// hierarchy, and in particular the relationships between free
418417
// regions, until regionck, as described in #3238.
419418

420-
type Map = Map<'tcx>;
419+
type Map = intravisit::ErasedMap<'tcx>;
421420

422421
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
423422
NestedVisitorMap::None

0 commit comments

Comments
 (0)