diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 957187ec71c61..72e0a86bf5909 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1465,7 +1465,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { noop_fold_generic_param(param, self) } - fn fold_attribute(&mut self, at: ast::Attribute) -> Option { + fn fold_attribute(&mut self, at: ast::Attribute) -> ast::Attribute { // turn `#[doc(include="filename")]` attributes into `#[doc(include(file="filename", // contents="file contents")]` attributes if !at.check_name("doc") { @@ -1585,10 +1585,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { let meta = attr::mk_list_item(DUMMY_SP, Ident::from_str("doc"), items); match at.style { - ast::AttrStyle::Inner => - Some(attr::mk_spanned_attr_inner(at.span, at.id, meta)), - ast::AttrStyle::Outer => - Some(attr::mk_spanned_attr_outer(at.span, at.id, meta)), + ast::AttrStyle::Inner => attr::mk_spanned_attr_inner(at.span, at.id, meta), + ast::AttrStyle::Outer => attr::mk_spanned_attr_outer(at.span, at.id, meta), } } else { noop_fold_attribute(at, self) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index c01ac3107b6d8..1ab1de1ba5c33 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -209,7 +209,7 @@ pub trait Folder : Sized { noop_fold_label(label, self) } - fn fold_attribute(&mut self, at: Attribute) -> Option { + fn fold_attribute(&mut self, at: Attribute) -> Attribute { noop_fold_attribute(at, self) } @@ -313,7 +313,7 @@ pub fn noop_fold_use_tree(use_tree: UseTree, fld: &mut T) -> UseTree } pub fn fold_attrs(attrs: Vec, fld: &mut T) -> Vec { - attrs.move_flat_map(|x| fld.fold_attribute(x)) + attrs.move_map(|x| fld.fold_attribute(x)) } pub fn fold_thin_attrs(attrs: ThinVec, fld: &mut T) -> ThinVec { @@ -485,15 +485,15 @@ pub fn noop_fold_local(l: P, fld: &mut T) -> P { }) } -pub fn noop_fold_attribute(attr: Attribute, fld: &mut T) -> Option { - Some(Attribute { +pub fn noop_fold_attribute(attr: Attribute, fld: &mut T) -> Attribute { + Attribute { id: attr.id, style: attr.style, path: fld.fold_path(attr.path), tokens: fld.fold_tts(attr.tokens), is_sugared_doc: attr.is_sugared_doc, span: fld.new_span(attr.span), - }) + } } pub fn noop_fold_mac(Spanned {node, span}: Mac, fld: &mut T) -> Mac { @@ -678,14 +678,10 @@ pub fn noop_fold_param_bound(pb: GenericBound, fld: &mut T) -> GenericBound w } pub fn noop_fold_generic_param(param: GenericParam, fld: &mut T) -> GenericParam { - let attrs: Vec<_> = param.attrs.into(); GenericParam { ident: fld.fold_ident(param.ident), id: fld.new_id(param.id), - attrs: attrs.into_iter() - .flat_map(|x| fld.fold_attribute(x).into_iter()) - .collect::>() - .into(), + attrs: fold_thin_attrs(param.attrs, fld), bounds: param.bounds.move_map(|l| noop_fold_param_bound(l, fld)), kind: match param.kind { GenericParamKind::Lifetime => GenericParamKind::Lifetime,