diff options
| author | bors <bors@rust-lang.org> | 2024-07-27 15:23:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-27 15:23:21 +0000 |
| commit | d20be39c7f904ba4e648dce3f82e776a5421bb71 (patch) | |
| tree | 6c8d2e3f949b8195996bb2bdb7fb72a932d56489 /tests | |
| parent | 92768eeac4af6fb31bdaf94b9844a6455750926e (diff) | |
| parent | 0cdf6e172cb861387d41ad01540a321a1e09c1b4 (diff) | |
| download | rust-d20be39c7f904ba4e648dce3f82e776a5421bb71.tar.gz rust-d20be39c7f904ba4e648dce3f82e776a5421bb71.zip | |
Auto merge of #13149 - jusexton:issue-13123, r=dswij
Fix while_let_on_iterator dropping loop label when applying fix. Loop label was not persisted when displaying help and was therefore producing broken rust code when applying fixes. Solution was to store the `ast::Label` when creating a `higher::WhileLet` from an expression and add the label name to the lint suggestion and diagnostics. --- Fixes: https://github.com/rust-lang/rust-clippy/issues/13123 changelog: [`while_let_on_iterator`]: Fix issue dropping loop label when displaying help and applying fixes.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/while_let_on_iterator.fixed | 9 | ||||
| -rw-r--r-- | tests/ui/while_let_on_iterator.rs | 9 | ||||
| -rw-r--r-- | tests/ui/while_let_on_iterator.stderr | 8 |
3 files changed, 25 insertions, 1 deletions
diff --git a/tests/ui/while_let_on_iterator.fixed b/tests/ui/while_let_on_iterator.fixed index 59b5c858d04..b8087c6e000 100644 --- a/tests/ui/while_let_on_iterator.fixed +++ b/tests/ui/while_let_on_iterator.fixed @@ -456,6 +456,15 @@ fn fn_once_closure() { }); } +fn issue13123() { + let mut it = 0..20; + 'label: for n in it { + if n % 25 == 0 { + break 'label; + } + } +} + fn main() { let mut it = 0..20; for _ in it { diff --git a/tests/ui/while_let_on_iterator.rs b/tests/ui/while_let_on_iterator.rs index 559513d5694..8e02f59b512 100644 --- a/tests/ui/while_let_on_iterator.rs +++ b/tests/ui/while_let_on_iterator.rs @@ -456,6 +456,15 @@ fn fn_once_closure() { }); } +fn issue13123() { + let mut it = 0..20; + 'label: while let Some(n) = it.next() { + if n % 25 == 0 { + break 'label; + } + } +} + fn main() { let mut it = 0..20; while let Some(..) = it.next() { diff --git a/tests/ui/while_let_on_iterator.stderr b/tests/ui/while_let_on_iterator.stderr index 8ff1f23644b..d96b26acf34 100644 --- a/tests/ui/while_let_on_iterator.stderr +++ b/tests/ui/while_let_on_iterator.stderr @@ -160,8 +160,14 @@ LL | while let Some(x) = it.next() { error: this loop could be written as a `for` loop --> tests/ui/while_let_on_iterator.rs:461:5 | +LL | 'label: while let Some(n) = it.next() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `'label: for n in it` + +error: this loop could be written as a `for` loop + --> tests/ui/while_let_on_iterator.rs:470:5 + | LL | while let Some(..) = it.next() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it` -error: aborting due to 27 previous errors +error: aborting due to 28 previous errors |
