Skip to content

Commit 0b3ef24

Browse files
authored
Rollup merge of rust-lang#67979 - Centril:hir-cleanup, r=Zoxc
Move `intravisit` => `rustc_hir` + misc cleanup Working towards rust-lang#65031. This should eventually enable getting rid of rustc as a dependency in various passes (e.g. lints). cc rust-lang#67806 (this also facilitates liberating lints from tcx) cc rust-lang#67922 (some other dep reductions) r? @Zoxc
2 parents 5ea6978 + 0997388 commit 0b3ef24

File tree

50 files changed

+421
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+421
-262
lines changed

src/librustc/hir/check_attr.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
7+
use crate::hir::map::Map;
88
use crate::lint::builtin::UNUSED_ATTRIBUTES;
99
use crate::ty::query::Providers;
1010
use crate::ty::TyCtxt;
@@ -13,6 +13,7 @@ use errors::struct_span_err;
1313
use rustc_error_codes::*;
1414
use rustc_hir as hir;
1515
use rustc_hir::def_id::DefId;
16+
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1617
use rustc_hir::DUMMY_HIR_ID;
1718
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem, TraitItemKind};
1819
use rustc_span::symbol::sym;
@@ -519,7 +520,9 @@ impl CheckAttrVisitor<'tcx> {
519520
}
520521

521522
impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
522-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
523+
type Map = Map<'tcx>;
524+
525+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, Self::Map> {
523526
NestedVisitorMap::OnlyBodies(&self.tcx.hir())
524527
}
525528

src/librustc/hir/map/blocks.rs

+54-54
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//! nested within a uniquely determined `FnLike`), and users can ask
1212
//! for the `Code` associated with a particular NodeId.
1313
14-
use crate::hir::intravisit::FnKind;
15-
use crate::hir::map;
16-
use rustc_hir as ast;
14+
use crate::hir::map::Map;
15+
use rustc_hir as hir;
16+
use rustc_hir::intravisit::FnKind;
1717
use rustc_hir::{Expr, FnDecl, Node};
1818
use rustc_span::Span;
1919
use syntax::ast::{Attribute, Ident};
@@ -39,37 +39,37 @@ trait MaybeFnLike {
3939
fn is_fn_like(&self) -> bool;
4040
}
4141

42-
impl MaybeFnLike for ast::Item<'_> {
42+
impl MaybeFnLike for hir::Item<'_> {
4343
fn is_fn_like(&self) -> bool {
4444
match self.kind {
45-
ast::ItemKind::Fn(..) => true,
45+
hir::ItemKind::Fn(..) => true,
4646
_ => false,
4747
}
4848
}
4949
}
5050

51-
impl MaybeFnLike for ast::ImplItem<'_> {
51+
impl MaybeFnLike for hir::ImplItem<'_> {
5252
fn is_fn_like(&self) -> bool {
5353
match self.kind {
54-
ast::ImplItemKind::Method(..) => true,
54+
hir::ImplItemKind::Method(..) => true,
5555
_ => false,
5656
}
5757
}
5858
}
5959

60-
impl MaybeFnLike for ast::TraitItem<'_> {
60+
impl MaybeFnLike for hir::TraitItem<'_> {
6161
fn is_fn_like(&self) -> bool {
6262
match self.kind {
63-
ast::TraitItemKind::Method(_, ast::TraitMethod::Provided(_)) => true,
63+
hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true,
6464
_ => false,
6565
}
6666
}
6767
}
6868

69-
impl MaybeFnLike for ast::Expr<'_> {
69+
impl MaybeFnLike for hir::Expr<'_> {
7070
fn is_fn_like(&self) -> bool {
7171
match self.kind {
72-
ast::ExprKind::Closure(..) => true,
72+
hir::ExprKind::Closure(..) => true,
7373
_ => false,
7474
}
7575
}
@@ -85,21 +85,21 @@ pub enum Code<'a> {
8585
}
8686

8787
impl<'a> Code<'a> {
88-
pub fn id(&self) -> ast::HirId {
88+
pub fn id(&self) -> hir::HirId {
8989
match *self {
9090
Code::FnLike(node) => node.id(),
9191
Code::Expr(block) => block.hir_id,
9292
}
9393
}
9494

9595
/// Attempts to construct a Code from presumed FnLike or Expr node input.
96-
pub fn from_node(map: &map::Map<'a>, id: ast::HirId) -> Option<Code<'a>> {
96+
pub fn from_node(map: &Map<'a>, id: hir::HirId) -> Option<Code<'a>> {
9797
match map.get(id) {
98-
map::Node::Block(_) => {
98+
Node::Block(_) => {
9999
// Use the parent, hopefully an expression node.
100100
Code::from_node(map, map.get_parent_node(id))
101101
}
102-
map::Node::Expr(expr) => Some(Code::Expr(expr)),
102+
Node::Expr(expr) => Some(Code::Expr(expr)),
103103
node => FnLikeNode::from_node(node).map(Code::FnLike),
104104
}
105105
}
@@ -109,12 +109,12 @@ impl<'a> Code<'a> {
109109
/// use when implementing FnLikeNode operations.
110110
struct ItemFnParts<'a> {
111111
ident: Ident,
112-
decl: &'a ast::FnDecl<'a>,
113-
header: ast::FnHeader,
114-
vis: &'a ast::Visibility<'a>,
115-
generics: &'a ast::Generics<'a>,
116-
body: ast::BodyId,
117-
id: ast::HirId,
112+
decl: &'a hir::FnDecl<'a>,
113+
header: hir::FnHeader,
114+
vis: &'a hir::Visibility<'a>,
115+
generics: &'a hir::Generics<'a>,
116+
body: hir::BodyId,
117+
id: hir::HirId,
118118
span: Span,
119119
attrs: &'a [Attribute],
120120
}
@@ -123,17 +123,17 @@ struct ItemFnParts<'a> {
123123
/// for use when implementing FnLikeNode operations.
124124
struct ClosureParts<'a> {
125125
decl: &'a FnDecl<'a>,
126-
body: ast::BodyId,
127-
id: ast::HirId,
126+
body: hir::BodyId,
127+
id: hir::HirId,
128128
span: Span,
129129
attrs: &'a [Attribute],
130130
}
131131

132132
impl<'a> ClosureParts<'a> {
133133
fn new(
134134
d: &'a FnDecl<'a>,
135-
b: ast::BodyId,
136-
id: ast::HirId,
135+
b: hir::BodyId,
136+
id: hir::HirId,
137137
s: Span,
138138
attrs: &'a [Attribute],
139139
) -> Self {
@@ -145,65 +145,65 @@ impl<'a> FnLikeNode<'a> {
145145
/// Attempts to construct a FnLikeNode from presumed FnLike node input.
146146
pub fn from_node(node: Node<'_>) -> Option<FnLikeNode<'_>> {
147147
let fn_like = match node {
148-
map::Node::Item(item) => item.is_fn_like(),
149-
map::Node::TraitItem(tm) => tm.is_fn_like(),
150-
map::Node::ImplItem(it) => it.is_fn_like(),
151-
map::Node::Expr(e) => e.is_fn_like(),
148+
Node::Item(item) => item.is_fn_like(),
149+
Node::TraitItem(tm) => tm.is_fn_like(),
150+
Node::ImplItem(it) => it.is_fn_like(),
151+
Node::Expr(e) => e.is_fn_like(),
152152
_ => false,
153153
};
154154
fn_like.then_some(FnLikeNode { node })
155155
}
156156

157-
pub fn body(self) -> ast::BodyId {
157+
pub fn body(self) -> hir::BodyId {
158158
self.handle(
159159
|i: ItemFnParts<'a>| i.body,
160-
|_, _, _: &'a ast::FnSig<'a>, _, body: ast::BodyId, _, _| body,
160+
|_, _, _: &'a hir::FnSig<'a>, _, body: hir::BodyId, _, _| body,
161161
|c: ClosureParts<'a>| c.body,
162162
)
163163
}
164164

165165
pub fn decl(self) -> &'a FnDecl<'a> {
166166
self.handle(
167167
|i: ItemFnParts<'a>| &*i.decl,
168-
|_, _, sig: &'a ast::FnSig<'a>, _, _, _, _| &sig.decl,
168+
|_, _, sig: &'a hir::FnSig<'a>, _, _, _, _| &sig.decl,
169169
|c: ClosureParts<'a>| c.decl,
170170
)
171171
}
172172

173173
pub fn span(self) -> Span {
174174
self.handle(
175175
|i: ItemFnParts<'_>| i.span,
176-
|_, _, _: &'a ast::FnSig<'a>, _, _, span, _| span,
176+
|_, _, _: &'a hir::FnSig<'a>, _, _, span, _| span,
177177
|c: ClosureParts<'_>| c.span,
178178
)
179179
}
180180

181-
pub fn id(self) -> ast::HirId {
181+
pub fn id(self) -> hir::HirId {
182182
self.handle(
183183
|i: ItemFnParts<'_>| i.id,
184-
|id, _, _: &'a ast::FnSig<'a>, _, _, _, _| id,
184+
|id, _, _: &'a hir::FnSig<'a>, _, _, _, _| id,
185185
|c: ClosureParts<'_>| c.id,
186186
)
187187
}
188188

189-
pub fn constness(self) -> ast::Constness {
190-
self.kind().header().map_or(ast::Constness::NotConst, |header| header.constness)
189+
pub fn constness(self) -> hir::Constness {
190+
self.kind().header().map_or(hir::Constness::NotConst, |header| header.constness)
191191
}
192192

193-
pub fn asyncness(self) -> ast::IsAsync {
194-
self.kind().header().map_or(ast::IsAsync::NotAsync, |header| header.asyncness)
193+
pub fn asyncness(self) -> hir::IsAsync {
194+
self.kind().header().map_or(hir::IsAsync::NotAsync, |header| header.asyncness)
195195
}
196196

197-
pub fn unsafety(self) -> ast::Unsafety {
198-
self.kind().header().map_or(ast::Unsafety::Normal, |header| header.unsafety)
197+
pub fn unsafety(self) -> hir::Unsafety {
198+
self.kind().header().map_or(hir::Unsafety::Normal, |header| header.unsafety)
199199
}
200200

201201
pub fn kind(self) -> FnKind<'a> {
202202
let item = |p: ItemFnParts<'a>| -> FnKind<'a> {
203203
FnKind::ItemFn(p.ident, p.generics, p.header, p.vis, p.attrs)
204204
};
205205
let closure = |c: ClosureParts<'a>| FnKind::Closure(c.attrs);
206-
let method = |_, ident: Ident, sig: &'a ast::FnSig<'a>, vis, _, _, attrs| {
206+
let method = |_, ident: Ident, sig: &'a hir::FnSig<'a>, vis, _, _, attrs| {
207207
FnKind::Method(ident, sig, vis, attrs)
208208
};
209209
self.handle(item, method, closure)
@@ -213,19 +213,19 @@ impl<'a> FnLikeNode<'a> {
213213
where
214214
I: FnOnce(ItemFnParts<'a>) -> A,
215215
M: FnOnce(
216-
ast::HirId,
216+
hir::HirId,
217217
Ident,
218-
&'a ast::FnSig<'a>,
219-
Option<&'a ast::Visibility<'a>>,
220-
ast::BodyId,
218+
&'a hir::FnSig<'a>,
219+
Option<&'a hir::Visibility<'a>>,
220+
hir::BodyId,
221221
Span,
222222
&'a [Attribute],
223223
) -> A,
224224
C: FnOnce(ClosureParts<'a>) -> A,
225225
{
226226
match self.node {
227-
map::Node::Item(i) => match i.kind {
228-
ast::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts {
227+
Node::Item(i) => match i.kind {
228+
hir::ItemKind::Fn(ref sig, ref generics, block) => item_fn(ItemFnParts {
229229
id: i.hir_id,
230230
ident: i.ident,
231231
decl: &sig.decl,
@@ -238,20 +238,20 @@ impl<'a> FnLikeNode<'a> {
238238
}),
239239
_ => bug!("item FnLikeNode that is not fn-like"),
240240
},
241-
map::Node::TraitItem(ti) => match ti.kind {
242-
ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => {
241+
Node::TraitItem(ti) => match ti.kind {
242+
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
243243
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
244244
}
245245
_ => bug!("trait method FnLikeNode that is not fn-like"),
246246
},
247-
map::Node::ImplItem(ii) => match ii.kind {
248-
ast::ImplItemKind::Method(ref sig, body) => {
247+
Node::ImplItem(ii) => match ii.kind {
248+
hir::ImplItemKind::Method(ref sig, body) => {
249249
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
250250
}
251251
_ => bug!("impl method FnLikeNode that is not fn-like"),
252252
},
253-
map::Node::Expr(e) => match e.kind {
254-
ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) => {
253+
Node::Expr(e) => match e.kind {
254+
hir::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) => {
255255
closure(ClosureParts::new(&decl, block, e.hir_id, e.span, &e.attrs))
256256
}
257257
_ => bug!("expr FnLikeNode that is not fn-like"),

0 commit comments

Comments
 (0)