parent
0acc0a2989
commit
9344d2ca83
1 changed files with 10 additions and 11 deletions
21
src/attr.rs
21
src/attr.rs
|
@ -98,13 +98,16 @@ fn take_while_with_pred<'a, P>(
|
||||||
where
|
where
|
||||||
P: Fn(&ast::Attribute) -> bool,
|
P: Fn(&ast::Attribute) -> bool,
|
||||||
{
|
{
|
||||||
let mut last_index = 0;
|
let mut len = 0;
|
||||||
let mut iter = attrs.iter().enumerate().peekable();
|
let mut iter = attrs.iter().peekable();
|
||||||
while let Some((i, attr)) = iter.next() {
|
|
||||||
if !pred(attr) {
|
while let Some(attr) = iter.next() {
|
||||||
|
if pred(attr) {
|
||||||
|
len += 1;
|
||||||
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if let Some(&(_, next_attr)) = iter.peek() {
|
if let Some(next_attr) = iter.peek() {
|
||||||
// Extract comments between two attributes.
|
// Extract comments between two attributes.
|
||||||
let span_between_attr = mk_sp(attr.span.hi(), next_attr.span.lo());
|
let span_between_attr = mk_sp(attr.span.hi(), next_attr.span.lo());
|
||||||
let snippet = context.snippet(span_between_attr);
|
let snippet = context.snippet(span_between_attr);
|
||||||
|
@ -112,13 +115,9 @@ where
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last_index = i;
|
|
||||||
}
|
|
||||||
if last_index == 0 {
|
|
||||||
&[]
|
|
||||||
} else {
|
|
||||||
&attrs[..last_index + 1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&attrs[..len]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rewrite the same kind of attributes at the same time. This includes doc
|
/// Rewrite the same kind of attributes at the same time. This includes doc
|
||||||
|
|
Loading…
Reference in a new issue