1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use middle::def_id::DefId;
13 use rustc_front::util::IdVisitor;
14 use syntax::ast_util::{IdRange, IdRangeComputingVisitor, IdVisitingOperation};
16 use rustc_front::visit::Visitor;
17 use self::InlinedItem::*;
19 /// The data we save and restore about an inlined item or method. This is not
20 /// part of the AST that we parse from a file, but it becomes part of the tree
22 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
23 pub enum InlinedItem {
25 TraitItem(DefId /* impl id */, P<hir::TraitItem>),
26 ImplItem(DefId /* impl id */, P<hir::ImplItem>),
27 Foreign(P<hir::ForeignItem>),
30 /// A borrowed version of `hir::InlinedItem`.
31 pub enum InlinedItemRef<'a> {
33 TraitItem(DefId, &'a hir::TraitItem),
34 ImplItem(DefId, &'a hir::ImplItem),
35 Foreign(&'a hir::ForeignItem)
39 pub fn visit<'ast,V>(&'ast self, visitor: &mut V)
40 where V: Visitor<'ast>
43 Item(ref i) => visitor.visit_item(&**i),
44 Foreign(ref i) => visitor.visit_foreign_item(&**i),
45 TraitItem(_, ref ti) => visitor.visit_trait_item(ti),
46 ImplItem(_, ref ii) => visitor.visit_impl_item(ii),
50 pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
51 let mut id_visitor = IdVisitor::new(operation);
52 self.visit(&mut id_visitor);
55 pub fn compute_id_range(&self) -> IdRange {
56 let mut visitor = IdRangeComputingVisitor::new();
57 self.visit_ids(&mut visitor);