99// except according to those terms.
1010
1111use ast:: { Block , Crate , DeclLocal , ExprMac , PatMac } ;
12- use ast:: { Local , Ident , Mac_ } ;
12+ use ast:: { Local , Ident , Mac_ , Name } ;
1313use ast:: { ItemMac , MacStmtWithSemicolon , Mrk , Stmt , StmtDecl , StmtMac } ;
1414use ast:: { StmtExpr , StmtSemi } ;
1515use ast:: TokenTree ;
@@ -32,6 +32,8 @@ use visit;
3232use visit:: Visitor ;
3333use std_inject;
3434
35+ use std:: collections:: HashSet ;
36+
3537
3638pub fn expand_expr ( e : P < ast:: Expr > , fld : & mut MacroExpander ) -> P < ast:: Expr > {
3739 let expr_span = e. span ;
@@ -1261,7 +1263,7 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
12611263 imported_macros : Vec < ast:: MacroDef > ,
12621264 user_exts : Vec < NamedSyntaxExtension > ,
12631265 feature_gated_cfgs : & mut Vec < GatedCfg > ,
1264- c : Crate ) -> Crate {
1266+ c : Crate ) -> ( Crate , HashSet < Name > ) {
12651267 let mut cx = ExtCtxt :: new ( parse_sess, c. config . clone ( ) , cfg,
12661268 feature_gated_cfgs) ;
12671269 if std_inject:: no_core ( & c) {
@@ -1271,21 +1273,23 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
12711273 } else {
12721274 cx. crate_root = Some ( "std" ) ;
12731275 }
1276+ let ret = {
1277+ let mut expander = MacroExpander :: new ( & mut cx) ;
12741278
1275- let mut expander = MacroExpander :: new ( & mut cx) ;
1276-
1277- for def in imported_macros {
1278- expander. cx . insert_macro ( def) ;
1279- }
1279+ for def in imported_macros {
1280+ expander. cx . insert_macro ( def) ;
1281+ }
12801282
1281- for ( name, extension) in user_exts {
1282- expander. cx . syntax_env . insert ( name, extension) ;
1283- }
1283+ for ( name, extension) in user_exts {
1284+ expander. cx . syntax_env . insert ( name, extension) ;
1285+ }
12841286
1285- let mut ret = expander. fold_crate ( c) ;
1286- ret. exported_macros = expander. cx . exported_macros . clone ( ) ;
1287- parse_sess. span_diagnostic . handler ( ) . abort_if_errors ( ) ;
1288- return ret;
1287+ let mut ret = expander. fold_crate ( c) ;
1288+ ret. exported_macros = expander. cx . exported_macros . clone ( ) ;
1289+ parse_sess. span_diagnostic . handler ( ) . abort_if_errors ( ) ;
1290+ ret
1291+ } ;
1292+ return ( ret, cx. syntax_env . names ) ;
12891293}
12901294
12911295// HYGIENIC CONTEXT EXTENSION:
@@ -1480,7 +1484,7 @@ mod tests {
14801484 let ps = parse:: ParseSess :: new ( ) ;
14811485 let crate_ast = panictry ! ( string_to_parser( & ps, crate_str) . parse_crate_mod( ) ) ;
14821486 // the cfg argument actually does matter, here...
1483- expand_crate ( & ps, test_ecfg ( ) , vec ! ( ) , vec ! ( ) , & mut vec ! [ ] , crate_ast)
1487+ expand_crate ( & ps, test_ecfg ( ) , vec ! ( ) , vec ! ( ) , & mut vec ! [ ] , crate_ast) . 0
14841488 }
14851489
14861490 // find the pat_ident paths in a crate
0 commit comments