diff options
| author | Igor Matuszewski <Xanewok@gmail.com> | 2019-01-13 01:06:50 +0100 |
|---|---|---|
| committer | Igor Matuszewski <Xanewok@gmail.com> | 2019-01-13 23:53:58 +0100 |
| commit | 59d7d7d54b4b31d6a20143484536c4806fa8a74e (patch) | |
| tree | 2da2213c232f8279a7d0ba322cb7bc3da1f520b1 /src/librustc_plugin | |
| parent | fb6040096ca2c21c354a500ab8fd0038d84be193 (diff) | |
| download | rust-59d7d7d54b4b31d6a20143484536c4806fa8a74e.tar.gz rust-59d7d7d54b4b31d6a20143484536c4806fa8a74e.zip | |
Querify local plugin_registrar_fn
Diffstat (limited to 'src/librustc_plugin')
| -rw-r--r-- | src/librustc_plugin/build.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/librustc_plugin/build.rs b/src/librustc_plugin/build.rs index eca2736ee52..46c452668c3 100644 --- a/src/librustc_plugin/build.rs +++ b/src/librustc_plugin/build.rs @@ -2,11 +2,12 @@ use syntax::ast; use syntax::attr; -use errors; use syntax_pos::Span; -use rustc::hir::map::Map; use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir; +use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; +use rustc::ty::TyCtxt; +use rustc::ty::query::Providers; struct RegistrarFinder { registrars: Vec<(ast::NodeId, Span)> , @@ -30,21 +31,27 @@ impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { } /// Find the function marked with `#[plugin_registrar]`, if any. -pub fn find_plugin_registrar(diagnostic: &errors::Handler, - hir_map: &Map) - -> Option<ast::NodeId> { - let krate = hir_map.krate(); +pub fn find_plugin_registrar<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> Option<DefId> { + tcx.plugin_registrar_fn(LOCAL_CRATE) +} + +fn plugin_registrar_fn<'tcx>( + tcx: TyCtxt<'_, 'tcx, 'tcx>, + cnum: CrateNum, +) -> Option<DefId> { + assert_eq!(cnum, LOCAL_CRATE); let mut finder = RegistrarFinder { registrars: Vec::new() }; - krate.visit_all_item_likes(&mut finder); + tcx.hir().krate().visit_all_item_likes(&mut finder); match finder.registrars.len() { 0 => None, 1 => { let (node_id, _) = finder.registrars.pop().unwrap(); - Some(node_id) + Some(tcx.hir().local_def_id(node_id)) }, _ => { + let diagnostic = tcx.sess.diagnostic(); let mut e = diagnostic.struct_err("multiple plugin registration functions found"); for &(_, span) in &finder.registrars { e.span_note(span, "one is here"); @@ -55,3 +62,11 @@ pub fn find_plugin_registrar(diagnostic: &errors::Handler, } } } + + +pub fn provide(providers: &mut Providers<'_>) { + *providers = Providers { + plugin_registrar_fn, + ..*providers + }; +} |
