]> git.proxmox.com Git - rustc.git/blob - src/librustc_driver/derive_registrar.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / librustc_driver / derive_registrar.rs
1 // Copyright 2016 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.
4 //
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.
10
11 use rustc::dep_graph::DepNode;
12 use rustc::hir::intravisit::Visitor;
13 use rustc::hir::map::Map;
14 use rustc::hir;
15 use syntax::ast;
16 use syntax::attr;
17
18 pub fn find(hir_map: &Map) -> Option<ast::NodeId> {
19 let _task = hir_map.dep_graph.in_task(DepNode::PluginRegistrar);
20 let krate = hir_map.krate();
21
22 let mut finder = Finder { registrar: None };
23 krate.visit_all_items(&mut finder);
24 finder.registrar
25 }
26
27 struct Finder {
28 registrar: Option<ast::NodeId>,
29 }
30
31 impl<'v> Visitor<'v> for Finder {
32 fn visit_item(&mut self, item: &hir::Item) {
33 if attr::contains_name(&item.attrs, "rustc_derive_registrar") {
34 self.registrar = Some(item.id);
35 }
36 }
37 }