diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:04 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:47 -0500 |
| commit | a06baa56b95674fc626b3c3fd680d6a65357fe60 (patch) | |
| tree | cd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/librustc_plugin_impl | |
| parent | 8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff) | |
| download | rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip | |
Format the world
Diffstat (limited to 'src/librustc_plugin_impl')
| -rw-r--r-- | src/librustc_plugin_impl/build.rs | 26 | ||||
| -rw-r--r-- | src/librustc_plugin_impl/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_plugin_impl/load.rs | 54 |
3 files changed, 37 insertions, 44 deletions
diff --git a/src/librustc_plugin_impl/build.rs b/src/librustc_plugin_impl/build.rs index 8ceef5a4b76..ea462b49651 100644 --- a/src/librustc_plugin_impl/build.rs +++ b/src/librustc_plugin_impl/build.rs @@ -1,16 +1,16 @@ //! Used by `rustc` when compiling a plugin crate. -use syntax::attr; -use syntax::symbol::sym; -use syntax_pos::Span; -use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; -use rustc::ty::TyCtxt; +use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::ty::query::Providers; +use rustc::ty::TyCtxt; +use syntax::attr; +use syntax::symbol::sym; +use syntax_pos::Span; struct RegistrarFinder { - registrars: Vec<(hir::HirId, Span)> , + registrars: Vec<(hir::HirId, Span)>, } impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { @@ -22,11 +22,9 @@ impl<'v> ItemLikeVisitor<'v> for RegistrarFinder { } } - fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) { - } + fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {} - fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) { - } + fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {} } /// Finds the function marked with `#[plugin_registrar]`, if any. @@ -45,7 +43,7 @@ fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> { 1 => { let (hir_id, _) = finder.registrars.pop().unwrap(); Some(tcx.hir().local_def_id(hir_id)) - }, + } _ => { let diagnostic = tcx.sess.diagnostic(); let mut e = diagnostic.struct_err("multiple plugin registration functions found"); @@ -59,10 +57,6 @@ fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> { } } - pub fn provide(providers: &mut Providers<'_>) { - *providers = Providers { - plugin_registrar_fn, - ..*providers - }; + *providers = Providers { plugin_registrar_fn, ..*providers }; } diff --git a/src/librustc_plugin_impl/lib.rs b/src/librustc_plugin_impl/lib.rs index 5c4ea39aecc..682d223f565 100644 --- a/src/librustc_plugin_impl/lib.rs +++ b/src/librustc_plugin_impl/lib.rs @@ -7,7 +7,6 @@ //! of the Unstable Book for some examples. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] - #![feature(nll)] use rustc::lint::LintStore; diff --git a/src/librustc_plugin_impl/load.rs b/src/librustc_plugin_impl/load.rs index 0bd91076592..7eeeed1e92b 100644 --- a/src/librustc_plugin_impl/load.rs +++ b/src/librustc_plugin_impl/load.rs @@ -1,9 +1,9 @@ //! Used by `rustc` when loading a plugin. +use crate::Registry; use rustc::middle::cstore::MetadataLoader; use rustc::session::Session; use rustc_metadata::locator; -use crate::Registry; use std::borrow::ToOwned; use std::env; @@ -26,9 +26,11 @@ fn call_malformed_plugin_attribute(sess: &Session, span: Span) { } /// Read plugin metadata and dynamically load registrar functions. -pub fn load_plugins(sess: &Session, - metadata_loader: &dyn MetadataLoader, - krate: &Crate) -> Vec<PluginRegistrarFn> { +pub fn load_plugins( + sess: &Session, + metadata_loader: &dyn MetadataLoader, + krate: &Crate, +) -> Vec<PluginRegistrarFn> { let mut plugins = Vec::new(); for attr in &krate.attrs { @@ -38,8 +40,9 @@ pub fn load_plugins(sess: &Session, for plugin in attr.meta_item_list().unwrap_or_default() { match plugin.ident() { - Some(ident) if plugin.is_word() => - load_plugin(&mut plugins, sess, metadata_loader, ident), + Some(ident) if plugin.is_word() => { + load_plugin(&mut plugins, sess, metadata_loader, ident) + } _ => call_malformed_plugin_attribute(sess, plugin.span()), } } @@ -48,10 +51,12 @@ pub fn load_plugins(sess: &Session, plugins } -fn load_plugin(plugins: &mut Vec<PluginRegistrarFn>, - sess: &Session, - metadata_loader: &dyn MetadataLoader, - ident: Ident) { +fn load_plugin( + plugins: &mut Vec<PluginRegistrarFn>, + sess: &Session, + metadata_loader: &dyn MetadataLoader, + ident: Ident, +) { let registrar = locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name); if let Some((lib, disambiguator)) = registrar { @@ -62,10 +67,12 @@ fn load_plugin(plugins: &mut Vec<PluginRegistrarFn>, } // 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, + symbol: String, +) -> PluginRegistrarFn { use rustc_metadata::dynamic_lib::DynamicLibrary; // Make sure the path contains a / or the linker will search for it. @@ -76,22 +83,15 @@ fn dylink_registrar(sess: &Session, // this is fatal: there are almost certainly macros we need // inside this crate, so continue would spew "macro undefined" // errors - Err(err) => { - sess.span_fatal(span, &err) - } + Err(err) => sess.span_fatal(span, &err), }; unsafe { - let registrar = - match lib.symbol(&symbol) { - Ok(registrar) => { - mem::transmute::<*mut u8, PluginRegistrarFn>(registrar) - } - // again fatal if we can't register macros - Err(err) => { - sess.span_fatal(span, &err) - } - }; + let registrar = match lib.symbol(&symbol) { + Ok(registrar) => mem::transmute::<*mut u8, PluginRegistrarFn>(registrar), + // again fatal if we can't register macros + Err(err) => sess.span_fatal(span, &err), + }; // Intentionally leak the dynamic library. We can't ever unload it // since the library can make things that will live arbitrarily long |
