Skip to content

Commit

Permalink
Simplify fold_attribute.
Browse files Browse the repository at this point in the history
It doesn't need to return an `Option`.
  • Loading branch information
nnethercote committed Feb 5, 2019
1 parent eea2dfe commit f97e896
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -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<ast::Attribute> {
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") {
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 6 additions & 10 deletions src/libsyntax/fold.rs
Expand Up @@ -209,7 +209,7 @@ pub trait Folder : Sized {
noop_fold_label(label, self)
}

fn fold_attribute(&mut self, at: Attribute) -> Option<Attribute> {
fn fold_attribute(&mut self, at: Attribute) -> Attribute {
noop_fold_attribute(at, self)
}

Expand Down Expand Up @@ -313,7 +313,7 @@ pub fn noop_fold_use_tree<T: Folder>(use_tree: UseTree, fld: &mut T) -> UseTree
}

pub fn fold_attrs<T: Folder>(attrs: Vec<Attribute>, fld: &mut T) -> Vec<Attribute> {
attrs.move_flat_map(|x| fld.fold_attribute(x))
attrs.move_map(|x| fld.fold_attribute(x))
}

pub fn fold_thin_attrs<T: Folder>(attrs: ThinVec<Attribute>, fld: &mut T) -> ThinVec<Attribute> {
Expand Down Expand Up @@ -485,15 +485,15 @@ pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
})
}

pub fn noop_fold_attribute<T: Folder>(attr: Attribute, fld: &mut T) -> Option<Attribute> {
Some(Attribute {
pub fn noop_fold_attribute<T: Folder>(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<T: Folder>(Spanned {node, span}: Mac, fld: &mut T) -> Mac {
Expand Down Expand Up @@ -678,14 +678,10 @@ pub fn noop_fold_param_bound<T>(pb: GenericBound, fld: &mut T) -> GenericBound w
}

pub fn noop_fold_generic_param<T: Folder>(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::<Vec<_>>()
.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,
Expand Down

0 comments on commit f97e896

Please sign in to comment.