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

@ -27,7 +27,7 @@ use syntax::ptr::P;
use rustc::plugin::Registry;
struct Expander {
args: P<ast::MetaItem>,
args: Vec<P<ast::MetaItem>>,
}
impl TTMacroExpander for Expander {
@ -35,10 +35,9 @@ impl TTMacroExpander for Expander {
ecx: &'cx mut ExtCtxt,
sp: Span,
_: &[ast::TokenTree]) -> Box<MacResult+'cx> {
let attr = ecx.attribute(sp, self.args.clone());
let src = pprust::attribute_to_string(&attr);
let interned = token::intern_and_get_ident(&src);
let args = self.args.iter().map(|i| pprust::meta_item_to_string(&*i))
.collect::<Vec<_>>().connect(", ");
let interned = token::intern_and_get_ident(&args[]);
MacExpr::new(ecx.expr_str(sp, interned))
}
}

View file

@ -13,7 +13,7 @@
#![crate_type = "dylib"]
#![feature(plugin_registrar, quote)]
extern crate "syntax-extension-with-dll-deps-1" as other;
extern crate "syntax_extension_with_dll_deps_1" as other;
extern crate syntax;
extern crate rustc;

View file

@ -11,7 +11,7 @@
// aux-build:macro_crate_test.rs
// ignore-stage1
#[plugin] #[no_link] extern crate macro_crate_test;
#![plugin(macro_crate_test)]
//~^ ERROR compiler plugins are experimental and possibly buggy
fn main() {}

View file

@ -13,9 +13,7 @@
// compile-flags: -D lint-me
#![feature(plugin)]
#[plugin] #[no_link]
extern crate lint_group_plugin_test;
#![plugin(lint_group_plugin_test)]
fn lintme() { } //~ ERROR item is named 'lintme'

View file

@ -12,11 +12,9 @@
// ignore-stage1
#![feature(plugin)]
#![plugin(lint_plugin_test)]
#![deny(test_lint)]
#[plugin] #[no_link]
extern crate lint_plugin_test;
fn lintme() { } //~ ERROR item is named 'lintme'
pub fn main() {

View file

@ -13,9 +13,7 @@
// compile-flags: -D test-lint
#![feature(plugin)]
#[plugin] #[no_link]
extern crate lint_plugin_test;
#![plugin(lint_plugin_test)]
fn lintme() { } //~ ERROR item is named 'lintme'

View file

@ -12,11 +12,9 @@
// ignore-stage1
#![feature(plugin)]
#![plugin(lint_plugin_test)]
#![forbid(test_lint)]
#[plugin] #[no_link]
extern crate lint_plugin_test;
fn lintme() { } //~ ERROR item is named 'lintme'
#[allow(test_lint)] //~ ERROR allow(test_lint) overruled by outer forbid(test_lint)

View file

@ -13,9 +13,7 @@
// compile-flags: -F test-lint
#![feature(plugin)]
#[plugin] #[no_link]
extern crate lint_plugin_test;
#![plugin(lint_plugin_test)]
fn lintme() { } //~ ERROR item is named 'lintme'

View file

@ -21,9 +21,7 @@
// ident form.
#![feature(plugin)]
#[plugin] #[no_link]
extern crate macro_crate_test;
#![plugin(macro_crate_test)]
fn main() {
let x = 0;

View file

@ -15,7 +15,7 @@
// ignore-cross-compile gives a different error message
#![feature(plugin)]
#[plugin] #[no_link] extern crate rlib_crate_test;
#![plugin(rlib_crate_test)]
//~^ ERROR: plugin crate `rlib_crate_test` only found in rlib format, but must be available in dylib format
fn main() {}

View file

@ -14,8 +14,6 @@
// error-pattern: plugin tried to register a new MacroRulesTT
#![feature(plugin)]
#[plugin] #[no_link]
extern crate macro_crate_MacroRulesTT;
#![plugin(macro_crate_MacroRulesTT)]
fn main() { }

View file

@ -8,15 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:plugin_args.rs
// ignore-stage1
#![plugin] //~ ERROR malformed plugin attribute
#![feature(plugin)]
#[no_link]
#[plugin="foobar"]
extern crate plugin_args;
fn main() {
assert_eq!(plugin_args!(), "#[plugin = \"foobar\"]");
}
fn main() {}

View file

@ -0,0 +1,13 @@
// Copyright 2015 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.
#![plugin="bleh"] //~ ERROR malformed plugin attribute
fn main() {}

View file

@ -0,0 +1,13 @@
// Copyright 2015 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.
#![plugin(foo="bleh")] //~ ERROR malformed plugin attribute
fn main() {}

View file

@ -8,8 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[plugin]
#[plugin] //~ ERROR #[plugin] specified multiple times
#[plugin] //~ ERROR #[plugin] on `extern crate` is deprecated
extern crate std;
fn main() {}

View file

@ -12,8 +12,7 @@
// ignore-android
// aux-build:issue_16723_multiple_items_syntax_ext.rs
#![feature(plugin)]
#[plugin] #[no_link] extern crate issue_16723_multiple_items_syntax_ext;
#![plugin(issue_16723_multiple_items_syntax_ext)]
multiple_items!();

View file

@ -13,9 +13,7 @@
// ignore-pretty
#![feature(plugin)]
#[plugin] #[no_link]
extern crate lint_group_plugin_test;
#![plugin(lint_group_plugin_test)]
fn lintme() { } //~ WARNING item is named 'lintme'
fn pleaselintme() { } //~ WARNING item is named 'pleaselintme'

View file

@ -13,9 +13,7 @@
// compile-flags: -A test-lint
#![feature(plugin)]
#[plugin] #[no_link]
extern crate lint_plugin_test;
#![plugin(lint_plugin_test)]
fn lintme() { }

View file

@ -13,9 +13,7 @@
// ignore-pretty
#![feature(plugin)]
#[plugin] #[no_link]
extern crate lint_plugin_test;
#![plugin(lint_plugin_test)]
fn lintme() { } //~ WARNING item is named 'lintme'

View file

@ -15,9 +15,7 @@
// uses `quote_expr!` to rearrange it should be hygiene-preserving.
#![feature(plugin)]
#[plugin] #[no_link]
extern crate macro_crate_test;
#![plugin(macro_crate_test)]
fn main() {
let x = 3;

View file

@ -12,8 +12,6 @@
// ignore-stage1
#![feature(plugin)]
#[plugin] #[no_link]
extern crate plugin_crate_outlive_expansion_phase;
#![plugin(plugin_crate_outlive_expansion_phase)]
pub fn main() {}

View file

@ -12,8 +12,9 @@
// ignore-stage1
#![feature(plugin)]
#![plugin(macro_crate_test)]
#[macro_use] #[plugin] #[no_link]
#[macro_use] #[no_link]
extern crate macro_crate_test;
#[into_foo]

View file

@ -12,11 +12,8 @@
// ignore-stage1
#![feature(plugin)]
#[no_link]
#[plugin]
extern crate plugin_args;
#![plugin(plugin_args)]
fn main() {
assert_eq!(plugin_args!(), "#[plugin]");
assert_eq!(plugin_args!(), "");
}

View file

@ -12,11 +12,8 @@
// ignore-stage1
#![feature(plugin)]
#[no_link]
#[plugin()]
extern crate plugin_args;
#![plugin(plugin_args())]
fn main() {
assert_eq!(plugin_args!(), "#[plugin()]");
assert_eq!(plugin_args!(), "");
}

View file

@ -12,11 +12,8 @@
// ignore-stage1
#![feature(plugin)]
#[no_link]
#[plugin(hello(there), how(are="you"))]
extern crate plugin_args;
#![plugin(plugin_args(hello(there), how(are="you")))]
fn main() {
assert_eq!(plugin_args!(), "#[plugin(hello(there), how(are = \"you\"))]");
assert_eq!(plugin_args!(), "hello(there), how(are = \"you\")");
}

View file

@ -1,4 +1,4 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -16,8 +16,8 @@
// libsyntax is not compiled for it.
#![feature(plugin)]
#![plugin(macro_crate_test)]
#[plugin]
extern crate macro_crate_test;
fn main() {

View file

@ -12,9 +12,7 @@
// ignore-stage1
#![feature(plugin)]
#[plugin] #[no_link]
extern crate roman_numerals;
#![plugin(roman_numerals)]
pub fn main() {
assert_eq!(rn!(MMXV), 2015);

View file

@ -8,14 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:syntax-extension-with-dll-deps-1.rs
// aux-build:syntax-extension-with-dll-deps-2.rs
// aux-build:syntax_extension_with_dll_deps_1.rs
// aux-build:syntax_extension_with_dll_deps_2.rs
// ignore-stage1
#![feature(plugin)]
#[plugin] #[no_link]
extern crate "syntax-extension-with-dll-deps-2" as extension;
#![plugin(syntax_extension_with_dll_deps_2)]
fn main() {
foo!();