diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-02-05 15:11:27 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-02-05 15:11:27 +1100 |
| commit | f97e896fd669b61051027d76d6dccb89c72c4c52 (patch) | |
| tree | 8c2b3559423d67572625270d54e7f0a3ee9d7407 | |
| parent | eea2dfe76f7afea0df3ae99fcdd30f1afbf4402d (diff) | |
| download | rust-f97e896fd669b61051027d76d6dccb89c72c4c52.tar.gz rust-f97e896fd669b61051027d76d6dccb89c72c4c52.zip | |
Simplify `fold_attribute`.
It doesn't need to return an `Option`.
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 16 |
2 files changed, 9 insertions, 15 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 957187ec71c..72e0a86bf59 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<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") { @@ -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 c01ac3107b6..1ab1de1ba5c 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<Attribute> { + fn fold_attribute(&mut self, at: Attribute) -> Attribute { noop_fold_attribute(at, self) } @@ -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> { @@ -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 { @@ -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, |
