1 //! Infrastructure for compiler plugins.
3 //! Plugins are Rust libraries which extend the behavior of `rustc`
6 //! Plugin authors will use the `Registry` type re-exported by
7 //! this module, along with its methods. The rest of the module
8 //! is for use by `rustc` itself.
10 //! To define a plugin, build a dylib crate with a
11 //! `#[plugin_registrar]` function:
14 //! #![crate_name = "myplugin"]
15 //! #![crate_type = "dylib"]
16 //! #![feature(plugin_registrar)]
17 //! #![feature(rustc_private)]
19 //! extern crate rustc_plugin;
20 //! extern crate rustc_driver;
21 //! extern crate syntax;
22 //! extern crate syntax_pos;
24 //! use rustc_plugin::Registry;
25 //! use syntax::ext::base::{ExtCtxt, MacResult};
26 //! use syntax_pos::Span;
27 //! use syntax::tokenstream::TokenTree;
29 //! #[plugin_registrar]
30 //! pub fn plugin_registrar(reg: &mut Registry) {
31 //! reg.register_macro("mymacro", expand_mymacro);
34 //! fn expand_mymacro(cx: &mut ExtCtxt, span: Span, tt: &[TokenTree]) -> Box<MacResult> {
41 //! WARNING: We currently don't check that the registrar function
42 //! has the appropriate type!
44 //! To use a plugin while compiling another crate:
47 //! #![feature(plugin)]
48 //! #![plugin(myplugin)]
52 //! feature](https://doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html)
53 //! of the Unstable Book for more examples.
55 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
58 #![feature(rustc_diagnostic_macros)]
60 #![recursion_limit="256"]
62 pub use registry::Registry;
69 __build_diagnostic_array! { librustc_plugin, DIAGNOSTICS }