1 //! Used by plugin crates to tell `rustc` about the plugins they provide.
3 use rustc::lint::LintStore;
4 use rustc::session::Session;
8 use std::borrow::ToOwned;
10 /// Structure used to register plugins.
12 /// A plugin registrar function takes an `&mut Registry` and should call
13 /// methods to register its plugins.
15 /// This struct has public fields and other methods for use by `rustc`
16 /// itself. They are not documented here, and plugin authors should
18 pub struct Registry<'a> {
19 /// Compiler session. Useful if you want to emit diagnostic messages
20 /// from the plugin registrar.
21 pub sess: &'a Session,
23 /// The `LintStore` allows plugins to register new lints.
24 pub lint_store: &'a mut LintStore,
27 pub args_hidden: Option<Vec<ast::NestedMetaItem>>,
33 pub llvm_passes: Vec<String>,
36 impl<'a> Registry<'a> {
38 pub fn new(sess: &'a Session, lint_store: &'a mut LintStore, krate_span: Span) -> Registry<'a> {
48 /// Gets the plugin's arguments, if any.
50 /// These are specified inside the `plugin` crate attribute as
53 /// #![plugin(my_plugin_name(... args ...))]
56 /// Returns empty slice in case the plugin was loaded
57 /// with `--extra-plugins`
58 pub fn args(&self) -> &[ast::NestedMetaItem] {
59 self.args_hidden.as_ref().map(|v| &v[..]).unwrap_or(&[])
62 /// Register an LLVM pass.
64 /// Registration with LLVM itself is handled through static C++ objects with
65 /// constructors. This method simply adds a name to the list of passes to
67 pub fn register_llvm_pass(&mut self, name: &str) {
68 self.llvm_passes.push(name.to_owned());