Skip to content

Commit 55ba05b

Browse files
committed
rustc_plugin: Remove support for plugin arguments
1 parent 4007d4e commit 55ba05b

File tree

14 files changed

+97
-156
lines changed

14 files changed

+97
-156
lines changed

src/doc/unstable-book/src/language-features/plugin.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ the crate attribute `#![plugin(...)]`. See the
2121
`rustc_driver::plugin` documentation for more about the
2222
mechanics of defining and loading a plugin.
2323

24-
If present, arguments passed as `#![plugin(foo(... args ...))]` are not
25-
interpreted by rustc itself. They are provided to the plugin through the
26-
`Registry`'s `args` method.
27-
2824
In the vast majority of cases, a plugin should *only* be used through
2925
`#![plugin]` and not through an `extern crate` item. Linking a plugin would
3026
pull in all of libsyntax and librustc as dependencies of your crate. This is

src/librustc_feature/builtin_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
283283
)
284284
),
285285
(
286-
sym::plugin, CrateLevel, template!(List: "name|name(args)"),
286+
sym::plugin, CrateLevel, template!(List: "name"),
287287
Gated(
288288
Stability::Deprecated(
289289
"https://github.com/rust-lang/rust/pull/64675",

src/librustc_interface/passes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ pub fn register_plugins<'a>(
229229

230230
time(sess, "plugin registration", || {
231231
for registrar in registrars {
232-
registry.args_hidden = Some(registrar.args);
233-
(registrar.fun)(&mut registry);
232+
registrar(&mut registry);
234233
}
235234
});
236235

src/librustc_plugin_impl/load.rs

Lines changed: 68 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,15 @@ use std::borrow::ToOwned;
99
use std::env;
1010
use std::mem;
1111
use std::path::PathBuf;
12-
use syntax::ast;
12+
use syntax::ast::{Crate, Ident};
1313
use syntax::struct_span_err;
14-
use syntax::symbol::{Symbol, kw, sym};
15-
use syntax_pos::{Span, DUMMY_SP};
14+
use syntax::symbol::sym;
15+
use syntax_pos::Span;
1616

1717
use rustc_error_codes::*;
1818

1919
/// Pointer to a registrar function.
20-
pub type PluginRegistrarFun =
21-
fn(&mut Registry<'_>);
22-
23-
pub struct PluginRegistrar {
24-
pub fun: PluginRegistrarFun,
25-
pub args: Vec<ast::NestedMetaItem>,
26-
}
27-
28-
struct PluginLoader<'a> {
29-
sess: &'a Session,
30-
metadata_loader: &'a dyn MetadataLoader,
31-
plugins: Vec<PluginRegistrar>,
32-
}
20+
type PluginRegistrarFn = fn(&mut Registry<'_>);
3321

3422
fn call_malformed_plugin_attribute(sess: &Session, span: Span) {
3523
struct_span_err!(sess, span, E0498, "malformed `plugin` attribute")
@@ -40,98 +28,81 @@ fn call_malformed_plugin_attribute(sess: &Session, span: Span) {
4028
/// Read plugin metadata and dynamically load registrar functions.
4129
pub fn load_plugins(sess: &Session,
4230
metadata_loader: &dyn MetadataLoader,
43-
krate: &ast::Crate,
44-
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrar> {
45-
let mut loader = PluginLoader { sess, metadata_loader, plugins: Vec::new() };
46-
47-
// do not report any error now. since crate attributes are
48-
// not touched by expansion, every use of plugin without
49-
// the feature enabled will result in an error later...
50-
if sess.features_untracked().plugin {
51-
for attr in &krate.attrs {
52-
if !attr.check_name(sym::plugin) {
53-
continue;
54-
}
55-
56-
let plugins = match attr.meta_item_list() {
57-
Some(xs) => xs,
58-
None => continue,
59-
};
31+
krate: &Crate,
32+
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrarFn> {
33+
let mut plugins = Vec::new();
34+
let mut load_plugin = |ident| load_plugin(&mut plugins, sess, metadata_loader, ident);
35+
36+
for attr in &krate.attrs {
37+
if !attr.check_name(sym::plugin) {
38+
continue;
39+
}
6040

61-
for plugin in plugins {
62-
// plugins must have a name and can't be key = value
63-
let name = plugin.name_or_empty();
64-
if name != kw::Invalid && !plugin.is_value_str() {
65-
let args = plugin.meta_item_list().map(ToOwned::to_owned);
66-
loader.load_plugin(plugin.span(), name, args.unwrap_or_default());
67-
} else {
68-
call_malformed_plugin_attribute(sess, attr.span);
69-
}
41+
for plugin in attr.meta_item_list().unwrap_or_default() {
42+
match plugin.ident() {
43+
Some(ident) if plugin.is_word() => load_plugin(ident),
44+
_ => call_malformed_plugin_attribute(sess, plugin.span()),
7045
}
7146
}
7247
}
7348

74-
if let Some(plugins) = addl_plugins {
75-
for plugin in plugins {
76-
loader.load_plugin(DUMMY_SP, Symbol::intern(&plugin), vec![]);
77-
}
49+
for plugin in addl_plugins.unwrap_or_default() {
50+
load_plugin(Ident::from_str(&plugin));
7851
}
7952

80-
loader.plugins
53+
plugins
8154
}
8255

83-
impl<'a> PluginLoader<'a> {
84-
fn load_plugin(&mut self, span: Span, name: Symbol, args: Vec<ast::NestedMetaItem>) {
85-
let registrar = locator::find_plugin_registrar(self.sess, self.metadata_loader, span, name);
86-
87-
if let Some((lib, disambiguator)) = registrar {
88-
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator);
89-
let fun = self.dylink_registrar(span, lib, symbol);
90-
self.plugins.push(PluginRegistrar {
91-
fun,
92-
args,
93-
});
94-
}
56+
fn load_plugin(plugins: &mut Vec<PluginRegistrarFn>,
57+
sess: &Session,
58+
metadata_loader: &dyn MetadataLoader,
59+
ident: Ident) {
60+
let registrar = locator::find_plugin_registrar(sess, metadata_loader, ident.span, ident.name);
61+
62+
if let Some((lib, disambiguator)) = registrar {
63+
let symbol = sess.generate_plugin_registrar_symbol(disambiguator);
64+
let fun = dylink_registrar(sess, ident.span, lib, symbol);
65+
plugins.push(fun);
9566
}
67+
}
9668

97-
// Dynamically link a registrar function into the compiler process.
98-
fn dylink_registrar(&mut self,
99-
span: Span,
100-
path: PathBuf,
101-
symbol: String) -> PluginRegistrarFun {
102-
use rustc_metadata::dynamic_lib::DynamicLibrary;
103-
104-
// Make sure the path contains a / or the linker will search for it.
105-
let path = env::current_dir().unwrap().join(&path);
106-
107-
let lib = match DynamicLibrary::open(Some(&path)) {
108-
Ok(lib) => lib,
109-
// this is fatal: there are almost certainly macros we need
110-
// inside this crate, so continue would spew "macro undefined"
111-
// errors
112-
Err(err) => {
113-
self.sess.span_fatal(span, &err)
114-
}
115-
};
116-
117-
unsafe {
118-
let registrar =
119-
match lib.symbol(&symbol) {
120-
Ok(registrar) => {
121-
mem::transmute::<*mut u8,PluginRegistrarFun>(registrar)
122-
}
123-
// again fatal if we can't register macros
124-
Err(err) => {
125-
self.sess.span_fatal(span, &err)
126-
}
127-
};
128-
129-
// Intentionally leak the dynamic library. We can't ever unload it
130-
// since the library can make things that will live arbitrarily long
131-
// (e.g., an @-box cycle or a thread).
132-
mem::forget(lib);
133-
134-
registrar
69+
// Dynamically link a registrar function into the compiler process.
70+
fn dylink_registrar(sess: &Session,
71+
span: Span,
72+
path: PathBuf,
73+
symbol: String) -> PluginRegistrarFn {
74+
use rustc_metadata::dynamic_lib::DynamicLibrary;
75+
76+
// Make sure the path contains a / or the linker will search for it.
77+
let path = env::current_dir().unwrap().join(&path);
78+
79+
let lib = match DynamicLibrary::open(Some(&path)) {
80+
Ok(lib) => lib,
81+
// this is fatal: there are almost certainly macros we need
82+
// inside this crate, so continue would spew "macro undefined"
83+
// errors
84+
Err(err) => {
85+
sess.span_fatal(span, &err)
13586
}
87+
};
88+
89+
unsafe {
90+
let registrar =
91+
match lib.symbol(&symbol) {
92+
Ok(registrar) => {
93+
mem::transmute::<*mut u8, PluginRegistrarFn>(registrar)
94+
}
95+
// again fatal if we can't register macros
96+
Err(err) => {
97+
sess.span_fatal(span, &err)
98+
}
99+
};
100+
101+
// Intentionally leak the dynamic library. We can't ever unload it
102+
// since the library can make things that will live arbitrarily long
103+
// (e.g., an @-box cycle or a thread).
104+
mem::forget(lib);
105+
106+
registrar
136107
}
137108
}

src/librustc_plugin_impl/registry.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use rustc::lint::LintStore;
44
use rustc::session::Session;
5-
use syntax::ast;
65
use syntax_pos::Span;
76

87
use std::borrow::ToOwned;
@@ -23,9 +22,6 @@ pub struct Registry<'a> {
2322
/// The `LintStore` allows plugins to register new lints.
2423
pub lint_store: &'a mut LintStore,
2524

26-
#[doc(hidden)]
27-
pub args_hidden: Option<Vec<ast::NestedMetaItem>>,
28-
2925
#[doc(hidden)]
3026
pub krate_span: Span,
3127

@@ -39,26 +35,11 @@ impl<'a> Registry<'a> {
3935
Registry {
4036
sess,
4137
lint_store,
42-
args_hidden: None,
4338
krate_span,
4439
llvm_passes: vec![],
4540
}
4641
}
4742

48-
/// Gets the plugin's arguments, if any.
49-
///
50-
/// These are specified inside the `plugin` crate attribute as
51-
///
52-
/// ```no_run
53-
/// #![plugin(my_plugin_name(... args ...))]
54-
/// ```
55-
///
56-
/// Returns empty slice in case the plugin was loaded
57-
/// with `--extra-plugins`
58-
pub fn args(&self) -> &[ast::NestedMetaItem] {
59-
self.args_hidden.as_ref().map(|v| &v[..]).unwrap_or(&[])
60-
}
61-
6243
/// Register an LLVM pass.
6344
///
6445
/// Registration with LLVM itself is handled through static C++ objects with

src/test/ui/feature-gates/feature-gate-plugin.rs renamed to src/test/ui-fulldeps/feature-gate-plugin.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Test that `#![plugin(...)]` attribute is gated by `plugin` feature gate
1+
// aux-build:empty-plugin.rs
2+
// ignore-stage1
23

3-
#![plugin(foo)]
4+
#![plugin(empty_plugin)]
45
//~^ ERROR compiler plugins are deprecated
56
//~| WARN use of deprecated attribute `plugin`: compiler plugins are deprecated
67

src/test/ui/feature-gates/feature-gate-plugin.stderr renamed to src/test/ui-fulldeps/feature-gate-plugin.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0658]: compiler plugins are deprecated
2-
--> $DIR/feature-gate-plugin.rs:3:1
2+
--> $DIR/feature-gate-plugin.rs:4:1
33
|
4-
LL | #![plugin(foo)]
5-
| ^^^^^^^^^^^^^^^
4+
LL | #![plugin(empty_plugin)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/29597
88
= help: add `#![feature(plugin)]` to the crate attributes to enable
99

1010
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
11-
--> $DIR/feature-gate-plugin.rs:3:1
11+
--> $DIR/feature-gate-plugin.rs:4:1
1212
|
13-
LL | #![plugin(foo)]
14-
| ^^^^^^^^^^^^^^^ help: may be removed in a future compiler version
13+
LL | #![plugin(empty_plugin)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: may be removed in a future compiler version
1515
|
1616
= note: `#[warn(deprecated)]` on by default
1717

src/test/ui-fulldeps/plugin-args-2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// check-pass
21
// aux-build:empty-plugin.rs
32
// ignore-stage1
43

54
#![feature(plugin)]
6-
#![plugin(empty_plugin())] //~ WARNING compiler plugins are deprecated
5+
#![plugin(empty_plugin(args))]
6+
//~^ ERROR malformed `plugin` attribute
7+
//~| WARNING compiler plugins are deprecated
78

89
fn main() {}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
error[E0498]: malformed `plugin` attribute
2+
--> $DIR/plugin-args-2.rs:5:11
3+
|
4+
LL | #![plugin(empty_plugin(args))]
5+
| ^^^^^^^^^^^^^^^^^^ malformed attribute
6+
17
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
2-
--> $DIR/plugin-args-2.rs:6:1
8+
--> $DIR/plugin-args-2.rs:5:1
39
|
4-
LL | #![plugin(empty_plugin())]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: may be removed in a future compiler version
10+
LL | #![plugin(empty_plugin(args))]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: may be removed in a future compiler version
612
|
713
= note: `#[warn(deprecated)]` on by default
814

15+
error: aborting due to previous error
16+

src/test/ui-fulldeps/plugin-args-3.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui-fulldeps/plugin-args-3.stderr

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/test/ui/malformed/malformed-plugin-1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: malformed `plugin` attribute input
22
--> $DIR/malformed-plugin-1.rs:2:1
33
|
44
LL | #![plugin]
5-
| ^^^^^^^^^^ help: must be of the form: `#[plugin(name|name(args))]`
5+
| ^^^^^^^^^^ help: must be of the form: `#[plugin(name)]`
66

77
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
88
--> $DIR/malformed-plugin-1.rs:2:1

src/test/ui/malformed/malformed-plugin-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: malformed `plugin` attribute input
22
--> $DIR/malformed-plugin-2.rs:2:1
33
|
44
LL | #![plugin="bleh"]
5-
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[plugin(name|name(args))]`
5+
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[plugin(name)]`
66

77
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
88
--> $DIR/malformed-plugin-2.rs:2:1

src/test/ui/malformed/malformed-plugin-3.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0498]: malformed `plugin` attribute
2-
--> $DIR/malformed-plugin-3.rs:2:1
2+
--> $DIR/malformed-plugin-3.rs:2:11
33
|
44
LL | #![plugin(foo="bleh")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^ malformed attribute
5+
| ^^^^^^^^^^ malformed attribute
66

77
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
88
--> $DIR/malformed-plugin-3.rs:2:1

0 commit comments

Comments
 (0)