diff options
| author | yanglsh <yanglsh@shanghaitech.edu.cn> | 2024-12-28 09:50:52 -0700 |
|---|---|---|
| committer | yanglsh <yanglsh@shanghaitech.edu.cn> | 2025-01-02 07:45:16 -0700 |
| commit | f18399fb69a07571f9a95732be5f6ec6b7517a78 (patch) | |
| tree | 6e416f7a5f780dc36cdf285a05c9e4ab0ef1596f /tests | |
| parent | e582fcd75dda451c68c266d91d538f010f4a9b9f (diff) | |
| download | rust-f18399fb69a07571f9a95732be5f6ec6b7517a78.tar.gz rust-f18399fb69a07571f9a95732be5f6ec6b7517a78.zip | |
Emit redundant if when duplicated in `needless_continue`
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/needless_continue.rs | 26 | ||||
| -rw-r--r-- | tests/ui/needless_continue.stderr | 44 |
2 files changed, 69 insertions, 1 deletions
diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs index bc7233f3ba5..334a2b32775 100644 --- a/tests/ui/needless_continue.rs +++ b/tests/ui/needless_continue.rs @@ -194,6 +194,32 @@ mod issue_4077 { } } } + + for _ in 0..10 { + match "foo".parse::<i32>() { + Ok(_) => do_something(), + Err(_) => { + println!("bar-10"); + continue; + }, + } + } + + loop { + if true { + } else { + // redundant `else` + continue; // redundant `continue` + } + } + + loop { + if some_expr() { + continue; + } else { + do_something(); + } + } } // The contents of these functions are irrelevant, the purpose of this file is diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr index 4ab443108b0..ec39d623419 100644 --- a/tests/ui/needless_continue.stderr +++ b/tests/ui/needless_continue.stderr @@ -168,5 +168,47 @@ LL | continue 'inner; | = help: consider dropping the `continue` expression -error: aborting due to 12 previous errors +error: this `continue` expression is redundant + --> tests/ui/needless_continue.rs:203:21 + | +LL | continue; + | ^^^^^^^^ + | + = help: consider dropping the `continue` expression + +error: this `else` block is redundant + --> tests/ui/needless_continue.rs:210:20 + | +LL | } else { + | ____________________^ +LL | | // redundant `else` +LL | | continue; // redundant `continue` +LL | | } + | |_____________^ + | + = help: consider dropping the `else` clause and merging the code that follows (in the loop) with the `if` block + if true { + // merged code follows: + + } + +error: there is no need for an explicit `else` block for this `if` expression + --> tests/ui/needless_continue.rs:217:13 + | +LL | / if some_expr() { +LL | | continue; +LL | | } else { +LL | | do_something(); +LL | | } + | |_____________^ + | + = help: consider dropping the `else` clause + if some_expr() { + continue; + } + { + do_something(); + } + +error: aborting due to 15 previous errors |
