Auto merge of #22026 - kmcallister:plugin, r=sfackler
```rust #[plugin] #[no_link] extern crate bleh; ``` becomes a crate attribute ```rust #![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:
commit
94c06a1be0
37 changed files with 157 additions and 166 deletions
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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() {}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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() {}
|
||||
|
|
|
|||
|
|
@ -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() { }
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[plugin]
|
||||
#[plugin] //~ ERROR #[plugin] specified multiple times
|
||||
extern crate std;
|
||||
#![plugin] //~ ERROR malformed plugin attribute
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -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="bleh"] //~ ERROR malformed plugin attribute
|
||||
|
||||
#![feature(plugin)]
|
||||
|
||||
#[no_link]
|
||||
#[plugin="foobar"]
|
||||
extern crate plugin_args;
|
||||
|
||||
fn main() {
|
||||
assert_eq!(plugin_args!(), "#[plugin = \"foobar\"]");
|
||||
}
|
||||
fn main() {}
|
||||
13
src/test/compile-fail/malformed-plugin-3.rs
Normal file
13
src/test/compile-fail/malformed-plugin-3.rs
Normal 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() {}
|
||||
15
src/test/compile-fail/plugin-extern-crate-attr-deprecated.rs
Normal file
15
src/test/compile-fail/plugin-extern-crate-attr-deprecated.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// 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] //~ ERROR #[plugin] on `extern crate` is deprecated
|
||||
//~^ HELP use a crate attribute instead, i.e. #![plugin(std)]
|
||||
extern crate std;
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -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!();
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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() { }
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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() {}
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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!(), "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!(), "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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\")");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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!();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue