Use a crate attribute to load plugins

#[plugin] #[no_link] extern crate bleh;

becomes a crate attribute

    #![plugin(bleh)]

The feature gate is still required.

It's almost never correct to link a plugin into the resulting library /
executable, because it will bring all of libsyntax and librustc with it.
However if you really want this behavior, you can get it with a separate
`extern crate` item in addition to the `plugin` attribute.

Fixes #21043.
Fixes #20769.

[breaking-change]
This commit is contained in:
Keegan McAllister 2015-02-06 13:56:38 -08:00
parent 0ba9e1fa52
commit 93b642d974
37 changed files with 152 additions and 165 deletions

View file

@ -2014,6 +2014,11 @@ type int8_t = i8;
- `no_start` - disable linking to the `native` crate, which specifies the
"start" language item.
- `no_std` - disable linking to the `std` crate.
- `plugin` — load a list of named crates as compiler plugins, e.g.
`#![plugin(foo, bar)]`. Optional arguments for each plugin,
i.e. `#![plugin(foo(... args ...))]`, are provided to the plugin's
registrar function. The `plugin` feature gate is required to use
this attribute.
### Module-only attributes
@ -2082,7 +2087,7 @@ On `struct`s:
remove any padding between fields (note that this is very fragile and may
break platforms which require aligned access).
### Macro- and plugin-related attributes
### Macro-related attributes
- `macro_use` on a `mod` — macros defined in this module will be visible in the
module's parent, after this module has been included.
@ -2097,13 +2102,8 @@ On `struct`s:
- `macro_export` - export a macro for cross-crate usage.
- `plugin` on an `extern crate` — load this crate as a [compiler
plugin][plugin]. The `plugin` feature gate is required. Any arguments to
the attribute, e.g. `#[plugin=...]` or `#[plugin(...)]`, are provided to the
plugin.
- `no_link` on an `extern crate` — even if we load this crate for macros or
compiler plugins, don't link it into the output.
- `no_link` on an `extern crate` — even if we load this crate for macros, don't
link it into the output.
See the [macros section of the
book](book/macros.html#scoping-and-macro-import/export) for more information on

View file

@ -30,14 +30,14 @@ information.
extend the compiler's behavior with new syntax extensions, lint checks, etc.
A plugin is a dynamic library crate with a designated *registrar* function that
registers extensions with `rustc`. Other crates can use these extensions by
loading the plugin crate with `#[plugin] extern crate`. See the
registers extensions with `rustc`. Other crates can load these extensions using
the crate attribute `#![plugin(...)]`. See the
[`rustc::plugin`](../rustc/plugin/index.html) documentation for more about the
mechanics of defining and loading a plugin.
Arguments passed as `#[plugin=...]` or `#[plugin(...)]` are not interpreted by
rustc itself. They are provided to the plugin through the `Registry`'s [`args`
method](../rustc/plugin/registry/struct.Registry.html#method.args).
If present, arguments passed as `#![plugin(foo(... args ...))]` are not
interpreted by rustc itself. They are provided to the plugin through the
`Registry`'s [`args` method](../rustc/plugin/registry/struct.Registry.html#method.args).
# Syntax extensions
@ -110,8 +110,7 @@ Then we can use `rn!()` like any other macro:
```ignore
#![feature(plugin)]
#[plugin] extern crate roman_numerals;
#![plugin(roman_numerals)]
fn main() {
assert_eq!(rn!(MMXV), 2015);
@ -219,7 +218,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
Then code like
```ignore
#[plugin] extern crate lint_plugin_test;
#![plugin(lint_plugin_test)]
fn lintme() { }
```