9
9
// except according to those terms.
10
10
11
11
use ast:: { Block , Crate , DeclLocal , ExprMac , PatMac } ;
12
- use ast:: { Local , Ident , Mac_ } ;
12
+ use ast:: { Local , Ident , Mac_ , Name } ;
13
13
use ast:: { ItemMac , MacStmtWithSemicolon , Mrk , Stmt , StmtDecl , StmtMac } ;
14
14
use ast:: { StmtExpr , StmtSemi } ;
15
15
use ast:: TokenTree ;
@@ -32,6 +32,8 @@ use visit;
32
32
use visit:: Visitor ;
33
33
use std_inject;
34
34
35
+ use std:: collections:: HashSet ;
36
+
35
37
36
38
pub fn expand_expr ( e : P < ast:: Expr > , fld : & mut MacroExpander ) -> P < ast:: Expr > {
37
39
let expr_span = e. span ;
@@ -1261,7 +1263,7 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
1261
1263
imported_macros : Vec < ast:: MacroDef > ,
1262
1264
user_exts : Vec < NamedSyntaxExtension > ,
1263
1265
feature_gated_cfgs : & mut Vec < GatedCfg > ,
1264
- c : Crate ) -> Crate {
1266
+ c : Crate ) -> ( Crate , HashSet < Name > ) {
1265
1267
let mut cx = ExtCtxt :: new ( parse_sess, c. config . clone ( ) , cfg,
1266
1268
feature_gated_cfgs) ;
1267
1269
if std_inject:: no_core ( & c) {
@@ -1271,21 +1273,23 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
1271
1273
} else {
1272
1274
cx. crate_root = Some ( "std" ) ;
1273
1275
}
1276
+ let ret = {
1277
+ let mut expander = MacroExpander :: new ( & mut cx) ;
1274
1278
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
+ }
1280
1282
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
+ }
1284
1286
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 ) ;
1289
1293
}
1290
1294
1291
1295
// HYGIENIC CONTEXT EXTENSION:
@@ -1480,7 +1484,7 @@ mod tests {
1480
1484
let ps = parse:: ParseSess :: new ( ) ;
1481
1485
let crate_ast = panictry ! ( string_to_parser( & ps, crate_str) . parse_crate_mod( ) ) ;
1482
1486
// 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
1484
1488
}
1485
1489
1486
1490
// find the pat_ident paths in a crate
0 commit comments