2014-05-26 16:48:54 -05:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-11-25 20:17:11 -06: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 02:15:16 -05:00
|
|
|
//! ```no_run
|
2014-11-25 20:17:11 -06:00
|
|
|
//! #![crate_name = "myplugin"]
|
|
|
|
//! #![crate_type = "dylib"]
|
|
|
|
//! #![feature(plugin_registrar)]
|
2017-06-20 02:15:16 -05:00
|
|
|
//! #![feature(rustc_private)]
|
2014-11-25 20:17:11 -06:00
|
|
|
//!
|
2017-06-20 02:15:16 -05:00
|
|
|
//! extern crate rustc_plugin;
|
|
|
|
//! extern crate syntax;
|
|
|
|
//! extern crate syntax_pos;
|
2014-11-25 20:17:11 -06:00
|
|
|
//!
|
2016-08-31 09:45:05 -05:00
|
|
|
//! use rustc_plugin::Registry;
|
2017-06-20 02:15:16 -05:00
|
|
|
//! use syntax::ext::base::{ExtCtxt, MacResult};
|
|
|
|
//! use syntax_pos::Span;
|
|
|
|
//! use syntax::tokenstream::TokenTree;
|
2014-11-25 20:17:11 -06:00
|
|
|
//!
|
|
|
|
//! #[plugin_registrar]
|
|
|
|
//! pub fn plugin_registrar(reg: &mut Registry) {
|
|
|
|
//! reg.register_macro("mymacro", expand_mymacro);
|
|
|
|
//! }
|
|
|
|
//!
|
2017-06-20 02:15:16 -05:00
|
|
|
//! fn expand_mymacro(cx: &mut ExtCtxt, span: Span, tt: &[TokenTree]) -> Box<MacResult> {
|
|
|
|
//! unimplemented!()
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! # fn main() {}
|
2014-11-25 20:17:11 -06: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 22:43:46 -06:00
|
|
|
//! #![feature(plugin)]
|
2015-02-06 15:56:38 -06:00
|
|
|
//! #![plugin(myplugin)]
|
2014-11-25 20:17:11 -06:00
|
|
|
//! ```
|
|
|
|
//!
|
2017-12-31 10:08:04 -06:00
|
|
|
//! See the [`plugin` feature](../unstable-book/language-features/plugin.html) of
|
2017-06-12 11:30:08 -05:00
|
|
|
//! the Unstable Book for more examples.
|
2014-05-26 16:48:54 -05:00
|
|
|
|
2015-11-22 14:14:09 -06:00
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2016-01-21 17:26:19 -06:00
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/")]
|
2016-12-29 11:47:34 -06:00
|
|
|
#![deny(warnings)]
|
2015-11-22 14:14:09 -06:00
|
|
|
|
|
|
|
#![feature(rustc_diagnostic_macros)]
|
2017-08-21 05:46:36 -05:00
|
|
|
#![feature(staged_api)]
|
2017-05-08 16:36:44 -05:00
|
|
|
|
2015-11-22 14:14:09 -06:00
|
|
|
#[macro_use] extern crate syntax;
|
|
|
|
|
|
|
|
extern crate rustc;
|
2015-11-24 16:00:26 -06:00
|
|
|
extern crate rustc_metadata;
|
2016-06-21 17:08:13 -05:00
|
|
|
extern crate syntax_pos;
|
|
|
|
extern crate rustc_errors as errors;
|
2015-11-22 14:14:09 -06:00
|
|
|
|
2014-05-26 16:48:54 -05:00
|
|
|
pub use self::registry::Registry;
|
|
|
|
|
2017-08-18 19:09:55 -05:00
|
|
|
mod diagnostics;
|
2014-05-26 16:48:54 -05:00
|
|
|
pub mod registry;
|
|
|
|
pub mod load;
|
|
|
|
pub mod build;
|
2017-07-31 01:22:09 -05:00
|
|
|
|
|
|
|
__build_diagnostic_array! { librustc_plugin, DIAGNOSTICS }
|