2014-11-25 21:17:11 -05:00
|
|
|
//! Infrastructure for compiler plugins.
|
|
|
|
//!
|
|
|
|
//! Plugins are Rust libraries which extend the behavior of `rustc`
|
|
|
|
//! in various ways.
|
|
|
|
//!
|
|
|
|
//! Plugin authors will use the `Registry` type re-exported by
|
|
|
|
//! this module, along with its methods. The rest of the module
|
|
|
|
//! is for use by `rustc` itself.
|
|
|
|
//!
|
|
|
|
//! To define a plugin, build a dylib crate with a
|
|
|
|
//! `#[plugin_registrar]` function:
|
|
|
|
//!
|
2017-06-20 15:15:16 +08:00
|
|
|
//! ```no_run
|
2014-11-25 21:17:11 -05:00
|
|
|
//! #![crate_name = "myplugin"]
|
|
|
|
//! #![crate_type = "dylib"]
|
|
|
|
//! #![feature(plugin_registrar)]
|
2017-06-20 15:15:16 +08:00
|
|
|
//! #![feature(rustc_private)]
|
2014-11-25 21:17:11 -05:00
|
|
|
//!
|
2017-06-20 15:15:16 +08:00
|
|
|
//! extern crate rustc_plugin;
|
|
|
|
//! extern crate syntax;
|
|
|
|
//! extern crate syntax_pos;
|
2014-11-25 21:17:11 -05:00
|
|
|
//!
|
2016-08-31 22:45:05 +08:00
|
|
|
//! use rustc_plugin::Registry;
|
2017-06-20 15:15:16 +08:00
|
|
|
//! use syntax::ext::base::{ExtCtxt, MacResult};
|
|
|
|
//! use syntax_pos::Span;
|
|
|
|
//! use syntax::tokenstream::TokenTree;
|
2014-11-25 21:17:11 -05:00
|
|
|
//!
|
|
|
|
//! #[plugin_registrar]
|
|
|
|
//! pub fn plugin_registrar(reg: &mut Registry) {
|
|
|
|
//! reg.register_macro("mymacro", expand_mymacro);
|
|
|
|
//! }
|
|
|
|
//!
|
2017-06-20 15:15:16 +08:00
|
|
|
//! fn expand_mymacro(cx: &mut ExtCtxt, span: Span, tt: &[TokenTree]) -> Box<MacResult> {
|
|
|
|
//! unimplemented!()
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! # fn main() {}
|
2014-11-25 21:17:11 -05:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! WARNING: We currently don't check that the registrar function
|
|
|
|
//! has the appropriate type!
|
|
|
|
//!
|
|
|
|
//! To use a plugin while compiling another crate:
|
|
|
|
//!
|
|
|
|
//! ```rust
|
2014-12-31 20:43:46 -08:00
|
|
|
//! #![feature(plugin)]
|
2015-02-06 13:56:38 -08:00
|
|
|
//! #![plugin(myplugin)]
|
2014-11-25 21:17:11 -05:00
|
|
|
//! ```
|
|
|
|
//!
|
2017-12-31 17:08:04 +01:00
|
|
|
//! See the [`plugin` feature](../unstable-book/language-features/plugin.html) of
|
2017-06-13 01:30:08 +09:00
|
|
|
//! the Unstable Book for more examples.
|
2014-05-26 14:48:54 -07:00
|
|
|
|
2019-02-05 14:37:15 +01:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
|
2015-11-22 22:14:09 +02:00
|
|
|
|
|
|
|
#![feature(rustc_diagnostic_macros)]
|
2017-05-08 14:36:44 -07:00
|
|
|
|
2018-12-13 16:57:25 +01:00
|
|
|
#![recursion_limit="256"]
|
|
|
|
|
2019-02-06 23:56:39 +09:00
|
|
|
#![deny(rust_2018_idioms)]
|
2015-11-22 22:14:09 +02:00
|
|
|
|
2019-02-06 23:56:39 +09:00
|
|
|
pub use registry::Registry;
|
2014-05-26 14:48:54 -07:00
|
|
|
|
2017-08-19 03:09:55 +03:00
|
|
|
mod diagnostics;
|
2014-05-26 14:48:54 -07:00
|
|
|
pub mod registry;
|
|
|
|
pub mod load;
|
|
|
|
pub mod build;
|
2017-07-30 23:22:09 -07:00
|
|
|
|
|
|
|
__build_diagnostic_array! { librustc_plugin, DIAGNOSTICS }
|