@@ -44,11 +44,11 @@ pub struct Plugins {
44
44
pub registrars : Vec < PluginRegistrar > ,
45
45
}
46
46
47
- struct PluginLoader < ' a > {
47
+ pub struct PluginLoader < ' a > {
48
48
sess : & ' a Session ,
49
49
span_whitelist : HashSet < Span > ,
50
50
reader : CrateReader < ' a > ,
51
- plugins : Plugins ,
51
+ pub plugins : Plugins ,
52
52
}
53
53
54
54
impl < ' a > PluginLoader < ' a > {
@@ -67,7 +67,7 @@ impl<'a> PluginLoader<'a> {
67
67
68
68
/// Read plugin metadata and dynamically load registrar functions.
69
69
pub fn load_plugins ( sess : & Session , krate : & ast:: Crate ,
70
- addl_plugins : Option < Plugins > ) -> Plugins {
70
+ addl_plugins : Option < Vec < String > > ) -> Plugins {
71
71
let mut loader = PluginLoader :: new ( sess) ;
72
72
73
73
// We need to error on `#[macro_use] extern crate` when it isn't at the
@@ -79,19 +79,14 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
79
79
80
80
visit:: walk_crate ( & mut loader, krate) ;
81
81
82
- let mut plugins = loader. plugins ;
83
-
84
- match addl_plugins {
85
- Some ( addl_plugins) => {
86
- // Add in the additional plugins requested by the frontend
87
- let Plugins { macros : addl_macros, registrars : addl_registrars } = addl_plugins;
88
- plugins. macros . extend ( addl_macros. into_iter ( ) ) ;
89
- plugins. registrars . extend ( addl_registrars. into_iter ( ) ) ;
82
+ if let Some ( plugins) = addl_plugins {
83
+ for plugin in plugins. iter ( ) {
84
+ loader. load_plugin ( CrateOrString :: Str ( plugin. as_slice ( ) ) ,
85
+ None , None , None )
90
86
}
91
- None => ( )
92
87
}
93
88
94
- return plugins;
89
+ return loader . plugins ;
95
90
}
96
91
97
92
// note that macros aren't expanded yet, and therefore macros can't add plugins.
@@ -160,7 +155,7 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
160
155
}
161
156
}
162
157
163
- self . load_plugin ( CrateOrString :: Krate ( vi) , plugin_attr, macro_selection, reexport)
158
+ self . load_plugin ( CrateOrString :: Krate ( vi) , plugin_attr, macro_selection, Some ( reexport) )
164
159
}
165
160
166
161
fn visit_mac ( & mut self , _: & ast:: Mac ) {
@@ -174,13 +169,13 @@ impl<'a> PluginLoader<'a> {
174
169
c : CrateOrString < ' b > ,
175
170
plugin_attr : Option < P < ast:: MetaItem > > ,
176
171
macro_selection : Option < HashSet < token:: InternedString > > ,
177
- reexport : HashSet < token:: InternedString > ) {
172
+ reexport : Option < HashSet < token:: InternedString > > ) {
178
173
let mut macros = vec ! [ ] ;
179
174
let mut registrar = None ;
180
175
181
- let load_macros = match macro_selection. as_ref ( ) {
182
- Some ( sel) => sel. len ( ) != 0 || reexport . len ( ) != 0 ,
183
- None => true ,
176
+ let load_macros = match ( macro_selection. as_ref ( ) , reexport . as_ref ( ) ) {
177
+ ( Some ( sel) , Some ( re ) ) => sel. len ( ) != 0 || re . len ( ) != 0 ,
178
+ _ => true ,
184
179
} ;
185
180
let load_registrar = plugin_attr. is_some ( ) ;
186
181
@@ -207,7 +202,11 @@ impl<'a> PluginLoader<'a> {
207
202
None => true ,
208
203
Some ( sel) => sel. contains ( & name) ,
209
204
} ;
210
- def. export = reexport. contains ( & name) ;
205
+ def. export = if let Some ( ref re) = reexport {
206
+ re. contains ( & name)
207
+ } else {
208
+ false // Don't reexport macros from crates loaded from the command line
209
+ } ;
211
210
self . plugins . macros . push ( def) ;
212
211
}
213
212
0 commit comments