Skip to content

Commit 6fb91dd

Browse files
committed
Fixed the 'len_zero' clippy warnings
This replaces all the occurrences of the <collection>.len() == 0 with the <collection>.is_empty() and the occurrences of the <collection>.len() > 0 with the !<collection>.is_empty() Relevant clippy warning: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
1 parent 7941480 commit 6fb91dd

7 files changed

Lines changed: 14 additions & 15 deletions

File tree

vm/src/builtins.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ fn builtin_max(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
465465
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
466466
};
467467

468-
if candidates.len() == 0 {
468+
if candidates.is_empty() {
469469
let default = args.get_optional_kwarg("default");
470470
if default.is_none() {
471471
return Err(vm.new_value_error("max() arg is an empty sequence".to_string()));
@@ -516,7 +516,7 @@ fn builtin_min(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
516516
return Err(vm.new_type_error("Expected 1 or more arguments".to_string()));
517517
};
518518

519-
if candidates.len() == 0 {
519+
if candidates.is_empty() {
520520
let default = args.get_optional_kwarg("default");
521521
if default.is_none() {
522522
return Err(vm.new_value_error("min() arg is an empty sequence".to_string()));

vm/src/compile.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ impl Compiler {
11561156
generators: &Vec<ast::Comprehension>,
11571157
) -> Result<(), String> {
11581158
// We must have at least one generator:
1159-
assert!(generators.len() > 0);
1159+
assert!(!generators.is_empty());
11601160

11611161
let name = match kind {
11621162
ast::ComprehensionKind::GeneratorExpression { .. } => "<genexpr>",
@@ -1201,8 +1201,7 @@ impl Compiler {
12011201

12021202
let mut loop_labels = vec![];
12031203
for generator in generators {
1204-
let first = loop_labels.len() == 0;
1205-
if first {
1204+
if loop_labels.is_empty() {
12061205
// Load iterator onto stack (passed as first argument):
12071206
self.emit(Instruction::LoadName {
12081207
name: String::from(".0"),

vm/src/format.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn parse_align(text: &str) -> (Option<FormatAlign>, &str) {
8787

8888
fn parse_fill_and_align(text: &str) -> (Option<char>, Option<FormatAlign>, &str) {
8989
let char_indices: Vec<(usize, char)> = text.char_indices().take(3).collect();
90-
if char_indices.len() == 0 {
90+
if char_indices.is_empty() {
9191
(None, None, text)
9292
} else if char_indices.len() == 1 {
9393
let (maybe_align, remaining) = parse_align(text);
@@ -438,14 +438,14 @@ impl FormatString {
438438
fn parse_literal(text: &str) -> Result<(FormatPart, &str), FormatParseError> {
439439
let mut cur_text = text;
440440
let mut result_string = String::new();
441-
while cur_text.len() > 0 {
441+
while !cur_text.is_empty() {
442442
match FormatString::parse_literal_single(cur_text) {
443443
Ok((next_char, remaining)) => {
444444
result_string.push(next_char);
445445
cur_text = remaining;
446446
}
447447
Err(err) => {
448-
if result_string.len() > 0 {
448+
if !result_string.is_empty() {
449449
return Ok((FormatPart::Literal(result_string.to_string()), cur_text));
450450
} else {
451451
return Err(err);
@@ -467,7 +467,7 @@ impl FormatString {
467467
String::new()
468468
};
469469

470-
if arg_part.len() == 0 {
470+
if arg_part.is_empty() {
471471
return Ok(FormatPart::AutoSpec(format_spec));
472472
}
473473

@@ -500,7 +500,7 @@ impl FormatString {
500500
pub fn from_str(text: &str) -> Result<FormatString, FormatParseError> {
501501
let mut cur_text: &str = text;
502502
let mut parts: Vec<FormatPart> = Vec::new();
503-
while cur_text.len() > 0 {
503+
while !cur_text.is_empty() {
504504
// Try to parse both literals and bracketed format parts util we
505505
// run out of text
506506
cur_text = FormatString::parse_literal(cur_text)

vm/src/obj/objset.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn set_repr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9898
arg_check!(vm, args, required = [(o, Some(vm.ctx.set_type()))]);
9999

100100
let elements = get_elements(o);
101-
let s = if elements.len() == 0 {
101+
let s = if elements.is_empty() {
102102
"set()".to_string()
103103
} else {
104104
let mut str_parts = vec![];
@@ -136,7 +136,7 @@ fn frozenset_repr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
136136
arg_check!(vm, args, required = [(o, Some(vm.ctx.frozenset_type()))]);
137137

138138
let elements = get_elements(o);
139-
let s = if elements.len() == 0 {
139+
let s = if elements.is_empty() {
140140
"frozenset()".to_string()
141141
} else {
142142
let mut str_parts = vec![];

vm/src/obj/objstr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn str_add(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
208208
}
209209

210210
fn str_format(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
211-
if args.args.len() == 0 {
211+
if args.args.is_empty() {
212212
return Err(
213213
vm.new_type_error("descriptor 'format' of 'str' object needs an argument".to_string())
214214
);

vm/src/stdlib/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn io_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
295295
.filter(|a| raw_modes.contains(&a.to_string()))
296296
.collect();
297297

298-
if modes.len() == 0 || modes.len() > 1 {
298+
if modes.is_empty() || modes.len() > 1 {
299299
return Err(vm.new_value_error("Invalid Mode".to_string()));
300300
}
301301

vm/src/stdlib/pystruct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn pack_f64(
169169
}
170170

171171
fn struct_pack(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
172-
if args.args.len() < 1 {
172+
if args.args.is_empty() {
173173
Err(vm.new_type_error(format!(
174174
"Expected at least 1 argument (got: {})",
175175
args.args.len()

0 commit comments

Comments
 (0)