diff options
Diffstat (limited to 'compiler/rustc_plugin_impl')
| -rw-r--r-- | compiler/rustc_plugin_impl/Cargo.toml | 18 | ||||
| -rw-r--r-- | compiler/rustc_plugin_impl/messages.ftl | 4 | ||||
| -rw-r--r-- | compiler/rustc_plugin_impl/src/errors.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_plugin_impl/src/lib.rs | 33 | ||||
| -rw-r--r-- | compiler/rustc_plugin_impl/src/load.rs | 78 |
5 files changed, 0 insertions, 153 deletions
diff --git a/compiler/rustc_plugin_impl/Cargo.toml b/compiler/rustc_plugin_impl/Cargo.toml deleted file mode 100644 index a0762e815e3..00000000000 --- a/compiler/rustc_plugin_impl/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "rustc_plugin_impl" -version = "0.0.0" -build = false -edition = "2021" - -[dependencies] -# tidy-alphabetical-start -libloading = "0.7.1" -rustc_ast = { path = "../rustc_ast" } -rustc_errors = { path = "../rustc_errors" } -rustc_fluent_macro = { path = "../rustc_fluent_macro" } -rustc_lint = { path = "../rustc_lint" } -rustc_macros = { path = "../rustc_macros" } -rustc_metadata = { path = "../rustc_metadata" } -rustc_session = { path = "../rustc_session" } -rustc_span = { path = "../rustc_span" } -# tidy-alphabetical-end diff --git a/compiler/rustc_plugin_impl/messages.ftl b/compiler/rustc_plugin_impl/messages.ftl deleted file mode 100644 index 8db32a42c1d..00000000000 --- a/compiler/rustc_plugin_impl/messages.ftl +++ /dev/null @@ -1,4 +0,0 @@ -plugin_impl_load_plugin_error = {$msg} - -plugin_impl_malformed_plugin_attribute = malformed `plugin` attribute - .label = malformed attribute diff --git a/compiler/rustc_plugin_impl/src/errors.rs b/compiler/rustc_plugin_impl/src/errors.rs deleted file mode 100644 index e6a7fc86bee..00000000000 --- a/compiler/rustc_plugin_impl/src/errors.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! Errors emitted by plugin_impl - -use rustc_macros::Diagnostic; -use rustc_span::Span; - -#[derive(Diagnostic)] -#[diag(plugin_impl_load_plugin_error)] -pub struct LoadPluginError { - #[primary_span] - pub span: Span, - pub msg: String, -} - -#[derive(Diagnostic)] -#[diag(plugin_impl_malformed_plugin_attribute, code = "E0498")] -pub struct MalformedPluginAttribute { - #[primary_span] - #[label] - pub span: Span, -} diff --git a/compiler/rustc_plugin_impl/src/lib.rs b/compiler/rustc_plugin_impl/src/lib.rs deleted file mode 100644 index 0e1c80a1f64..00000000000 --- a/compiler/rustc_plugin_impl/src/lib.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! Infrastructure for compiler plugins. -//! -//! Plugins are a deprecated way to extend the behavior of `rustc` in various ways. -//! -//! See the [`plugin` -//! feature](https://doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html) -//! of the Unstable Book for some examples. - -#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![cfg_attr(not(bootstrap), doc(rust_logo))] -#![cfg_attr(not(bootstrap), feature(rustdoc_internals))] -#![cfg_attr(not(bootstrap), allow(internal_features))] -#![recursion_limit = "256"] -#![deny(rustc::untranslatable_diagnostic)] -#![deny(rustc::diagnostic_outside_of_impl)] - -use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_fluent_macro::fluent_messages; -use rustc_lint::LintStore; - -mod errors; -pub mod load; - -fluent_messages! { "../messages.ftl" } - -/// Structure used to register plugins. -/// -/// A plugin registrar function takes an `&mut Registry` and should call -/// methods to register its plugins. -pub struct Registry<'a> { - /// The `LintStore` allows plugins to register new lints. - pub lint_store: &'a mut LintStore, -} diff --git a/compiler/rustc_plugin_impl/src/load.rs b/compiler/rustc_plugin_impl/src/load.rs deleted file mode 100644 index 27e5cb9f0d0..00000000000 --- a/compiler/rustc_plugin_impl/src/load.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! Used by `rustc` when loading a plugin. - -use crate::errors::{LoadPluginError, MalformedPluginAttribute}; -use crate::Registry; -use libloading::Library; -use rustc_ast::Attribute; -use rustc_metadata::locator; -use rustc_session::cstore::MetadataLoader; -use rustc_session::Session; -use rustc_span::symbol::{sym, Ident}; - -use std::env; -use std::mem; -use std::path::PathBuf; - -/// Pointer to a registrar function. -type PluginRegistrarFn = fn(&mut Registry<'_>); - -/// Read plugin metadata and dynamically load registrar functions. -pub fn load_plugins( - sess: &Session, - metadata_loader: &dyn MetadataLoader, - attrs: &[Attribute], -) -> Vec<PluginRegistrarFn> { - let mut plugins = Vec::new(); - - for attr in attrs { - if !attr.has_name(sym::plugin) { - continue; - } - - 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) - } - _ => { - sess.emit_err(MalformedPluginAttribute { span: plugin.span() }); - } - } - } - } - - plugins -} - -fn load_plugin( - plugins: &mut Vec<PluginRegistrarFn>, - sess: &Session, - metadata_loader: &dyn MetadataLoader, - ident: Ident, -) { - let lib = locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name); - let fun = dylink_registrar(lib).unwrap_or_else(|err| { - // This is fatal: there are almost certainly macros we need inside this crate, so - // continuing would spew "macro undefined" errors. - sess.emit_fatal(LoadPluginError { span: ident.span, msg: err.to_string() }); - }); - plugins.push(fun); -} - -/// Dynamically link a registrar function into the compiler process. -fn dylink_registrar(lib_path: PathBuf) -> Result<PluginRegistrarFn, libloading::Error> { - // Make sure the path contains a / or the linker will search for it. - let lib_path = env::current_dir().unwrap().join(&lib_path); - - let lib = unsafe { Library::new(&lib_path) }?; - - let registrar_sym = unsafe { lib.get::<PluginRegistrarFn>(b"__rustc_plugin_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 Rc cycle or a thread). - let registrar_sym = unsafe { registrar_sym.into_raw() }; - mem::forget(lib); - - Ok(*registrar_sym) -} |
