diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-05-14 15:37:53 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2021-08-10 14:20:48 +0200 |
| commit | a501308ec1601c2b1d50230a061fb2700940727d (patch) | |
| tree | 4c382ec2525a497a8ed11c6097d85dd8870e70c0 /compiler/rustc_plugin_impl/src | |
| parent | 2d10c2a3302d53e10a4ad3ac581103faaae9eeb6 (diff) | |
| download | rust-a501308ec1601c2b1d50230a061fb2700940727d.tar.gz rust-a501308ec1601c2b1d50230a061fb2700940727d.zip | |
Replace #[plugin_registrar] with exporting __rustc_plugin_registrar
Diffstat (limited to 'compiler/rustc_plugin_impl/src')
| -rw-r--r-- | compiler/rustc_plugin_impl/src/build.rs | 57 | ||||
| -rw-r--r-- | compiler/rustc_plugin_impl/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_plugin_impl/src/load.rs | 17 |
3 files changed, 5 insertions, 70 deletions
diff --git a/compiler/rustc_plugin_impl/src/build.rs b/compiler/rustc_plugin_impl/src/build.rs deleted file mode 100644 index b95c4a72019..00000000000 --- a/compiler/rustc_plugin_impl/src/build.rs +++ /dev/null @@ -1,57 +0,0 @@ -//! Used by `rustc` when compiling a plugin crate. - -use rustc_hir as hir; -use rustc_hir::def_id::LocalDefId; -use rustc_hir::itemlikevisit::ItemLikeVisitor; -use rustc_middle::ty::query::Providers; -use rustc_middle::ty::TyCtxt; -use rustc_span::symbol::sym; -use rustc_span::Span; - -struct RegistrarFinder<'tcx> { - tcx: TyCtxt<'tcx>, - registrars: Vec<(LocalDefId, Span)>, -} - -impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> { - fn visit_item(&mut self, item: &hir::Item<'_>) { - if let hir::ItemKind::Fn(..) = item.kind { - let attrs = self.tcx.hir().attrs(item.hir_id()); - if self.tcx.sess.contains_name(attrs, sym::plugin_registrar) { - self.registrars.push((item.def_id, item.span)); - } - } - } - - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {} - - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {} - - fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {} -} - -/// Finds the function marked with `#[plugin_registrar]`, if any. -fn plugin_registrar_fn(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> { - let mut finder = RegistrarFinder { tcx, registrars: Vec::new() }; - tcx.hir().krate().visit_all_item_likes(&mut finder); - - let (def_id, span) = finder.registrars.pop()?; - - if !finder.registrars.is_empty() { - let diagnostic = tcx.sess.diagnostic(); - let mut e = diagnostic.struct_err("multiple plugin registration functions found"); - e.span_note(span, "one is here"); - for &(_, span) in &finder.registrars { - e.span_note(span, "one is here"); - } - e.emit(); - diagnostic.abort_if_errors(); - unreachable!(); - } - - Some(def_id) -} - -pub fn provide(providers: &mut Providers) { - *providers = Providers { plugin_registrar_fn, ..*providers }; -} diff --git a/compiler/rustc_plugin_impl/src/lib.rs b/compiler/rustc_plugin_impl/src/lib.rs index 5bf4d300e9e..a1e13a1abb6 100644 --- a/compiler/rustc_plugin_impl/src/lib.rs +++ b/compiler/rustc_plugin_impl/src/lib.rs @@ -12,7 +12,6 @@ use rustc_lint::LintStore; -pub mod build; pub mod load; /// Structure used to register plugins. diff --git a/compiler/rustc_plugin_impl/src/load.rs b/compiler/rustc_plugin_impl/src/load.rs index 687f7db221f..5da02e3a489 100644 --- a/compiler/rustc_plugin_impl/src/load.rs +++ b/compiler/rustc_plugin_impl/src/load.rs @@ -55,20 +55,13 @@ fn load_plugin( metadata_loader: &dyn MetadataLoader, ident: Ident, ) { - let (lib, disambiguator) = - locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name); - let symbol = sess.generate_plugin_registrar_symbol(disambiguator); - let fun = dylink_registrar(sess, ident.span, lib, symbol); + let lib = locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name); + let fun = dylink_registrar(sess, ident.span, lib); plugins.push(fun); } // Dynamically link a registrar function into the compiler process. -fn dylink_registrar( - sess: &Session, - span: Span, - path: PathBuf, - symbol: String, -) -> PluginRegistrarFn { +fn dylink_registrar(sess: &Session, span: Span, path: PathBuf) -> PluginRegistrarFn { use rustc_metadata::dynamic_lib::DynamicLibrary; // Make sure the path contains a / or the linker will search for it. @@ -83,7 +76,7 @@ fn dylink_registrar( }; unsafe { - let registrar = match lib.symbol(&symbol) { + let registrar = match lib.symbol("__rustc_plugin_registrar") { Ok(registrar) => mem::transmute::<*mut u8, PluginRegistrarFn>(registrar), // again fatal if we can't register macros Err(err) => sess.span_fatal(span, &err), @@ -91,7 +84,7 @@ fn dylink_registrar( // Intentionally leak the dynamic library. We can't ever unload it // since the library can make things that will live arbitrarily long - // (e.g., an @-box cycle or a thread). + // (e.g., an Rc cycle or a thread). mem::forget(lib); registrar |
