syntax::fold: Allow removing attributes
This commit is contained in:
parent
0ba9e1fa52
commit
0110f5e03c
2 changed files with 20 additions and 16 deletions
|
@ -844,7 +844,7 @@ fn expand_arm(arm: ast::Arm, fld: &mut MacroExpander) -> ast::Arm {
|
||||||
arm.guard.map(|g| fld.fold_expr(rename_fld.fold_expr(g)));
|
arm.guard.map(|g| fld.fold_expr(rename_fld.fold_expr(g)));
|
||||||
let rewritten_body = fld.fold_expr(rename_fld.fold_expr(arm.body));
|
let rewritten_body = fld.fold_expr(rename_fld.fold_expr(arm.body));
|
||||||
ast::Arm {
|
ast::Arm {
|
||||||
attrs: arm.attrs.move_map(|x| fld.fold_attribute(x)),
|
attrs: fold::fold_attrs(arm.attrs, fld),
|
||||||
pats: rewritten_pats,
|
pats: rewritten_pats,
|
||||||
guard: rewritten_guard,
|
guard: rewritten_guard,
|
||||||
body: rewritten_body,
|
body: rewritten_body,
|
||||||
|
@ -1273,7 +1273,7 @@ fn expand_method(m: P<ast::Method>, fld: &mut MacroExpander) -> SmallVector<P<as
|
||||||
let (rewritten_fn_decl, rewritten_body)
|
let (rewritten_fn_decl, rewritten_body)
|
||||||
= expand_and_rename_fn_decl_and_block(decl, body, fld);
|
= expand_and_rename_fn_decl_and_block(decl, body, fld);
|
||||||
SmallVector::one(P(ast::Method {
|
SmallVector::one(P(ast::Method {
|
||||||
attrs: m.attrs.move_map(|a| fld.fold_attribute(a)),
|
attrs: fold::fold_attrs(m.attrs, fld),
|
||||||
id: id,
|
id: id,
|
||||||
span: fld.new_span(m.span),
|
span: fld.new_span(m.span),
|
||||||
node: ast::MethDecl(fld.fold_ident(ident),
|
node: ast::MethDecl(fld.fold_ident(ident),
|
||||||
|
|
|
@ -223,7 +223,7 @@ pub trait Folder : Sized {
|
||||||
noop_fold_lifetime_def(l, self)
|
noop_fold_lifetime_def(l, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_attribute(&mut self, at: Attribute) -> Attribute {
|
fn fold_attribute(&mut self, at: Attribute) -> Option<Attribute> {
|
||||||
noop_fold_attribute(at, self)
|
noop_fold_attribute(at, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,9 +373,13 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fold_attrs<T: Folder>(attrs: Vec<Attribute>, fld: &mut T) -> Vec<Attribute> {
|
||||||
|
attrs.into_iter().flat_map(|x| fld.fold_attribute(x).into_iter()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T) -> Arm {
|
pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T) -> Arm {
|
||||||
Arm {
|
Arm {
|
||||||
attrs: attrs.move_map(|x| fld.fold_attribute(x)),
|
attrs: fold_attrs(attrs, fld),
|
||||||
pats: pats.move_map(|x| fld.fold_pat(x)),
|
pats: pats.move_map(|x| fld.fold_pat(x)),
|
||||||
guard: guard.map(|x| fld.fold_expr(x)),
|
guard: guard.map(|x| fld.fold_expr(x)),
|
||||||
body: fld.fold_expr(body),
|
body: fld.fold_expr(body),
|
||||||
|
@ -475,7 +479,7 @@ pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
|
||||||
node: Variant_ {
|
node: Variant_ {
|
||||||
id: fld.new_id(id),
|
id: fld.new_id(id),
|
||||||
name: name,
|
name: name,
|
||||||
attrs: attrs.move_map(|x| fld.fold_attribute(x)),
|
attrs: fold_attrs(attrs, fld),
|
||||||
kind: match kind {
|
kind: match kind {
|
||||||
TupleVariantKind(variant_args) => {
|
TupleVariantKind(variant_args) => {
|
||||||
TupleVariantKind(variant_args.move_map(|x|
|
TupleVariantKind(variant_args.move_map(|x|
|
||||||
|
@ -553,9 +557,9 @@ pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Attribute {
|
pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attribute> {
|
||||||
let Spanned {node: Attribute_ {id, style, value, is_sugared_doc}, span} = at;
|
let Spanned {node: Attribute_ {id, style, value, is_sugared_doc}, span} = at;
|
||||||
Spanned {
|
Some(Spanned {
|
||||||
node: Attribute_ {
|
node: Attribute_ {
|
||||||
id: id,
|
id: id,
|
||||||
style: style,
|
style: style,
|
||||||
|
@ -563,7 +567,7 @@ pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Attribute {
|
||||||
is_sugared_doc: is_sugared_doc
|
is_sugared_doc: is_sugared_doc
|
||||||
},
|
},
|
||||||
span: fld.new_span(span)
|
span: fld.new_span(span)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mut T)
|
pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mut T)
|
||||||
|
@ -843,8 +847,8 @@ pub fn noop_fold_typedef<T>(t: Typedef, folder: &mut T)
|
||||||
where T: Folder {
|
where T: Folder {
|
||||||
let new_id = folder.new_id(t.id);
|
let new_id = folder.new_id(t.id);
|
||||||
let new_span = folder.new_span(t.span);
|
let new_span = folder.new_span(t.span);
|
||||||
let new_attrs = t.attrs.iter().map(|attr| {
|
let new_attrs = t.attrs.iter().flat_map(|attr| {
|
||||||
folder.fold_attribute((*attr).clone())
|
folder.fold_attribute((*attr).clone()).into_iter()
|
||||||
}).collect();
|
}).collect();
|
||||||
let new_ident = folder.fold_ident(t.ident);
|
let new_ident = folder.fold_ident(t.ident);
|
||||||
let new_type = folder.fold_ty(t.typ);
|
let new_type = folder.fold_ty(t.typ);
|
||||||
|
@ -864,7 +868,7 @@ pub fn noop_fold_associated_type<T>(at: AssociatedType, folder: &mut T)
|
||||||
{
|
{
|
||||||
let new_attrs = at.attrs
|
let new_attrs = at.attrs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|attr| folder.fold_attribute((*attr).clone()))
|
.flat_map(|attr| folder.fold_attribute((*attr).clone()).into_iter())
|
||||||
.collect();
|
.collect();
|
||||||
let new_param = folder.fold_ty_param(at.ty_param);
|
let new_param = folder.fold_ty_param(at.ty_param);
|
||||||
ast::AssociatedType {
|
ast::AssociatedType {
|
||||||
|
@ -906,7 +910,7 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
|
||||||
id: fld.new_id(id),
|
id: fld.new_id(id),
|
||||||
kind: kind,
|
kind: kind,
|
||||||
ty: fld.fold_ty(ty),
|
ty: fld.fold_ty(ty),
|
||||||
attrs: attrs.move_map(|a| fld.fold_attribute(a))
|
attrs: fold_attrs(attrs, fld),
|
||||||
},
|
},
|
||||||
span: fld.new_span(span)
|
span: fld.new_span(span)
|
||||||
}
|
}
|
||||||
|
@ -1069,7 +1073,7 @@ pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMetho
|
||||||
TypeMethod {
|
TypeMethod {
|
||||||
id: fld.new_id(id),
|
id: fld.new_id(id),
|
||||||
ident: fld.fold_ident(ident),
|
ident: fld.fold_ident(ident),
|
||||||
attrs: attrs.move_map(|a| fld.fold_attribute(a)),
|
attrs: fold_attrs(attrs, fld),
|
||||||
unsafety: unsafety,
|
unsafety: unsafety,
|
||||||
abi: abi,
|
abi: abi,
|
||||||
decl: fld.fold_fn_decl(decl),
|
decl: fld.fold_fn_decl(decl),
|
||||||
|
@ -1151,7 +1155,7 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}
|
||||||
Item {
|
Item {
|
||||||
id: id,
|
id: id,
|
||||||
ident: folder.fold_ident(ident),
|
ident: folder.fold_ident(ident),
|
||||||
attrs: attrs.move_map(|e| folder.fold_attribute(e)),
|
attrs: fold_attrs(attrs, folder),
|
||||||
node: node,
|
node: node,
|
||||||
vis: vis,
|
vis: vis,
|
||||||
span: folder.new_span(span)
|
span: folder.new_span(span)
|
||||||
|
@ -1162,7 +1166,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
|
||||||
ni.map(|ForeignItem {id, ident, attrs, node, span, vis}| ForeignItem {
|
ni.map(|ForeignItem {id, ident, attrs, node, span, vis}| ForeignItem {
|
||||||
id: folder.new_id(id),
|
id: folder.new_id(id),
|
||||||
ident: folder.fold_ident(ident),
|
ident: folder.fold_ident(ident),
|
||||||
attrs: attrs.move_map(|x| folder.fold_attribute(x)),
|
attrs: fold_attrs(attrs, folder),
|
||||||
node: match node {
|
node: match node {
|
||||||
ForeignItemFn(fdec, generics) => {
|
ForeignItemFn(fdec, generics) => {
|
||||||
ForeignItemFn(folder.fold_fn_decl(fdec), folder.fold_generics(generics))
|
ForeignItemFn(folder.fold_fn_decl(fdec), folder.fold_generics(generics))
|
||||||
|
@ -1181,7 +1185,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
|
||||||
pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<P<Method>> {
|
pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<P<Method>> {
|
||||||
SmallVector::one(m.map(|Method {id, attrs, node, span}| Method {
|
SmallVector::one(m.map(|Method {id, attrs, node, span}| Method {
|
||||||
id: folder.new_id(id),
|
id: folder.new_id(id),
|
||||||
attrs: attrs.move_map(|a| folder.fold_attribute(a)),
|
attrs: fold_attrs(attrs, folder),
|
||||||
node: match node {
|
node: match node {
|
||||||
MethDecl(ident,
|
MethDecl(ident,
|
||||||
generics,
|
generics,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue