/// If `item` is an attribute invocation, remove the attribute and return it together with
/// its position and derives following it. We have to collect the derives in order to resolve
/// legacy derive helpers (helpers written before derives that introduce them).
If `item` is an attribute invocation, remove the attribute and return it together with
its position and derives following it. We have to collect the derives in order to resolve
legacy derive helpers (helpers written before derives that introduce them).
If ` item ` is an attribute invocation remove the attribute and return it together with its position and derives following it . We have to collect the derives in order to resolve legacy derive helpers ( helpers written before derives that introduce them ) .
fn take_first_attr(
        &mut self,
        item: &mut impl AstLike,
    ) -> Option<(ast::Attribute, usize, Vec<Path>)> {
        let mut attr = None;
        item.visit_attrs(|attrs| {
            attr = attrs
                .iter()
                .position(|a| !self.cx.expanded_inert_attrs.is_marked(a) && !is_builtin_attr(a))
                .map(|attr_pos| {
                    let attr = attrs.remove(attr_pos);
                    let following_derives = attrs[attr_pos..]
                        .iter()
                        .filter(|a| a.has_name(sym::derive))
                        .flat_map(|a| a.meta_item_list().unwrap_or_default())
                        .filter_map(|nested_meta| match nested_meta {
                            NestedMetaItem::MetaItem(ast::MetaItem {
                                kind: MetaItemKind::Word,
                                path,
                                ..
                            }) => Some(path),
                            _ => None,
                        })
                        .collect();
                    (attr, attr_pos, following_derives)
                })
        });
        attr
    }
fn take_first_attr ( & mut self , item : & mut impl AstLike , ) -> Option < ( ast :: Attribute , usize , Vec < Path > ) > { let mut attr = None ; item . visit_attrs ( | attrs | { attr = attrs . iter ( ) . position ( | a | ! self . cx . expanded_inert_attrs . is_marked ( a ) && ! is_builtin_attr ( a ) ) . map ( | attr_pos | { let attr = attrs . remove ( attr_pos ) ; let following_derives = attrs [ attr_pos .. ] . iter ( ) . filter ( | a | a . has_name ( sym :: derive ) ) . flat_map ( | a | a . meta_item_list ( ) . unwrap_or_default ( ) ) . filter_map ( | nested_meta | match nested_meta { NestedMetaItem :: MetaItem ( ast :: MetaItem { kind : MetaItemKind :: Word , path , .. } ) => Some ( path ) , _ => None , } ) . collect ( ) ; ( attr , attr_pos , following_derives ) } ) } ) ; attr }
If `item` is an attribute invocation, remove the attribute and return it together with
its position and derives following it.
If ` item ` is an attribute invocation remove the attribute and return it together with its position and derives following it .
&mut self
item
&mut impl AstLike