syntax: simplify HasAttrs code
This commit is contained in:
parent
64d0143c2c
commit
9be73dc63a
@ -62,7 +62,7 @@ impl HasAttrs for Annotatable {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
match self {
|
||||
Annotatable::Item(item) => item.visit_attrs(f),
|
||||
Annotatable::TraitItem(trait_item) => trait_item.visit_attrs(f),
|
||||
|
@ -657,15 +657,15 @@ impl NestedMetaItem {
|
||||
}
|
||||
|
||||
pub trait HasAttrs: Sized {
|
||||
fn attrs(&self) -> &[ast::Attribute];
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<ast::Attribute>)>(&mut self, f: F);
|
||||
fn attrs(&self) -> &[Attribute];
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>));
|
||||
}
|
||||
|
||||
impl<T: HasAttrs> HasAttrs for Spanned<T> {
|
||||
fn attrs(&self) -> &[ast::Attribute] {
|
||||
fn attrs(&self) -> &[Attribute] {
|
||||
self.node.attrs()
|
||||
}
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<ast::Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
self.node.visit_attrs(f);
|
||||
}
|
||||
}
|
||||
@ -674,7 +674,7 @@ impl HasAttrs for Vec<Attribute> {
|
||||
fn attrs(&self) -> &[Attribute] {
|
||||
self
|
||||
}
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
@ -683,7 +683,7 @@ impl HasAttrs for AttrVec {
|
||||
fn attrs(&self) -> &[Attribute] {
|
||||
self
|
||||
}
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
visit_clobber(self, |this| {
|
||||
let mut vec = this.into();
|
||||
f(&mut vec);
|
||||
@ -696,7 +696,7 @@ impl<T: HasAttrs + 'static> HasAttrs for P<T> {
|
||||
fn attrs(&self) -> &[Attribute] {
|
||||
(**self).attrs()
|
||||
}
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
(**self).visit_attrs(f);
|
||||
}
|
||||
}
|
||||
@ -714,7 +714,7 @@ impl HasAttrs for StmtKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
match self {
|
||||
StmtKind::Local(local) => local.visit_attrs(f),
|
||||
StmtKind::Item(..) => {}
|
||||
@ -733,21 +733,11 @@ impl HasAttrs for Stmt {
|
||||
self.kind.attrs()
|
||||
}
|
||||
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<ast::Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
self.kind.visit_attrs(f);
|
||||
}
|
||||
}
|
||||
|
||||
impl HasAttrs for GenericParam {
|
||||
fn attrs(&self) -> &[ast::Attribute] {
|
||||
&self.attrs
|
||||
}
|
||||
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
||||
self.attrs.visit_attrs(f);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! derive_has_attrs {
|
||||
($($ty:path),*) => { $(
|
||||
impl HasAttrs for $ty {
|
||||
@ -755,7 +745,7 @@ macro_rules! derive_has_attrs {
|
||||
&self.attrs
|
||||
}
|
||||
|
||||
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
||||
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<Attribute>)) {
|
||||
self.attrs.visit_attrs(f);
|
||||
}
|
||||
}
|
||||
@ -764,5 +754,5 @@ macro_rules! derive_has_attrs {
|
||||
|
||||
derive_has_attrs! {
|
||||
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::AssocItem, ast::Arm,
|
||||
ast::Field, ast::FieldPat, ast::Variant, ast::Param
|
||||
ast::Field, ast::FieldPat, ast::Variant, ast::Param, GenericParam
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user