/// Removes matching attributes, parses them, and then allows visiting them.
///
/// This returns the most appropriate span to reference the original attributes.
Removes matching attributes, parses them, and then allows visiting them.
This returns the most appropriate span to reference the original attributes.
Removes matching attributes parses them and then allows visiting them . This returns the most appropriate span to reference the original attributes .
pub(crate) fn visit_matching_attrs_parsed<ParsedAttr: Parse>(
    attributes: &mut Vec<Attribute>,
    mut filter: impl FnMut(&mut Attribute) -> bool,
    mut visit: impl FnMut(ParsedAttr, Span),
) -> Option<Span> {
    let mut span_of_all: Option<Span> = None;
    let mut i = 0;
    // TODO: use `drain_filter` once it's stabilized (see
    // https://github.com/rust-lang/rust/issues/43244).
    while i < attributes.len() {
        if filter(&mut attributes[i]) {
            let attr = attributes.remove(i);
            // This should never fail on nightly, where joining is supported.
            // On stable, it'll use the better `bracket_token` span instead of the default `#` span
            // returned by `attr.span()`.
            let span = attr
                .span()
                .join(attr.bracket_token.span)
                .unwrap_or_else(|| attr.bracket_token.span);
            span_of_all = Some(match span_of_all.take() {
                Some(old_span) => old_span.join(span).unwrap_or_else(|| span),
                None => span,
            });
            match syn::parse2::<ParsedAttr>(attr.tokens) {
                Ok(parsed_attr) => visit(parsed_attr, span),
                Err(err) => emit_error!(err),
            }
        } else {
            i += 1;
        }
    }
    span_of_all
}
pub ( crate ) fn visit_matching_attrs_parsed < ParsedAttr : Parse > ( attributes : & mut Vec < Attribute > , mut filter : impl FnMut ( & mut Attribute ) -> bool , mut visit : impl FnMut ( ParsedAttr , Span ) , ) -> Option < Span > { let mut span_of_all : Option < Span > = None ; let mut i = 0 ; // TODO: use `drain_filter` once it's stabilized (see // https://github.com/rust-lang/rust/issues/43244). while i < attributes . len ( ) { if filter ( & mut attributes [ i ] ) { let attr = attributes . remove ( i ) ; // This should never fail on nightly, where joining is supported. // On stable, it'll use the better `bracket_token` span instead of the default `#` span // returned by `attr.span()`. let span = attr . span ( ) . join ( attr . bracket_token . span ) . unwrap_or_else ( | | attr . bracket_token . span ) ; span_of_all = Some ( match span_of_all . take ( ) { Some ( old_span ) => old_span . join ( span ) . unwrap_or_else ( | | span ) , None => span , } ) ; match syn :: parse2 :: < ParsedAttr > ( attr . tokens ) { Ok ( parsed_attr ) => visit ( parsed_attr , span ) , Err ( err ) => emit_error ! ( err ) , } } else { i += 1 ; } } span_of_all }
Removes matching attributes, parses them, and then allows visiting them.
Removes matching attributes parses them and then allows visiting them .
attributes
&mut Vec<Attribute>
filter
impl FnMut(&mut Attribute) -> bool
visit
impl FnMut(ParsedAttr, Span)