@@ -44,11 +44,11 @@ pub struct Plugins {
4444 pub registrars : Vec < PluginRegistrar > ,
4545}
4646
47- struct PluginLoader < ' a > {
47+ pub struct PluginLoader < ' a > {
4848 sess : & ' a Session ,
4949 span_whitelist : HashSet < Span > ,
5050 reader : CrateReader < ' a > ,
51- plugins : Plugins ,
51+ pub plugins : Plugins ,
5252}
5353
5454impl < ' a > PluginLoader < ' a > {
@@ -67,7 +67,7 @@ impl<'a> PluginLoader<'a> {
6767
6868/// Read plugin metadata and dynamically load registrar functions.
6969pub fn load_plugins ( sess : & Session , krate : & ast:: Crate ,
70- addl_plugins : Option < Plugins > ) -> Plugins {
70+ addl_plugins : Option < Vec < String > > ) -> Plugins {
7171 let mut loader = PluginLoader :: new ( sess) ;
7272
7373 // 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,
7979
8080 visit:: walk_crate ( & mut loader, krate) ;
8181
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 )
9086 }
91- None => ( )
9287 }
9388
94- return plugins;
89+ return loader . plugins ;
9590}
9691
9792// 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> {
160155 }
161156 }
162157
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) )
164159 }
165160
166161 fn visit_mac ( & mut self , _: & ast:: Mac ) {
@@ -174,13 +169,13 @@ impl<'a> PluginLoader<'a> {
174169 c : CrateOrString < ' b > ,
175170 plugin_attr : Option < P < ast:: MetaItem > > ,
176171 macro_selection : Option < HashSet < token:: InternedString > > ,
177- reexport : HashSet < token:: InternedString > ) {
172+ reexport : Option < HashSet < token:: InternedString > > ) {
178173 let mut macros = vec ! [ ] ;
179174 let mut registrar = None ;
180175
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 ,
184179 } ;
185180 let load_registrar = plugin_attr. is_some ( ) ;
186181
@@ -207,7 +202,11 @@ impl<'a> PluginLoader<'a> {
207202 None => true ,
208203 Some ( sel) => sel. contains ( & name) ,
209204 } ;
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+ } ;
211210 self . plugins . macros . push ( def) ;
212211 }
213212
0 commit comments