Skip to content

Commit f97e896

Browse files
committed
Simplify fold_attribute.
It doesn't need to return an `Option`.
1 parent eea2dfe commit f97e896

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
14651465
noop_fold_generic_param(param, self)
14661466
}
14671467

1468-
fn fold_attribute(&mut self, at: ast::Attribute) -> Option<ast::Attribute> {
1468+
fn fold_attribute(&mut self, at: ast::Attribute) -> ast::Attribute {
14691469
// turn `#[doc(include="filename")]` attributes into `#[doc(include(file="filename",
14701470
// contents="file contents")]` attributes
14711471
if !at.check_name("doc") {
@@ -1585,10 +1585,8 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
15851585

15861586
let meta = attr::mk_list_item(DUMMY_SP, Ident::from_str("doc"), items);
15871587
match at.style {
1588-
ast::AttrStyle::Inner =>
1589-
Some(attr::mk_spanned_attr_inner(at.span, at.id, meta)),
1590-
ast::AttrStyle::Outer =>
1591-
Some(attr::mk_spanned_attr_outer(at.span, at.id, meta)),
1588+
ast::AttrStyle::Inner => attr::mk_spanned_attr_inner(at.span, at.id, meta),
1589+
ast::AttrStyle::Outer => attr::mk_spanned_attr_outer(at.span, at.id, meta),
15921590
}
15931591
} else {
15941592
noop_fold_attribute(at, self)

src/libsyntax/fold.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub trait Folder : Sized {
209209
noop_fold_label(label, self)
210210
}
211211

212-
fn fold_attribute(&mut self, at: Attribute) -> Option<Attribute> {
212+
fn fold_attribute(&mut self, at: Attribute) -> Attribute {
213213
noop_fold_attribute(at, self)
214214
}
215215

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

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

319319
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> {
485485
})
486486
}
487487

488-
pub fn noop_fold_attribute<T: Folder>(attr: Attribute, fld: &mut T) -> Option<Attribute> {
489-
Some(Attribute {
488+
pub fn noop_fold_attribute<T: Folder>(attr: Attribute, fld: &mut T) -> Attribute {
489+
Attribute {
490490
id: attr.id,
491491
style: attr.style,
492492
path: fld.fold_path(attr.path),
493493
tokens: fld.fold_tts(attr.tokens),
494494
is_sugared_doc: attr.is_sugared_doc,
495495
span: fld.new_span(attr.span),
496-
})
496+
}
497497
}
498498

499499
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
678678
}
679679

680680
pub fn noop_fold_generic_param<T: Folder>(param: GenericParam, fld: &mut T) -> GenericParam {
681-
let attrs: Vec<_> = param.attrs.into();
682681
GenericParam {
683682
ident: fld.fold_ident(param.ident),
684683
id: fld.new_id(param.id),
685-
attrs: attrs.into_iter()
686-
.flat_map(|x| fld.fold_attribute(x).into_iter())
687-
.collect::<Vec<_>>()
688-
.into(),
684+
attrs: fold_thin_attrs(param.attrs, fld),
689685
bounds: param.bounds.move_map(|l| noop_fold_param_bound(l, fld)),
690686
kind: match param.kind {
691687
GenericParamKind::Lifetime => GenericParamKind::Lifetime,

0 commit comments

Comments
 (0)