Skip to content

Conversation

A4-Tacks
Copy link
Contributor

Fixes:

  • loses label for convert_while_to_loop and convert_for_to_while_let
  • loses attributes for convert_while_to_loop and convert_for_to_while_let
  • bad indent for convert_while_to_loop

Examples

fn main() {
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: while$0 let Some(x) = cond {
        foo();
        break 'a;
    }
}

Before this PR:

fn main() {
    loop {
        if let Some(x) = cond {
            foo();
            break 'a;
        } else {
            break;
        }
    }
}

After this PR:

fn main() {
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: loop {
        if let Some(x) = cond {
            foo();
            break 'a;
        } else {
            break;
        }
    }
}

fn main() {
    let mut x = vec![1, 2, 3];
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: for $0v in x {
        v *= 2;
        break 'a;
    };
}

Before this PR:

fn main() {
    let mut x = vec![1, 2, 3];
    let mut tmp = x.into_iter();
    while let Some(v) = tmp.next() {
        v *= 2;
        break 'a;
    };
}

After this PR:

fn main() {
    let mut x = vec![1, 2, 3];
    let mut tmp = x.into_iter();
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: while let Some(v) = tmp.next() {
        v *= 2;
        break 'a;
    };
}

Fixes:
- loses label for `convert_while_to_loop` and `convert_for_to_while_let`
- loses attributes for `convert_while_to_loop` and `convert_for_to_while_let`
- bad indent for `convert_while_to_loop`

Examples
---
```rust
fn main() {
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: while$0 let Some(x) = cond {
        foo();
        break 'a;
    }
}
```

**Before this PR**:

```rust
fn main() {
    loop {
        if let Some(x) = cond {
            foo();
            break 'a;
        } else {
            break;
        }
    }
}
```

**After this PR**:

```rust
fn main() {
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: loop {
        if let Some(x) = cond {
            foo();
            break 'a;
        } else {
            break;
        }
    }
}
```

---

```rust
fn main() {
    let mut x = vec![1, 2, 3];
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: for $0v in x {
        v *= 2;
        break 'a;
    };
}
```

**Before this PR**:

```rust
fn main() {
    let mut x = vec![1, 2, 3];
    let mut tmp = x.into_iter();
    while let Some(v) = tmp.next() {
        v *= 2;
        break 'a;
    };
}
```

**After this PR**:

```rust
fn main() {
    let mut x = vec![1, 2, 3];
    let mut tmp = x.into_iter();
    #[allow(unused)]
    #[deny(unsafe_code)]
    'a: while let Some(v) = tmp.next() {
        v *= 2;
        break 'a;
    };
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants