Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Clippy #115790

Merged
merged 119 commits into from
Sep 13, 2023
Merged
Changes from 5 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
f76615a
New chapter: Emitting lints
blyxyas Apr 5, 2023
8277e7d
Don't pass extra generic arguments in `needless_borrow`
Jarcho Jul 30, 2023
f746e19
allow trait alias DefIds in `implements_trait_with_env_from_iter`
y21 Aug 14, 2023
3c50a0a
Add new chapter: "Trait Checking"
blyxyas Apr 10, 2023
94387ef
Fixes based on reviews
blyxyas Apr 18, 2023
b2e1ede
Change Tokio example description to Core
blyxyas Apr 19, 2023
2a3f75b
Fix CI
blyxyas Apr 19, 2023
289bafa
New chapter: Writing tests
blyxyas Apr 3, 2023
864df49
Formatting, slimming and ui-toml tests
flip1995 Apr 16, 2023
32dc7c5
Applying review suggestions
flip1995 Aug 18, 2023
9b8b835
Formatting and minor wording fixes
flip1995 Aug 18, 2023
8ee6ca0
Update rustfix section to new ui-test crate
flip1995 Aug 18, 2023
7721567
fix [`undocumented_unsafe_blocks`] not able to detect comment for glo…
J-ZhengLi Aug 22, 2023
82f2e52
Fix span when linting `explicit_auto_deref` immediately after `needle…
Jarcho Aug 22, 2023
42c6492
[`unnecessary_unwrap`]: lint on `.as_ref().unwrap()`
y21 Aug 23, 2023
fb6fad2
[`iter_overeager_cloned`]: detect .cloned().all() and .cloned().any()
lengyijun Aug 20, 2023
70f6321
when terminating during unwinding, show the reason why
RalfJung Aug 21, 2023
2faa43c
[arithmetic_side_effects] Fix #11393
c410-f3r Aug 24, 2023
d802ab2
Dogfood
c410-f3r Aug 24, 2023
86b6644
new lint: `iter_out_of_bounds`
y21 Aug 24, 2023
cc61aee
Merge commit '080b587854a73f2a8cbaecff1884860a78e2ff37' into clippyup
flip1995 Aug 24, 2023
d65c459
Auto merge of #11360 - lengyijun:any_all, r=blyxyas
bors Aug 24, 2023
dba7763
[`if_then_some_else_none`]: look into local initializers
y21 Aug 24, 2023
19eaafb
Auto merge of #11338 - y21:issue11337, r=Centri3
bors Aug 24, 2023
11072b5
lint vecs, version bump, more tests
y21 Aug 24, 2023
706c48b
Auto merge of #11395 - c410-f3r:let-chain, r=Manishearth
bors Aug 25, 2023
6eec4a3
remove unecessary code
J-ZhengLi Aug 25, 2023
90fcc67
fix "derivable_impls: attributes are ignored"
kiscad Aug 25, 2023
e43c234
allow float_cmp when lhs is a custom type
markhuang1212 Aug 23, 2023
d78d26a
Remove redundant auxiliary test files
Alexendoo Aug 25, 2023
f80c55d
add a test for statics and doc comments
y21 Aug 25, 2023
7ff8716
Typo
smoelius Aug 25, 2023
d2f6522
update uitest enum_clike_unportable_variant
kiscad Aug 24, 2023
4736908
Auto merge of #11404 - mojave2:issue-11368, r=matthiaskrgr
bors Aug 26, 2023
74a46a7
Auto merge of #11391 - mojave2:fix-uitest-enum_clike_unportable_varia…
bors Aug 26, 2023
8c20739
Auto merge of #11411 - smoelius:patch-1, r=Alexendoo
bors Aug 26, 2023
33cc140
add more negative tests
y21 Aug 27, 2023
8de52e5
Auto merge of #11405 - Alexendoo:redundant-aux, r=giraffate
bors Aug 28, 2023
be55a96
Add config flag for reborrows in explicit_iter_loop
Benjscho Aug 28, 2023
4118738
Auto merge of #11401 - y21:issue11394, r=xFrednet
bors Aug 28, 2023
5cc5f27
Auto merge of #11385 - markhuang1212:master, r=blyxyas
bors Aug 28, 2023
b97eaab
Auto merge of #11387 - y21:issue11371, r=blyxyas
bors Aug 28, 2023
6a876f2
Bump ui_test
oli-obk Aug 29, 2023
af02b43
Auto merge of #115183 - flip1995:clippyup, r=Manishearth,oli-obk
bors Aug 29, 2023
11d8e55
Bump ui_test to 0.18.1
oli-obk Aug 30, 2023
6eb7a46
Documentation Formatting
TDecking Aug 30, 2023
1f8b204
Second instance of `vec!` with parenthesis.
TDecking Aug 30, 2023
3da21b0
Auto merge of #11396 - y21:issue11345, r=Jarcho
bors Aug 30, 2023
563abf9
[`implied_bounds_in_impls`]: move to nursery and fix ICEs
y21 Aug 30, 2023
55bd0fe
Fix metadata collection
Benjscho Aug 30, 2023
c50d86f
Auto merge of #11418 - Benjscho:explicit_iter_loop_config, r=llogiq
bors Aug 31, 2023
77e395e
Auto merge of #11376 - Jarcho:issue_11366, r=llogiq
bors Aug 31, 2023
299fbce
Check binary operators and attributes in disallowed_macros
Alexendoo Aug 31, 2023
b54bac9
new lint: `missing_assert_for_indexing`
y21 Apr 21, 2023
790922c
update ui tests and some minor cleanups
y21 Aug 31, 2023
79c684d
Auto merge of #10692 - y21:missing-asserts, r=Alexendoo
bors Aug 31, 2023
c1f8ae3
Auto merge of #11430 - TDecking:vec-fmt, r=giraffate
bors Sep 1, 2023
b3136a8
[`clippy`] Use symbols intended for `arithmetic_side_effects`
c410-f3r Aug 31, 2023
aeed86c
Bump ui_test to 0.20
oli-obk Aug 31, 2023
acdffd7
Auto merge of #11427 - oli-obk:ui_test_bump, r=Alexendoo
bors Sep 1, 2023
f595f1e
Use multipart suggestions for raw string lints
Alexendoo Aug 27, 2023
a8b5245
Auto merge of #11416 - Alexendoo:raw-strings-multipart, r=xFrednet
bors Sep 1, 2023
b0eaa84
fix some comments
cuishuang Sep 1, 2023
f5efade
Merge from rustc
RalfJung Sep 2, 2023
6801189
Rewrite `never_loop` as a strict reachability pass
digama0 Sep 2, 2023
e1a3f63
Apply suggestion
blyxyas Sep 2, 2023
aa371eb
Auto merge of #10596 - blyxyas:book-write_tests, r=flip1995
bors Sep 2, 2023
79e31cb
DefaultUnionRepresentation: explain why we only warn about unions wit…
RalfJung Sep 2, 2023
a26937f
Fix links
blyxyas Sep 2, 2023
3cf1087
Auto merge of #10598 - blyxyas:book-emit_lints, r=flip1995
bors Sep 2, 2023
a45feda
Auto merge of #11445 - cuishuang:master, r=Centri3
bors Sep 2, 2023
7cf96da
Auto merge of #11448 - RalfJung:DefaultUnionRepresentation, r=blyxyas
bors Sep 2, 2023
92d47db
Add `emitting_lints` link to `Writing tests` and remove that `FIXME`
blyxyas Aug 18, 2023
b65e544
Auto merge of #10626 - blyxyas:book-trait_checking, r=flip1995
bors Sep 2, 2023
39b316d
an empty match diverges
digama0 Sep 2, 2023
b3980d8
catch never loops through diverging functions
digama0 Sep 2, 2023
44f64ac
`never_loop` catches `loop { panic!() }`
digama0 Sep 2, 2023
b9906ac
Auto merge of #11450 - digama0:never_loop2, r=llogiq
bors Sep 2, 2023
78983d9
[`slow_vector_initialization`]: use the source span of `vec![]` macro
y21 Sep 2, 2023
5120632
[`slow_vector_initialization`]: only warn on `vec![]` expn
y21 Sep 2, 2023
61a2f97
skip `todo` / `unimplemented` in `never_loop`
digama0 Sep 3, 2023
a0ebcc3
Merge from rustc
RalfJung Sep 3, 2023
e0014af
Add suggestions for std_instead_of_core
tom-anders Sep 3, 2023
c317077
Use relative positions inside a SourceFile.
cjgillot Sep 3, 2023
d5f0f44
Fix clippy.
cjgillot Sep 3, 2023
1317378
fix todo item check, remove unimplemented
digama0 Sep 3, 2023
3de0f19
Auto merge of #11437 - y21:issue-11422, r=xFrednet
bors Sep 3, 2023
7262145
[`implied_bounds_in_impl`]: fix suggestion for assoc types
y21 Sep 3, 2023
60a18b7
Auto merge of #11449 - blyxyas:book-write_tests, r=flip1995
bors Sep 3, 2023
32e2511
extract lint emitting into separate fn
y21 Sep 3, 2023
f13e1f4
Auto merge of #11259 - Jarcho:ice_10253, r=dswij
bors Sep 4, 2023
4e0a346
fix vec.rs test, comment
digama0 Sep 4, 2023
da882f0
Auto merge of #11455 - digama0:never_loop3, r=Centri3,dswij
bors Sep 4, 2023
bcf856b
Auto merge of #11375 - J-ZhengLi:issue11246, r=Centri3
bors Sep 4, 2023
a86e758
Adjust clippy tests with new rustc help suggestion for lints
Urgau Aug 1, 2023
822c7df
Add ui_test error annotations in existing tests
samueltardieu Sep 4, 2023
2f5c445
Ignore wildcards in function arguments and local bindings
samueltardieu Sep 2, 2023
eb0df1d
Auto merge of #11454 - samueltardieu:issue-11403, r=Centri3
bors Sep 5, 2023
bbf67c3
Preserve literals and range kinds in `manual_range_patterns`
Alexendoo Sep 4, 2023
30846b1
add comments in code to clarify and fix typo
y21 Sep 5, 2023
953901e
Auto merge of #115507 - cjgillot:relative-source-file, r=oli-obk
bors Sep 5, 2023
0d36d57
Auto merge of #11439 - Alexendoo:disallowed-macros-bins-attrs, r=xFre…
bors Sep 6, 2023
60ffff0
Fix i686-unknown-linux-gnu CI job
Alexendoo Sep 6, 2023
69fcbfd
Auto merge of #11466 - Alexendoo:ci-32bit, r=flip1995
bors Sep 6, 2023
415ba21
Auto merge of #11451 - y21:issue11408, r=xFrednet
bors Sep 7, 2023
6150bf5
Auto merge of #11462 - Alexendoo:manual-range-patterns-preserve-liter…
bors Sep 7, 2023
d2b0843
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Sep 7, 2023
d780573
Bump nightly version -> 2023-09-07
flip1995 Sep 7, 2023
25e8639
Fix clippy driver stderr test
flip1995 Sep 7, 2023
184c971
Fix 32bit tests
flip1995 Sep 7, 2023
253f1c4
Auto merge of #11469 - flip1995:rustup, r=flip1995
bors Sep 7, 2023
b99921a
Rename incorrect_impls to non_canonical_impls, move them to warn by d…
Alexendoo Sep 8, 2023
27165ac
Auto merge of #11456 - tom-anders:std_instead_of_core_suggestion, r=M…
bors Sep 8, 2023
ec6f1bd
Auto merge of #11358 - Alexendoo:incorrect-to-manual-impls, r=Jarcho
bors Sep 9, 2023
8c48b93
Auto merge of #11459 - y21:issue11435, r=blyxyas
bors Sep 9, 2023
c548d11
Auto deref does not apply on union field
samueltardieu Sep 10, 2023
98363cb
Auto merge of #11477 - samueltardieu:11474, r=xFrednet
bors Sep 11, 2023
9ff2e4e
Merge commit '98363cbf6a7c3f8b571a7d92a3c645bb4376e4a6' into clippyup
flip1995 Sep 12, 2023
780cbf3
Update Cargo.lock (ui_test update)
flip1995 Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 128 additions & 128 deletions clippy_lints/src/loops/never_loop.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/ui/crashes/ice-360.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@ fn main() {}
fn no_panic<T>(slice: &[T]) {
let mut iter = slice.iter();
loop {
//~^ ERROR: this loop could be written as a `while let` loop
//~^ ERROR: this loop never actually loops
//~| ERROR: this loop could be written as a `while let` loop
//~| NOTE: `-D clippy::while-let-loop` implied by `-D warnings`
let _ = match iter.next() {
Some(ele) => ele,
20 changes: 17 additions & 3 deletions tests/ui/crashes/ice-360.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
error: this loop never actually loops
--> $DIR/ice-360.rs:5:5
|
LL | / loop {
LL | |
LL | |
LL | |
... |
LL | |
LL | | }
| |_____^
|
= note: `#[deny(clippy::never_loop)]` on by default

error: this loop could be written as a `while let` loop
--> $DIR/ice-360.rs:5:5
|
LL | / loop {
LL | |
LL | |
LL | | let _ = match iter.next() {
LL | |
... |
LL | |
LL | | }
@@ -13,13 +27,13 @@ LL | | }
= note: `-D clippy::while-let-loop` implied by `-D warnings`

error: empty `loop {}` wastes CPU cycles
--> $DIR/ice-360.rs:12:9
--> $DIR/ice-360.rs:13:9
|
LL | loop {}
| ^^^^^^^
|
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
= note: `-D clippy::empty-loop` implied by `-D warnings`

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

3 changes: 3 additions & 0 deletions tests/ui/empty_loop.rs
Original file line number Diff line number Diff line change
@@ -7,17 +7,20 @@ use proc_macros::{external, inline_macros};

fn should_trigger() {
loop {}
#[allow(clippy::never_loop)]
loop {
loop {}
}

#[allow(clippy::never_loop)]
'outer: loop {
'inner: loop {}
}
}

#[inline_macros]
fn should_not_trigger() {
#[allow(clippy::never_loop)]
loop {
panic!("This is fine")
}
4 changes: 2 additions & 2 deletions tests/ui/empty_loop.stderr
Original file line number Diff line number Diff line change
@@ -8,15 +8,15 @@ LL | loop {}
= note: `-D clippy::empty-loop` implied by `-D warnings`

error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop.rs:11:9
--> $DIR/empty_loop.rs:12:9
|
LL | loop {}
| ^^^^^^^
|
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body

error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop.rs:15:9
--> $DIR/empty_loop.rs:17:9
|
LL | 'inner: loop {}
| ^^^^^^^^^^^^^^^
1 change: 1 addition & 0 deletions tests/ui/iter_out_of_bounds.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ fn opaque_empty_iter() -> impl Iterator<Item = ()> {
}

fn main() {
#[allow(clippy::never_loop)]
for _ in [1, 2, 3].iter().skip(4) {
//~^ ERROR: this `.skip()` call skips more items than the iterator will produce
unreachable!();
28 changes: 14 additions & 14 deletions tests/ui/iter_out_of_bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:11:14
--> $DIR/iter_out_of_bounds.rs:12:14
|
LL | for _ in [1, 2, 3].iter().skip(4) {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,103 +12,103 @@ LL | #![deny(clippy::iter_out_of_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this `.take()` call takes more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:15:19
--> $DIR/iter_out_of_bounds.rs:16:19
|
LL | for (i, _) in [1, 2, 3].iter().take(4).enumerate() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and the returned iterator will simply yield the same items

error: this `.take()` call takes more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:21:14
--> $DIR/iter_out_of_bounds.rs:22:14
|
LL | for _ in (&&&&&&[1, 2, 3]).iter().take(4) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and the returned iterator will simply yield the same items

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:24:14
--> $DIR/iter_out_of_bounds.rs:25:14
|
LL | for _ in [1, 2, 3].iter().skip(4) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:27:14
--> $DIR/iter_out_of_bounds.rs:28:14
|
LL | for _ in [1; 3].iter().skip(4) {}
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:33:14
--> $DIR/iter_out_of_bounds.rs:34:14
|
LL | for _ in vec![1, 2, 3].iter().skip(4) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:36:14
--> $DIR/iter_out_of_bounds.rs:37:14
|
LL | for _ in vec![1; 3].iter().skip(4) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:40:14
--> $DIR/iter_out_of_bounds.rs:41:14
|
LL | for _ in x.iter().skip(4) {}
| ^^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:44:14
--> $DIR/iter_out_of_bounds.rs:45:14
|
LL | for _ in x.iter().skip(n) {}
| ^^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:49:14
--> $DIR/iter_out_of_bounds.rs:50:14
|
LL | for _ in empty().skip(1) {}
| ^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.take()` call takes more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:52:14
--> $DIR/iter_out_of_bounds.rs:53:14
|
LL | for _ in empty().take(1) {}
| ^^^^^^^^^^^^^^^
|
= note: this operation is useless and the returned iterator will simply yield the same items

error: this `.skip()` call skips more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:55:14
--> $DIR/iter_out_of_bounds.rs:56:14
|
LL | for _ in std::iter::once(1).skip(2) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and will create an empty iterator

error: this `.take()` call takes more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:58:14
--> $DIR/iter_out_of_bounds.rs:59:14
|
LL | for _ in std::iter::once(1).take(2) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this operation is useless and the returned iterator will simply yield the same items

error: this `.take()` call takes more items than the iterator will produce
--> $DIR/iter_out_of_bounds.rs:61:14
--> $DIR/iter_out_of_bounds.rs:62:14
|
LL | for x in [].iter().take(1) {
| ^^^^^^^^^^^^^^^^^
6 changes: 6 additions & 0 deletions tests/ui/needless_collect_indirect.rs
Original file line number Diff line number Diff line change
@@ -260,6 +260,7 @@ mod issue_8553 {
let w = v.iter().collect::<Vec<_>>();
//~^ ERROR: avoid using `collect()` when not needed
// Do lint
#[allow(clippy::never_loop)]
for _ in 0..w.len() {
todo!();
}
@@ -270,6 +271,7 @@ mod issue_8553 {
let v: Vec<usize> = vec.iter().map(|i| i * i).collect();
let w = v.iter().collect::<Vec<_>>();
// Do not lint, because w is used.
#[allow(clippy::never_loop)]
for _ in 0..w.len() {
todo!();
}
@@ -283,6 +285,7 @@ mod issue_8553 {
let mut w = v.iter().collect::<Vec<_>>();
//~^ ERROR: avoid using `collect()` when not needed
// Do lint
#[allow(clippy::never_loop)]
while 1 == w.len() {
todo!();
}
@@ -293,6 +296,7 @@ mod issue_8553 {
let mut v: Vec<usize> = vec.iter().map(|i| i * i).collect();
let mut w = v.iter().collect::<Vec<_>>();
// Do not lint, because w is used.
#[allow(clippy::never_loop)]
while 1 == w.len() {
todo!();
}
@@ -306,6 +310,7 @@ mod issue_8553 {
let mut w = v.iter().collect::<Vec<_>>();
//~^ ERROR: avoid using `collect()` when not needed
// Do lint
#[allow(clippy::never_loop)]
while let Some(i) = Some(w.len()) {
todo!();
}
@@ -316,6 +321,7 @@ mod issue_8553 {
let mut v: Vec<usize> = vec.iter().map(|i| i * i).collect();
let mut w = v.iter().collect::<Vec<_>>();
// Do not lint, because w is used.
#[allow(clippy::never_loop)]
while let Some(i) = Some(w.len()) {
todo!();
}
7 changes: 5 additions & 2 deletions tests/ui/needless_collect_indirect.stderr
Original file line number Diff line number Diff line change
@@ -230,11 +230,12 @@ help: take the original Iterator's count instead of collecting it and finding th
LL ~
LL |
LL | // Do lint
LL | #[allow(clippy::never_loop)]
LL ~ for _ in 0..v.iter().count() {
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:283:30
--> $DIR/needless_collect_indirect.rs:285:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -247,11 +248,12 @@ help: take the original Iterator's count instead of collecting it and finding th
LL ~
LL |
LL | // Do lint
LL | #[allow(clippy::never_loop)]
LL ~ while 1 == v.iter().count() {
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:306:30
--> $DIR/needless_collect_indirect.rs:310:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -264,6 +266,7 @@ help: take the original Iterator's count instead of collecting it and finding th
LL ~
LL |
LL | // Do lint
LL | #[allow(clippy::never_loop)]
LL ~ while let Some(i) = Some(v.iter().count()) {
|

47 changes: 45 additions & 2 deletions tests/ui/never_loop.rs
Original file line number Diff line number Diff line change
@@ -337,10 +337,8 @@ pub fn test26() {

pub fn test27() {
loop {
//~^ ERROR: this loop never actually loops
'label: {
let x = true;
// Lints because we cannot prove it's always `true`
if x {
break 'label;
}
@@ -349,6 +347,51 @@ pub fn test27() {
}
}

// issue 11004
pub fn test29() {
loop {
'label: {
if true {
break 'label;
}
return;
}
}
}

pub fn test30() {
'a: loop {
'b: {
for j in 0..2 {
if j == 1 {
break 'b;
}
}
break 'a;
}
}
}

pub fn test31(b: bool) {
'a: loop {
'b: {
'c: loop {
//~^ ERROR: this loop never actually loops
if b { break 'c } else { break 'b }
}
continue 'a;
}
break 'a;
}
}

pub fn test32(b: bool) {
loop {
//~^ ERROR: this loop never actually loops
panic!("oh no");
}
}

fn main() {
test1();
test2();
18 changes: 12 additions & 6 deletions tests/ui/never_loop.stderr
Original file line number Diff line number Diff line change
@@ -153,16 +153,22 @@ LL | if let Some(_) = (0..20).next() {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: this loop never actually loops
--> $DIR/never_loop.rs:339:5
--> $DIR/never_loop.rs:378:13
|
LL | / 'c: loop {
LL | |
LL | | if b { break 'c } else { break 'b }
LL | | }
| |_____________^

error: this loop never actually loops
--> $DIR/never_loop.rs:389:5
|
LL | / loop {
LL | |
LL | | 'label: {
LL | | let x = true;
... |
LL | | }
LL | | panic!("oh no");
LL | | }
| |_____^

error: aborting due to 14 previous errors
error: aborting due to 15 previous errors

Loading