forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#5656 - ebroto:len_zero_ranges, r=matthiaskrgr
len_zero: skip ranges if feature `range_is_empty` is not enabled If the feature is not enabled, calling `is_empty()` on a range is ambiguous. Moreover, the two possible resolutions are unstable methods, one inherent to the range and the other being part of the `ExactSizeIterator` trait. Since `len_zero` only checks for existing `is_empty()` inherent methods, we only take into account the `range_is_empty` feature. Related: rust-lang#48111 (comment) changelog: len_zero: avoid linting ranges without #![feature(range_is_empty)] Fixes: rust-lang#3807
- Loading branch information
Showing
6 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// run-rustfix | ||
|
||
#![feature(range_is_empty)] | ||
#![warn(clippy::len_zero)] | ||
#![allow(unused)] | ||
|
||
mod issue_3807 { | ||
// With the feature enabled, `is_empty` should be suggested | ||
fn suggestion_is_fine() { | ||
let _ = (0..42).is_empty(); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// run-rustfix | ||
|
||
#![feature(range_is_empty)] | ||
#![warn(clippy::len_zero)] | ||
#![allow(unused)] | ||
|
||
mod issue_3807 { | ||
// With the feature enabled, `is_empty` should be suggested | ||
fn suggestion_is_fine() { | ||
let _ = (0..42).len() == 0; | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: length comparison to zero | ||
--> $DIR/len_zero_ranges.rs:10:17 | ||
| | ||
LL | let _ = (0..42).len() == 0; | ||
| ^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `(0..42).is_empty()` | ||
| | ||
= note: `-D clippy::len-zero` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|