Skip to content

Commit b4d9722

Browse files
committed
Negative case of len() -> is_empty()
`s/([^\(\s]+\.)len\(\) [(?:!=)>] 0/!$1is_empty()/g`
1 parent decb5e5 commit b4d9722

File tree

62 files changed

+140
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+140
-140
lines changed

src/compiletest/compiletest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::Test
366366
fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
367367
match full_version_line {
368368
Some(ref full_version_line)
369-
if full_version_line.trim().len() > 0 => {
369+
if !full_version_line.trim().is_empty() => {
370370
let full_version_line = full_version_line.trim();
371371

372372
// used to be a regex "(^|[^0-9])([0-9]\.[0-9])([^0-9]|$)"
@@ -406,7 +406,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
406406

407407
match full_version_line {
408408
Some(ref full_version_line)
409-
if full_version_line.trim().len() > 0 => {
409+
if !full_version_line.trim().is_empty() => {
410410
let full_version_line = full_version_line.trim();
411411

412412
for (pos, l) in full_version_line.char_indices() {
@@ -424,7 +424,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
424424
let vers = full_version_line[pos + 5..].chars().take_while(|c| {
425425
c.is_digit(10)
426426
}).collect::<String>();
427-
if vers.len() > 0 { return Some(vers) }
427+
if !vers.is_empty() { return Some(vers) }
428428
}
429429
println!("Could not extract LLDB version from line '{}'",
430430
full_version_line);

src/libcollections/btree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ impl<K, V> Node<K, V> {
12251225
/// because we have one too many, and our parent now has one too few
12261226
fn split(&mut self) -> (K, V, Node<K, V>) {
12271227
// Necessary for correctness, but in a private function
1228-
debug_assert!(self.len() > 0);
1228+
debug_assert!(!self.is_empty());
12291229

12301230
let mut right = if self.is_leaf() {
12311231
Node::new_leaf(self.capacity())

src/libfmt_macros/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<'a> Parser<'a> {
371371
None => {
372372
let tmp = self.cur.clone();
373373
match self.word() {
374-
word if word.len() > 0 => {
374+
word if !word.is_empty() => {
375375
if self.consume('$') {
376376
CountIsName(word)
377377
} else {
@@ -463,7 +463,7 @@ mod tests {
463463
fn musterr(s: &str) {
464464
let mut p = Parser::new(s);
465465
p.next();
466-
assert!(p.errors.len() != 0);
466+
assert!(!p.errors.is_empty());
467467
}
468468

469469
#[test]

src/libgetopts/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ fn format_option(opt: &OptGroup) -> String {
804804
}
805805

806806
// Use short_name is possible, but fallback to long_name.
807-
if opt.short_name.len() > 0 {
807+
if !opt.short_name.is_empty() {
808808
line.push('-');
809809
line.push_str(&opt.short_name[..]);
810810
} else {

src/librustc/metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ fn each_auxiliary_node_id<F>(item: &ast::Item, callback: F) -> bool where
469469
ast::ItemStruct(ref struct_def, _) => {
470470
// If this is a newtype struct, return the constructor.
471471
match struct_def.ctor_id {
472-
Some(ctor_id) if struct_def.fields.len() > 0 &&
472+
Some(ctor_id) if !struct_def.fields.is_empty() &&
473473
struct_def.fields[0].node.kind.is_unnamed() => {
474474
continue_ = callback(ctor_id);
475475
}

src/librustc/metadata/loader.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,13 @@ impl<'a> Context<'a> {
307307
}
308308

309309
pub fn report_load_errs(&mut self) {
310-
let message = if self.rejected_via_hash.len() > 0 {
310+
let message = if !self.rejected_via_hash.is_empty() {
311311
format!("found possibly newer version of crate `{}`",
312312
self.ident)
313-
} else if self.rejected_via_triple.len() > 0 {
313+
} else if !self.rejected_via_triple.is_empty() {
314314
format!("couldn't find crate `{}` with expected target triple {}",
315315
self.ident, self.triple)
316-
} else if self.rejected_via_kind.len() > 0 {
316+
} else if !self.rejected_via_kind.is_empty() {
317317
format!("found staticlib `{}` instead of rlib or dylib", self.ident)
318318
} else {
319319
format!("can't find crate for `{}`", self.ident)
@@ -325,15 +325,15 @@ impl<'a> Context<'a> {
325325
};
326326
self.sess.span_err(self.span, &message[..]);
327327

328-
if self.rejected_via_triple.len() > 0 {
328+
if !self.rejected_via_triple.is_empty() {
329329
let mismatches = self.rejected_via_triple.iter();
330330
for (i, &CrateMismatch{ ref path, ref got }) in mismatches.enumerate() {
331331
self.sess.fileline_note(self.span,
332332
&format!("crate `{}`, path #{}, triple {}: {}",
333333
self.ident, i+1, got, path.display()));
334334
}
335335
}
336-
if self.rejected_via_hash.len() > 0 {
336+
if !self.rejected_via_hash.is_empty() {
337337
self.sess.span_note(self.span, "perhaps this crate needs \
338338
to be recompiled?");
339339
let mismatches = self.rejected_via_hash.iter();
@@ -353,7 +353,7 @@ impl<'a> Context<'a> {
353353
}
354354
}
355355
}
356-
if self.rejected_via_kind.len() > 0 {
356+
if !self.rejected_via_kind.is_empty() {
357357
self.sess.fileline_help(self.span, "please recompile this crate using \
358358
--crate-type lib");
359359
let mismatches = self.rejected_via_kind.iter();

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
182182

183183
fn mark_live_symbols(&mut self) {
184184
let mut scanned = HashSet::new();
185-
while self.worklist.len() > 0 {
185+
while !self.worklist.is_empty() {
186186
let id = self.worklist.pop().unwrap();
187187
if scanned.contains(&id) {
188188
continue

src/librustc/middle/infer/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
965965
fn pick_lifetime(&self,
966966
region_names: &HashSet<ast::Name>)
967967
-> (ast::Lifetime, FreshOrKept) {
968-
if region_names.len() > 0 {
968+
if !region_names.is_empty() {
969969
// It's not necessary to convert the set of region names to a
970970
// vector of string and then sort them. However, it makes the
971971
// choice of lifetime name deterministic and thus easier to test.

src/librustc/middle/infer/region_inference/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
246246
}
247247

248248
fn in_snapshot(&self) -> bool {
249-
self.undo_log.borrow().len() > 0
249+
!self.undo_log.borrow().is_empty()
250250
}
251251

252252
pub fn start_snapshot(&self) -> RegionSnapshot {

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15271527
// for nil return types, it is ok to not return a value expl.
15281528
} else {
15291529
let ends_with_stmt = match body.expr {
1530-
None if body.stmts.len() > 0 =>
1530+
None if !body.stmts.is_empty() =>
15311531
match body.stmts.first().unwrap().node {
15321532
ast::StmtSemi(ref e, _) => {
15331533
ty::expr_ty(self.ir.tcx, &**e) == t_ret

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
227227
ref bounds,
228228
ref bound_lifetimes,
229229
.. }) => {
230-
if bound_lifetimes.len() > 0 {
230+
if !bound_lifetimes.is_empty() {
231231
self.trait_ref_hack = true;
232232
let result = self.with(LateScope(bound_lifetimes, self.scope),
233233
|old_scope, this| {
@@ -267,7 +267,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
267267
_modifier: &ast::TraitBoundModifier) {
268268
debug!("visit_poly_trait_ref trait_ref={:?}", trait_ref);
269269

270-
if !self.trait_ref_hack || trait_ref.bound_lifetimes.len() > 0 {
270+
if !self.trait_ref_hack || !trait_ref.bound_lifetimes.is_empty() {
271271
if self.trait_ref_hack {
272272
println!("{:?}", trait_ref.span);
273273
span_err!(self.sess, trait_ref.span, E0316,

src/librustc/middle/ty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3722,7 +3722,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
37223722
res = res | TC::OwnsDtor;
37233723
}
37243724

3725-
if variants.len() != 0 {
3725+
if !variants.is_empty() {
37263726
let repr_hints = lookup_repr_hints(cx, did);
37273727
if repr_hints.len() > 1 {
37283728
// this is an error later on, but this type isn't safe
@@ -4766,7 +4766,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
47664766
match resolve_expr(tcx, expr) {
47674767
def::DefVariant(tid, vid, _) => {
47684768
let variant_info = enum_variant_with_id(tcx, tid, vid);
4769-
if variant_info.args.len() > 0 {
4769+
if !variant_info.args.is_empty() {
47704770
// N-ary variant.
47714771
RvalueDatumExpr
47724772
} else {
@@ -5361,7 +5361,7 @@ impl<'tcx> VariantInfo<'tcx> {
53615361

53625362
match ast_variant.node.kind {
53635363
ast::TupleVariantKind(ref args) => {
5364-
let arg_tys = if args.len() > 0 {
5364+
let arg_tys = if !args.is_empty() {
53655365
// the regions in the argument types come from the
53665366
// enum def'n, and hence will all be early bound
53675367
ty::no_late_bound_regions(cx, &ty_fn_args(ctor_ty)).unwrap()
@@ -5382,7 +5382,7 @@ impl<'tcx> VariantInfo<'tcx> {
53825382
ast::StructVariantKind(ref struct_def) => {
53835383
let fields: &[StructField] = &struct_def.fields;
53845384

5385-
assert!(fields.len() > 0);
5385+
assert!(!fields.is_empty());
53865386

53875387
let arg_tys = struct_def.fields.iter()
53885388
.map(|field| node_id_to_type(cx, field.node.id)).collect();

src/librustc/middle/ty_relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
544544
.map(|(a, b)| relation.relate(a, b))
545545
.collect::<Result<_, _>>());
546546
Ok(ty::mk_tup(tcx, ts))
547-
} else if as_.len() != 0 && bs.len() != 0 {
547+
} else if !(as_.is_empty() || bs.is_empty()) {
548548
Err(ty::terr_tuple_size(
549549
expected_found(relation, &as_.len(), &bs.len())))
550550
} else {

src/librustc/util/ppaux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ pub fn parameterized<'tcx,GG>(cx: &ctxt<'tcx>,
555555
&strs[0][..]
556556
},
557557
tail)
558-
} else if strs.len() > 0 {
558+
} else if !strs.is_empty() {
559559
format!("{}<{}>", base, strs.connect(", "))
560560
} else {
561561
format!("{}", base)

src/librustc_back/tempdir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl TempDir {
5050
let mut rng = thread_rng();
5151
for _ in 0..NUM_RETRIES {
5252
let suffix: String = rng.gen_ascii_chars().take(NUM_RAND_CHARS).collect();
53-
let leaf = if prefix.len() > 0 {
53+
let leaf = if !prefix.is_empty() {
5454
format!("{}.{}", prefix, suffix)
5555
} else {
5656
// If we're given an empty string for a prefix, then creating a

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ impl NonCamelCaseTypes {
778778

779779
// start with a non-lowercase letter rather than non-uppercase
780780
// ones (some scripts don't have a concept of upper/lowercase)
781-
ident.len() > 0 && !ident.char_at(0).is_lowercase() && !ident.contains('_')
781+
!ident.is_empty() && !ident.char_at(0).is_lowercase() && !ident.contains('_')
782782
}
783783

784784
fn to_camel_case(s: &str) -> String {
@@ -1900,7 +1900,7 @@ impl LintPass for UnconditionalRecursion {
19001900
// doesn't return (e.g. calls a `-> !` function or `loop { /*
19011901
// no break */ }`) shouldn't be linted unless it actually
19021902
// recurs.
1903-
if !reached_exit_without_self_call && self_call_spans.len() > 0 {
1903+
if !reached_exit_without_self_call && !self_call_spans.is_empty() {
19041904
cx.span_lint(UNCONDITIONAL_RECURSION, sp,
19051905
"function cannot return without recurring");
19061906

src/librustc_privacy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
10551055
let check_inherited = |sp: Span, vis: ast::Visibility, note: &str| {
10561056
if vis != ast::Inherited {
10571057
tcx.sess.span_err(sp, "unnecessary visibility qualifier");
1058-
if note.len() > 0 {
1058+
if !note.is_empty() {
10591059
tcx.sess.span_note(sp, note);
10601060
}
10611061
}

src/librustc_resolve/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3061,7 +3061,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30613061
}
30623062
}
30633063

3064-
if values.len() > 0 &&
3064+
if !values.is_empty() &&
30653065
values[smallest] != usize::MAX &&
30663066
values[smallest] < name.len() + 2 &&
30673067
values[smallest] <= max_distance &&
@@ -3217,7 +3217,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
32173217
format!("to call `{}::{}`", path_str, path_name)
32183218
};
32193219

3220-
if msg.len() > 0 {
3220+
if !msg.is_empty() {
32213221
msg = format!(". Did you mean {}?", msg)
32223222
}
32233223

src/librustc_trans/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub fn sanitize(s: &str) -> String {
269269
}
270270

271271
// Underscore-qualify anything that didn't start as an ident.
272-
if result.len() > 0 &&
272+
if !result.is_empty() &&
273273
result.as_bytes()[0] != '_' as u8 &&
274274
! (result.as_bytes()[0] as char).is_xid_start() {
275275
return format!("_{}", &result[..]);

src/librustc_trans/save/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
11191119
let glob_map = glob_map.as_ref().unwrap();
11201120
if glob_map.contains_key(&item.id) {
11211121
for n in glob_map.get(&item.id).unwrap() {
1122-
if name_string.len() > 0 {
1122+
if !name_string.is_empty() {
11231123
name_string.push_str(", ");
11241124
}
11251125
name_string.push_str(n.as_str());

src/librustc_trans/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11131113
let mut kind = NoBranch;
11141114
let mut test_val = val;
11151115
debug!("test_val={}", bcx.val_to_string(test_val));
1116-
if opts.len() > 0 {
1116+
if !opts.is_empty() {
11171117
match opts[0] {
11181118
ConstantValue(..) | ConstantRange(..) => {
11191119
test_val = load_if_immediate(bcx, val, left_ty);

src/librustc_trans/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2813,7 +2813,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
28132813
ccx.sess().bug("struct variant kind unexpected in get_item_val")
28142814
}
28152815
};
2816-
assert!(args.len() != 0);
2816+
assert!(!args.is_empty());
28172817
let ty = ty::node_id_to_type(ccx.tcx(), id);
28182818
let parent = ccx.tcx().map.get_parent(id);
28192819
let enm = ccx.tcx().map.expect_item(parent);

src/librustc_trans/trans/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
183183
bcx.fcx.param_substs);
184184

185185
// Nullary variants are not callable
186-
assert!(vinfo.args.len() > 0);
186+
assert!(!vinfo.args.is_empty());
187187

188188
Callee {
189189
bcx: bcx,
@@ -498,7 +498,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
498498

499499
match map_node {
500500
ast_map::NodeVariant(v) => match v.node.kind {
501-
ast::TupleVariantKind(ref args) => args.len() > 0,
501+
ast::TupleVariantKind(ref args) => !args.is_empty(),
502502
_ => false
503503
},
504504
ast_map::NodeStructCtor(_) => true,

src/librustc_trans/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
794794
let vinfo = ty::enum_variant_with_id(cx.tcx(),
795795
enum_did,
796796
variant_did);
797-
if vinfo.args.len() > 0 {
797+
if !vinfo.args.is_empty() {
798798
// N-ary variant.
799799
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
800800
} else {

src/librustc_trans/trans/debuginfo.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'tcx> TypeMap<'tcx> {
531531
// Maybe check that there is no self type here.
532532

533533
let tps = substs.types.get_slice(subst::TypeSpace);
534-
if tps.len() > 0 {
534+
if !tps.is_empty() {
535535
output.push('<');
536536

537537
for &type_parameter in tps {
@@ -1101,7 +1101,7 @@ pub fn get_cleanup_debug_loc_for_ast_node<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
11011101
if let Ok(code_snippet) = code_snippet {
11021102
let bytes = code_snippet.as_bytes();
11031103

1104-
if bytes.len() > 0 && &bytes[bytes.len()-1..] == b"}" {
1104+
if !bytes.is_empty() && &bytes[bytes.len()-1..] == b"}" {
11051105
cleanup_span = Span {
11061106
lo: node_span.hi - codemap::BytePos(1),
11071107
hi: node_span.hi,
@@ -3824,7 +3824,7 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
38243824
output.push_str("fn(");
38253825

38263826
let sig = ty::erase_late_bound_regions(cx.tcx(), sig);
3827-
if sig.inputs.len() > 0 {
3827+
if !sig.inputs.is_empty() {
38283828
for &parameter_type in &sig.inputs {
38293829
push_debuginfo_type_name(cx, parameter_type, true, output);
38303830
output.push_str(", ");
@@ -3834,7 +3834,7 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
38343834
}
38353835

38363836
if sig.variadic {
3837-
if sig.inputs.len() > 0 {
3837+
if !sig.inputs.is_empty() {
38383838
output.push_str(", ...");
38393839
} else {
38403840
output.push_str("...");

src/librustc_trans/trans/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ fn trans_def_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
12591259
match def {
12601260
def::DefVariant(tid, vid, _) => {
12611261
let variant_info = ty::enum_variant_with_id(bcx.tcx(), tid, vid);
1262-
if variant_info.args.len() > 0 {
1262+
if !variant_info.args.is_empty() {
12631263
// N-ary variant.
12641264
let llfn = callee::trans_fn_ref(bcx.ccx(), vid,
12651265
ExprId(ref_expr.id),

0 commit comments

Comments
 (0)