Skip to content

Commit 3fd67eb

Browse files
committed
fallout from separating impl-items from impls
Basically adding `visit_impl_item` in various places and so forth.
1 parent b889259 commit 3fd67eb

File tree

30 files changed

+233
-70
lines changed

30 files changed

+233
-70
lines changed

src/librustc/hir/itemlikevisit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use super::intravisit::Visitor;
5656
/// needed.
5757
pub trait ItemLikeVisitor<'hir> {
5858
fn visit_item(&mut self, item: &'hir Item);
59+
fn visit_impl_item(&mut self, impl_item: &'hir ImplItem);
5960
}
6061

6162
pub struct DeepVisitor<'v, V: 'v> {
@@ -76,4 +77,8 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V>
7677
fn visit_item(&mut self, item: &'hir Item) {
7778
self.visitor.visit_item(item);
7879
}
80+
81+
fn visit_impl_item(&mut self, impl_item: &'hir ImplItem) {
82+
self.visitor.visit_impl_item(impl_item);
83+
}
7984
}

src/librustc/hir/map/collector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
9999
}
100100
}
101101

102+
fn visit_nested_impl_item(&mut self, item_id: ImplItemId) {
103+
self.visit_impl_item(self.krate.impl_item(item_id))
104+
}
105+
102106
fn visit_item(&mut self, i: &'ast Item) {
103107
debug!("visit_item: {:?}", i);
104108

src/librustc/lint/context.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,13 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
797797
/// items in the context of the outer item, so enable
798798
/// deep-walking.
799799
fn visit_nested_item(&mut self, item: hir::ItemId) {
800-
let tcx = self.tcx;
801-
self.visit_item(tcx.map.expect_item(item.id))
800+
let item = self.tcx.map.expect_item(item.id);
801+
self.visit_item(item)
802+
}
803+
804+
fn visit_nested_impl_item(&mut self, item_id: hir::ImplItemId) {
805+
let impl_item = self.tcx.map.impl_item(item_id);
806+
self.visit_impl_item(impl_item)
802807
}
803808

804809
fn visit_item(&mut self, it: &hir::Item) {

src/librustc/middle/dead.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,12 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
330330
// or
331331
// 2) We are not sure to be live or not
332332
// * Implementation of a trait method
333-
struct LifeSeeder {
334-
worklist: Vec<ast::NodeId>
333+
struct LifeSeeder<'k> {
334+
worklist: Vec<ast::NodeId>,
335+
krate: &'k hir::Crate,
335336
}
336337

337-
impl<'v> ItemLikeVisitor<'v> for LifeSeeder {
338+
impl<'v, 'k> ItemLikeVisitor<'v> for LifeSeeder<'k> {
338339
fn visit_item(&mut self, item: &hir::Item) {
339340
let allow_dead_code = has_allow_dead_code_or_lang_attr(&item.attrs);
340341
if allow_dead_code {
@@ -358,17 +359,22 @@ impl<'v> ItemLikeVisitor<'v> for LifeSeeder {
358359
}
359360
}
360361
}
361-
hir::ItemImpl(.., ref opt_trait, _, ref impl_items) => {
362-
for impl_item in impl_items {
362+
hir::ItemImpl(.., ref opt_trait, _, ref impl_item_ids) => {
363+
for &impl_item_id in impl_item_ids {
364+
let impl_item = self.krate.impl_item(impl_item_id);
363365
if opt_trait.is_some() ||
364366
has_allow_dead_code_or_lang_attr(&impl_item.attrs) {
365-
self.worklist.push(impl_item.id);
367+
self.worklist.push(impl_item_id.id);
366368
}
367369
}
368370
}
369371
_ => ()
370372
}
371373
}
374+
375+
fn visit_impl_item(&mut self, _item: &hir::ImplItem) {
376+
// ignore: we are handling this in `visit_item` above
377+
}
372378
}
373379

374380
fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -387,7 +393,8 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
387393

388394
// Seed implemented trait items
389395
let mut life_seeder = LifeSeeder {
390-
worklist: worklist
396+
worklist: worklist,
397+
krate: krate,
391398
};
392399
krate.visit_all_item_likes(&mut life_seeder);
393400

@@ -510,8 +517,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
510517
/// an error. We could do this also by checking the parents, but
511518
/// this is how the code is setup and it seems harmless enough.
512519
fn visit_nested_item(&mut self, item: hir::ItemId) {
513-
let tcx = self.tcx;
514-
self.visit_item(tcx.map.expect_item(item.id))
520+
let item = self.tcx.map.expect_item(item.id);
521+
self.visit_item(item)
522+
}
523+
524+
fn visit_nested_impl_item(&mut self, item_id: hir::ImplItemId) {
525+
let impl_item = self.tcx.map.impl_item(item_id);
526+
self.visit_impl_item(impl_item)
515527
}
516528

517529
fn visit_item(&mut self, item: &hir::Item) {

src/librustc/middle/entry.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::ast::NodeId;
1717
use syntax::attr;
1818
use syntax::entry::EntryPointType;
1919
use syntax_pos::Span;
20-
use hir::{Item, ItemFn};
20+
use hir::{Item, ItemFn, ImplItem};
2121
use hir::itemlikevisit::ItemLikeVisitor;
2222

2323
struct EntryContext<'a, 'tcx: 'a> {
@@ -46,6 +46,10 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> {
4646
let at_root = def_key.parent == Some(CRATE_DEF_INDEX);
4747
find_item(item, self, at_root);
4848
}
49+
50+
fn visit_impl_item(&mut self, _impl_item: &'tcx ImplItem) {
51+
// entry fn is never an impl item
52+
}
4953
}
5054

5155
pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) {

src/librustc/middle/lang_items.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ impl<'a, 'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'a, 'tcx> {
164164
}
165165
}
166166
}
167+
168+
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
169+
// at present, lang items are always items, not impl items
170+
}
167171
}
168172

169173
impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {

src/librustc/middle/reachable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ impl<'a, 'v> ItemLikeVisitor<'v> for CollectPrivateImplItemsVisitor<'a> {
336336
}
337337
}
338338
}
339+
340+
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
341+
// processed in visit_item above
342+
}
339343
}
340344

341345
pub fn find_reachable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

src/librustc/middle/resolve_lifetime.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for LifetimeContext<'a, 'tcx> {
141141
self.visit_item(item)
142142
}
143143

144+
fn visit_nested_impl_item(&mut self, id: hir::ImplItemId) {
145+
let impl_item = self.hir_map.impl_item(id);
146+
self.visit_impl_item(impl_item)
147+
}
148+
144149
fn visit_item(&mut self, item: &hir::Item) {
145150
// Save labels for nested items.
146151
let saved_labels_in_fn = replace(&mut self.labels_in_fn, vec![]);

src/librustc/middle/stability.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
239239
/// nested items in the context of the outer item, so enable
240240
/// deep-walking.
241241
fn visit_nested_item(&mut self, item: hir::ItemId) {
242-
let tcx = self.tcx;
243-
self.visit_item(tcx.map.expect_item(item.id))
242+
let item = self.tcx.map.expect_item(item.id);
243+
self.visit_item(item)
244+
}
245+
246+
fn visit_nested_impl_item(&mut self, item_id: hir::ImplItemId) {
247+
let impl_item = self.tcx.map.impl_item(item_id);
248+
self.visit_impl_item(impl_item)
244249
}
245250

246251
fn visit_item(&mut self, i: &Item) {
@@ -449,8 +454,13 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
449454
/// nested items in the context of the outer item, so enable
450455
/// deep-walking.
451456
fn visit_nested_item(&mut self, item: hir::ItemId) {
452-
let tcx = self.tcx;
453-
self.visit_item(tcx.map.expect_item(item.id))
457+
let item = self.tcx.map.expect_item(item.id);
458+
self.visit_item(item)
459+
}
460+
461+
fn visit_nested_impl_item(&mut self, item_id: hir::ImplItemId) {
462+
let impl_item = self.tcx.map.impl_item(item_id);
463+
self.visit_impl_item(impl_item)
454464
}
455465

456466
fn visit_item(&mut self, item: &hir::Item) {
@@ -527,9 +537,10 @@ pub fn check_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
527537
// For implementations of traits, check the stability of each item
528538
// individually as it's possible to have a stable trait with unstable
529539
// items.
530-
hir::ItemImpl(.., Some(ref t), _, ref impl_items) => {
540+
hir::ItemImpl(.., Some(ref t), _, ref impl_item_ids) => {
531541
let trait_did = tcx.expect_def(t.ref_id).def_id();
532-
for impl_item in impl_items {
542+
for &impl_item_id in impl_item_ids {
543+
let impl_item = tcx.map.impl_item(impl_item_id);
533544
let item = tcx.associated_items(trait_did)
534545
.find(|item| item.name == impl_item.name).unwrap();
535546
if warn_about_defns {

src/librustc_driver/derive_registrar.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ impl<'v> ItemLikeVisitor<'v> for Finder {
3434
self.registrar = Some(item.id);
3535
}
3636
}
37+
38+
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
39+
}
3740
}
41+

0 commit comments

Comments
 (0)