9
9
// except according to those terms.
10
10
11
11
use ast:: { Block , Crate , Ident , Mac_ , PatKind } ;
12
- use ast:: { MacStmtStyle , StmtKind , ItemKind } ;
12
+ use ast:: { Name , MacStmtStyle , StmtKind , ItemKind } ;
13
13
use ast;
14
14
use ext:: hygiene:: Mark ;
15
15
use ext:: placeholders:: { placeholder, PlaceholderExpander } ;
@@ -299,10 +299,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
299
299
} ;
300
300
301
301
attr:: mark_used ( & attr) ;
302
+ let name = intern ( & attr. name ( ) ) ;
302
303
self . cx . bt_push ( ExpnInfo {
303
304
call_site : attr. span ,
304
305
callee : NameAndSpan {
305
- format : MacroAttribute ( intern ( & attr . name ( ) ) ) ,
306
+ format : MacroAttribute ( name) ,
306
307
span : Some ( attr. span ) ,
307
308
allow_internal_unstable : false ,
308
309
}
@@ -325,7 +326,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
325
326
let item_toks = TokenStream :: from_tts ( tts_for_item ( & item, & self . cx . parse_sess ) ) ;
326
327
327
328
let tok_result = mac. expand ( self . cx , attr. span , attr_toks, item_toks) ;
328
- self . parse_expansion ( tok_result, kind, attr. span )
329
+ self . parse_expansion ( tok_result, kind, name , attr. span )
329
330
}
330
331
_ => unreachable ! ( ) ,
331
332
}
@@ -424,7 +425,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
424
425
425
426
let toks = TokenStream :: from_tts ( marked_tts) ;
426
427
let tok_result = expandfun. expand ( self . cx , span, toks) ;
427
- Some ( self . parse_expansion ( tok_result, kind, span) )
428
+ Some ( self . parse_expansion ( tok_result, kind, extname , span) )
428
429
}
429
430
} ;
430
431
@@ -443,7 +444,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
443
444
} )
444
445
}
445
446
446
- fn parse_expansion ( & mut self , toks : TokenStream , kind : ExpansionKind , span : Span ) -> Expansion {
447
+ fn parse_expansion ( & mut self , toks : TokenStream , kind : ExpansionKind , name : Name , span : Span )
448
+ -> Expansion {
447
449
let mut parser = self . cx . new_parser_from_tts ( & toks. to_tts ( ) ) ;
448
450
let expansion = match parser. parse_expansion ( kind, false ) {
449
451
Ok ( expansion) => expansion,
@@ -452,13 +454,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
452
454
return kind. dummy ( span) ;
453
455
}
454
456
} ;
455
- parser. ensure_complete_parse ( kind == ExpansionKind :: Expr , |parser| {
456
- let msg = format ! ( "macro expansion ignores token `{}` and any following" ,
457
- parser. this_token_to_string( ) ) ;
458
- parser. diagnostic ( ) . struct_span_err ( parser. span , & msg)
459
- . span_note ( span, "caused by the macro expansion here" )
460
- . emit ( ) ;
461
- } ) ;
457
+ parser. ensure_complete_parse ( name, kind. name ( ) , span) ;
462
458
// FIXME better span info
463
459
expansion. fold_with ( & mut ChangeSpan { span : span } )
464
460
}
0 commit comments