Skip to content

Commit

Permalink
Fix a case of iterator invalidation when moving #[doc] attributes (#…
Browse files Browse the repository at this point in the history
…1272)

This fixes index-based iterator invalidation when `#[doc]` attributes are being moved to the `cooked` list to prevent the `#[help]` macro from rejecting them. Without this, a panic would occur.
  • Loading branch information
arqunis committed Mar 30, 2021
1 parent 8ab0305 commit 166c248
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions command_attr/src/lib.rs
Expand Up @@ -297,9 +297,15 @@ pub fn help(attr: TokenStream, input: TokenStream) -> TokenStream {

// Additionally, place the documentation attributes to the `cooked` list
// to prevent the macro from rejecting them as invalid attributes.
for i in 0..fun.attributes.len() {
if fun.attributes[i].path.is_ident("doc") {
fun.cooked.push(fun.attributes.remove(i));
{
let mut i = 0;
while i < fun.attributes.len() {
if fun.attributes[i].path.is_ident("doc") {
fun.cooked.push(fun.attributes.remove(i));
continue;
}

i += 1;
}
}

Expand Down

0 comments on commit 166c248

Please sign in to comment.