Skip to content

Commit 10f15e7

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

File tree

61 files changed

+142
-142
lines changed

Some content is hidden

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

61 files changed

+142
-142
lines changed

src/compiletest/compiletest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::Test
368368
fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
369369
match full_version_line {
370370
Some(ref full_version_line)
371-
if full_version_line.trim().len() > 0 => {
371+
if !full_version_line.trim().is_empty() => {
372372
let full_version_line = full_version_line.trim();
373373

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

409409
match full_version_line {
410410
Some(ref full_version_line)
411-
if full_version_line.trim().len() > 0 => {
411+
if !full_version_line.trim().is_empty() => {
412412
let full_version_line = full_version_line.trim();
413413

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

src/libcollections/btree/node.rs

Lines changed: 1 addition & 1 deletion
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/libcore/char.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl CharExt for char {
227227
#[inline]
228228
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
229229
// Marked #[inline] to allow llvm optimizing it away
230-
if code < MAX_ONE_B && dst.len() >= 1 {
230+
if code < MAX_ONE_B && !dst.is_empty() {
231231
dst[0] = code as u8;
232232
Some(1)
233233
} else if code < MAX_TWO_B && dst.len() >= 2 {
@@ -258,7 +258,7 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
258258
#[inline]
259259
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
260260
// Marked #[inline] to allow llvm optimizing it away
261-
if (ch & 0xFFFF) == ch && dst.len() >= 1 {
261+
if (ch & 0xFFFF) == ch && !dst.is_empty() {
262262
// The BMP falls through (assuming non-surrogate, as it should)
263263
dst[0] = ch as u16;
264264
Some(1)

src/libfmt_macros/lib.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3665,7 +3665,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
36653665
res = res | TC::OwnsDtor;
36663666
}
36673667

3668-
if variants.len() != 0 {
3668+
if !variants.is_empty() {
36693669
let repr_hints = lookup_repr_hints(cx, did);
36703670
if repr_hints.len() > 1 {
36713671
// this is an error later on, but this type isn't safe
@@ -4654,7 +4654,7 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
46544654
match resolve_expr(tcx, expr) {
46554655
def::DefVariant(tid, vid, _) => {
46564656
let variant_info = enum_variant_with_id(tcx, tid, vid);
4657-
if variant_info.args.len() > 0 {
4657+
if !variant_info.args.is_empty() {
46584658
// N-ary variant.
46594659
RvalueDatumExpr
46604660
} else {
@@ -5259,7 +5259,7 @@ impl<'tcx> VariantInfo<'tcx> {
52595259

52605260
match ast_variant.node.kind {
52615261
ast::TupleVariantKind(ref args) => {
5262-
let arg_tys = if args.len() > 0 {
5262+
let arg_tys = if !args.is_empty() {
52635263
// the regions in the argument types come from the
52645264
// enum def'n, and hence will all be early bound
52655265
ty::no_late_bound_regions(cx, &ty_fn_args(ctor_ty)).unwrap()
@@ -5280,7 +5280,7 @@ impl<'tcx> VariantInfo<'tcx> {
52805280
ast::StructVariantKind(ref struct_def) => {
52815281
let fields: &[StructField] = &struct_def.fields;
52825282

5283-
assert!(fields.len() > 0);
5283+
assert!(!fields.is_empty());
52845284

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

src/librustc/middle/ty_relate/mod.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ pub fn parameterized<'tcx,GG>(cx: &ctxt<'tcx>,
558558
&strs[0][..]
559559
},
560560
tail)
561-
} else if strs.len() > 0 {
561+
} else if !strs.is_empty() {
562562
format!("{}<{}>", base, strs.connect(", "))
563563
} else {
564564
format!("{}", base)

src/librustc_back/tempdir.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30723072
}
30733073
}
30743074

3075-
if values.len() > 0 &&
3075+
if !values.is_empty() &&
30763076
values[smallest] != usize::MAX &&
30773077
values[smallest] < name.len() + 2 &&
30783078
values[smallest] <= max_distance &&
@@ -3228,7 +3228,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
32283228
format!("to call `{}::{}`", path_str, path_name)
32293229
};
32303230

3231-
if msg.len() > 0 {
3231+
if !msg.is_empty() {
32323232
msg = format!(". Did you mean {}?", msg)
32333233
}
32343234

src/librustc_trans/back/link.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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

src/librustc_trans/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
23922392
ccx.sess().bug("struct variant kind unexpected in get_item_val")
23932393
}
23942394
};
2395-
assert!(args.len() != 0);
2395+
assert!(!args.is_empty());
23962396
let ty = ty::node_id_to_type(ccx.tcx(), id);
23972397
let parent = ccx.tcx().map.get_parent(id);
23982398
let enm = ccx.tcx().map.expect_item(parent);

src/librustc_trans/trans/callee.rs

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

186186
// Nullary variants are not callable
187-
assert!(vinfo.args.len() > 0);
187+
assert!(!vinfo.args.is_empty());
188188

189189
Callee {
190190
bcx: bcx,
@@ -495,7 +495,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
495495

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

src/librustc_trans/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
781781
let vinfo = ty::enum_variant_with_id(cx.tcx(),
782782
enum_did,
783783
variant_did);
784-
if vinfo.args.len() > 0 {
784+
if !vinfo.args.is_empty() {
785785
// N-ary variant.
786786
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
787787
} else {

src/librustc_trans/trans/debuginfo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ impl<'tcx> TypeMap<'tcx> {
532532
// Maybe check that there is no self type here.
533533

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

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

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

38363836
let sig = ty::erase_late_bound_regions(cx.tcx(), sig);
3837-
if sig.inputs.len() > 0 {
3837+
if !sig.inputs.is_empty() {
38383838
for &parameter_type in &sig.inputs {
38393839
push_debuginfo_type_name(cx, parameter_type, true, output);
38403840
output.push_str(", ");
@@ -3844,7 +3844,7 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
38443844
}
38453845

38463846
if sig.variadic {
3847-
if sig.inputs.len() > 0 {
3847+
if !sig.inputs.is_empty() {
38483848
output.push_str(", ...");
38493849
} else {
38503850
output.push_str("...");

0 commit comments

Comments
 (0)