implement hygiene for method args
This commit is contained in:
parent
8f34b21375
commit
e59dd484c2
1 changed files with 25 additions and 0 deletions
|
|
@ -934,6 +934,27 @@ impl<'a> Folder for PatIdentRenamer<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// expand a method
|
||||
fn expand_method(m: &ast::Method, fld: &mut MacroExpander) -> Gc<ast::Method> {
|
||||
let id = fld.new_id(m.id);
|
||||
let (rewritten_fn_decl, rewritten_body)
|
||||
= expand_and_rename_fn_decl_and_block(m.decl,m.body,fld);
|
||||
|
||||
// all of the other standard stuff:
|
||||
box(GC) ast::Method {
|
||||
id: id,
|
||||
ident: fld.fold_ident(m.ident),
|
||||
attrs: m.attrs.iter().map(|a| fld.fold_attribute(*a)).collect(),
|
||||
generics: fold_generics(&m.generics, fld),
|
||||
explicit_self: fld.fold_explicit_self(&m.explicit_self),
|
||||
fn_style: m.fn_style,
|
||||
decl: rewritten_fn_decl,
|
||||
body: rewritten_body,
|
||||
span: fld.new_span(m.span),
|
||||
vis: m.vis
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a fn_decl and a block and a MacroExpander, expand the fn_decl, then use the
|
||||
/// PatIdents in its arguments to perform renaming in the FnDecl and
|
||||
/// the block, returning both the new FnDecl and the new Block.
|
||||
|
|
@ -988,6 +1009,10 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
|
|||
expand_arm(arm, self)
|
||||
}
|
||||
|
||||
fn fold_method(&mut self, method: Gc<ast::Method>) -> Gc<ast::Method> {
|
||||
expand_method(method, self)
|
||||
}
|
||||
|
||||
fn new_span(&mut self, span: Span) -> Span {
|
||||
new_span(self.cx, span)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue