]> git.proxmox.com Git - rustc.git/blame - src/librustc_plugin/lib.rs
New upstream version 1.26.0+dfsg1
[rustc.git] / src / librustc_plugin / lib.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! Infrastructure for compiler plugins.
12//!
13//! Plugins are Rust libraries which extend the behavior of `rustc`
14//! in various ways.
15//!
16//! Plugin authors will use the `Registry` type re-exported by
17//! this module, along with its methods. The rest of the module
18//! is for use by `rustc` itself.
19//!
20//! To define a plugin, build a dylib crate with a
21//! `#[plugin_registrar]` function:
22//!
041b39d2 23//! ```no_run
1a4d82fc
JJ
24//! #![crate_name = "myplugin"]
25//! #![crate_type = "dylib"]
26//! #![feature(plugin_registrar)]
041b39d2 27//! #![feature(rustc_private)]
1a4d82fc 28//!
041b39d2
XL
29//! extern crate rustc_plugin;
30//! extern crate syntax;
31//! extern crate syntax_pos;
1a4d82fc 32//!
9e0c209e 33//! use rustc_plugin::Registry;
041b39d2
XL
34//! use syntax::ext::base::{ExtCtxt, MacResult};
35//! use syntax_pos::Span;
36//! use syntax::tokenstream::TokenTree;
1a4d82fc
JJ
37//!
38//! #[plugin_registrar]
39//! pub fn plugin_registrar(reg: &mut Registry) {
40//! reg.register_macro("mymacro", expand_mymacro);
41//! }
42//!
041b39d2
XL
43//! fn expand_mymacro(cx: &mut ExtCtxt, span: Span, tt: &[TokenTree]) -> Box<MacResult> {
44//! unimplemented!()
45//! }
46//!
47//! # fn main() {}
1a4d82fc
JJ
48//! ```
49//!
50//! WARNING: We currently don't check that the registrar function
51//! has the appropriate type!
52//!
53//! To use a plugin while compiling another crate:
54//!
55//! ```rust
56//! #![feature(plugin)]
85aaf69f 57//! #![plugin(myplugin)]
1a4d82fc
JJ
58//! ```
59//!
ff7c6d11 60//! See the [`plugin` feature](../unstable-book/language-features/plugin.html) of
041b39d2 61//! the Unstable Book for more examples.
1a4d82fc 62
92a42be0 63#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
7453a54e
SL
64 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
65 html_root_url = "https://doc.rust-lang.org/nightly/")]
32a655c1 66#![deny(warnings)]
92a42be0 67
92a42be0 68#![feature(rustc_diagnostic_macros)]
3b2f2976 69#![feature(staged_api)]
7cac9316 70
92a42be0 71#[macro_use] extern crate syntax;
92a42be0
SL
72
73extern crate rustc;
92a42be0 74extern crate rustc_metadata;
3157f602
XL
75extern crate syntax_pos;
76extern crate rustc_errors as errors;
92a42be0 77
1a4d82fc
JJ
78pub use self::registry::Registry;
79
3b2f2976 80mod diagnostics;
1a4d82fc
JJ
81pub mod registry;
82pub mod load;
83pub mod build;
3b2f2976
XL
84
85__build_diagnostic_array! { librustc_plugin, DIAGNOSTICS }