Skip to content

Commit

Permalink
Negative case of len() -> is_empty()
Browse files Browse the repository at this point in the history
`s/([^\(\s]+\.)len\(\) [(?:!=)>] 0/!$1is_empty()/g`
  • Loading branch information
tamird committed Apr 15, 2015
1 parent 29ac044 commit 10f15e7
Show file tree
Hide file tree
Showing 61 changed files with 142 additions and 142 deletions.
6 changes: 3 additions & 3 deletions src/compiletest/compiletest.rs
Expand Up @@ -368,7 +368,7 @@ pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::Test
fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
match full_version_line {
Some(ref full_version_line)
if full_version_line.trim().len() > 0 => {
if !full_version_line.trim().is_empty() => {
let full_version_line = full_version_line.trim();

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

match full_version_line {
Some(ref full_version_line)
if full_version_line.trim().len() > 0 => {
if !full_version_line.trim().is_empty() => {
let full_version_line = full_version_line.trim();

for (pos, l) in full_version_line.char_indices() {
Expand All @@ -426,7 +426,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
let vers = full_version_line[pos + 5..].chars().take_while(|c| {
c.is_digit(10)
}).collect::<String>();
if vers.len() > 0 { return Some(vers) }
if !vers.is_empty() { return Some(vers) }
}
println!("Could not extract LLDB version from line '{}'",
full_version_line);
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/btree/node.rs
Expand Up @@ -1225,7 +1225,7 @@ impl<K, V> Node<K, V> {
/// because we have one too many, and our parent now has one too few
fn split(&mut self) -> (K, V, Node<K, V>) {
// Necessary for correctness, but in a private function
debug_assert!(self.len() > 0);
debug_assert!(!self.is_empty());

let mut right = if self.is_leaf() {
Node::new_leaf(self.capacity())
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/char.rs
Expand Up @@ -227,7 +227,7 @@ impl CharExt for char {
#[inline]
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if code < MAX_ONE_B && dst.len() >= 1 {
if code < MAX_ONE_B && !dst.is_empty() {
dst[0] = code as u8;
Some(1)
} else if code < MAX_TWO_B && dst.len() >= 2 {
Expand Down Expand Up @@ -258,7 +258,7 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
#[inline]
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
// Marked #[inline] to allow llvm optimizing it away
if (ch & 0xFFFF) == ch && dst.len() >= 1 {
if (ch & 0xFFFF) == ch && !dst.is_empty() {
// The BMP falls through (assuming non-surrogate, as it should)
dst[0] = ch as u16;
Some(1)
Expand Down
4 changes: 2 additions & 2 deletions src/libfmt_macros/lib.rs
Expand Up @@ -371,7 +371,7 @@ impl<'a> Parser<'a> {
None => {
let tmp = self.cur.clone();
match self.word() {
word if word.len() > 0 => {
word if !word.is_empty() => {
if self.consume('$') {
CountIsName(word)
} else {
Expand Down Expand Up @@ -463,7 +463,7 @@ mod tests {
fn musterr(s: &str) {
let mut p = Parser::new(s);
p.next();
assert!(p.errors.len() != 0);
assert!(!p.errors.is_empty());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libgetopts/lib.rs
Expand Up @@ -804,7 +804,7 @@ fn format_option(opt: &OptGroup) -> String {
}

// Use short_name is possible, but fallback to long_name.
if opt.short_name.len() > 0 {
if !opt.short_name.is_empty() {
line.push('-');
line.push_str(&opt.short_name[..]);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Expand Up @@ -469,7 +469,7 @@ fn each_auxiliary_node_id<F>(item: &ast::Item, callback: F) -> bool where
ast::ItemStruct(ref struct_def, _) => {
// If this is a newtype struct, return the constructor.
match struct_def.ctor_id {
Some(ctor_id) if struct_def.fields.len() > 0 &&
Some(ctor_id) if !struct_def.fields.is_empty() &&
struct_def.fields[0].node.kind.is_unnamed() => {
continue_ = callback(ctor_id);
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/metadata/loader.rs
Expand Up @@ -307,13 +307,13 @@ impl<'a> Context<'a> {
}

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

if self.rejected_via_triple.len() > 0 {
if !self.rejected_via_triple.is_empty() {
let mismatches = self.rejected_via_triple.iter();
for (i, &CrateMismatch{ ref path, ref got }) in mismatches.enumerate() {
self.sess.fileline_note(self.span,
&format!("crate `{}`, path #{}, triple {}: {}",
self.ident, i+1, got, path.display()));
}
}
if self.rejected_via_hash.len() > 0 {
if !self.rejected_via_hash.is_empty() {
self.sess.span_note(self.span, "perhaps this crate needs \
to be recompiled?");
let mismatches = self.rejected_via_hash.iter();
Expand All @@ -353,7 +353,7 @@ impl<'a> Context<'a> {
}
}
}
if self.rejected_via_kind.len() > 0 {
if !self.rejected_via_kind.is_empty() {
self.sess.fileline_help(self.span, "please recompile this crate using \
--crate-type lib");
let mismatches = self.rejected_via_kind.iter();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -182,7 +182,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {

fn mark_live_symbols(&mut self) {
let mut scanned = HashSet::new();
while self.worklist.len() > 0 {
while !self.worklist.is_empty() {
let id = self.worklist.pop().unwrap();
if scanned.contains(&id) {
continue
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/error_reporting.rs
Expand Up @@ -966,7 +966,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
fn pick_lifetime(&self,
region_names: &HashSet<ast::Name>)
-> (ast::Lifetime, FreshOrKept) {
if region_names.len() > 0 {
if !region_names.is_empty() {
// It's not necessary to convert the set of region names to a
// vector of string and then sort them. However, it makes the
// choice of lifetime name deterministic and thus easier to test.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/region_inference/mod.rs
Expand Up @@ -246,7 +246,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
}

fn in_snapshot(&self) -> bool {
self.undo_log.borrow().len() > 0
!self.undo_log.borrow().is_empty()
}

pub fn start_snapshot(&self) -> RegionSnapshot {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Expand Up @@ -1527,7 +1527,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// for nil return types, it is ok to not return a value expl.
} else {
let ends_with_stmt = match body.expr {
None if body.stmts.len() > 0 =>
None if !body.stmts.is_empty() =>
match body.stmts.first().unwrap().node {
ast::StmtSemi(ref e, _) => {
ty::expr_ty(self.ir.tcx, &**e) == t_ret
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -227,7 +227,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
ref bounds,
ref bound_lifetimes,
.. }) => {
if bound_lifetimes.len() > 0 {
if !bound_lifetimes.is_empty() {
self.trait_ref_hack = true;
let result = self.with(LateScope(bound_lifetimes, self.scope),
|old_scope, this| {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
_modifier: &ast::TraitBoundModifier) {
debug!("visit_poly_trait_ref trait_ref={:?}", trait_ref);

if !self.trait_ref_hack || trait_ref.bound_lifetimes.len() > 0 {
if !self.trait_ref_hack || !trait_ref.bound_lifetimes.is_empty() {
if self.trait_ref_hack {
println!("{:?}", trait_ref.span);
span_err!(self.sess, trait_ref.span, E0316,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/ty.rs
Expand Up @@ -3665,7 +3665,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
res = res | TC::OwnsDtor;
}

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

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

assert!(fields.len() > 0);
assert!(!fields.is_empty());

let arg_tys = struct_def.fields.iter()
.map(|field| node_id_to_type(cx, field.node.id)).collect();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty_relate/mod.rs
Expand Up @@ -544,7 +544,7 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R,
.map(|(a, b)| relation.relate(a, b))
.collect::<Result<_, _>>());
Ok(ty::mk_tup(tcx, ts))
} else if as_.len() != 0 && bs.len() != 0 {
} else if !(as_.is_empty() || bs.is_empty()) {
Err(ty::terr_tuple_size(
expected_found(relation, &as_.len(), &bs.len())))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Expand Up @@ -558,7 +558,7 @@ pub fn parameterized<'tcx,GG>(cx: &ctxt<'tcx>,
&strs[0][..]
},
tail)
} else if strs.len() > 0 {
} else if !strs.is_empty() {
format!("{}<{}>", base, strs.connect(", "))
} else {
format!("{}", base)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/tempdir.rs
Expand Up @@ -50,7 +50,7 @@ impl TempDir {
let mut rng = thread_rng();
for _ in 0..NUM_RETRIES {
let suffix: String = rng.gen_ascii_chars().take(NUM_RAND_CHARS).collect();
let leaf = if prefix.len() > 0 {
let leaf = if !prefix.is_empty() {
format!("{}.{}", prefix, suffix)
} else {
// If we're given an empty string for a prefix, then creating a
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Expand Up @@ -778,7 +778,7 @@ impl NonCamelCaseTypes {

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_privacy/lib.rs
Expand Up @@ -1055,7 +1055,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
let check_inherited = |sp: Span, vis: ast::Visibility, note: &str| {
if vis != ast::Inherited {
tcx.sess.span_err(sp, "unnecessary visibility qualifier");
if note.len() > 0 {
if !note.is_empty() {
tcx.sess.span_note(sp, note);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/lib.rs
Expand Up @@ -3072,7 +3072,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}

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

if msg.len() > 0 {
if !msg.is_empty() {
msg = format!(". Did you mean {}?", msg)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/back/link.rs
Expand Up @@ -269,7 +269,7 @@ pub fn sanitize(s: &str) -> String {
}

// Underscore-qualify anything that didn't start as an ident.
if result.len() > 0 &&
if !result.is_empty() &&
result.as_bytes()[0] != '_' as u8 &&
! (result.as_bytes()[0] as char).is_xid_start() {
return format!("_{}", &result[..]);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/save/mod.rs
Expand Up @@ -1119,7 +1119,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
let glob_map = glob_map.as_ref().unwrap();
if glob_map.contains_key(&item.id) {
for n in glob_map.get(&item.id).unwrap() {
if name_string.len() > 0 {
if !name_string.is_empty() {
name_string.push_str(", ");
}
name_string.push_str(n.as_str());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/_match.rs
Expand Up @@ -1112,7 +1112,7 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
let mut kind = NoBranch;
let mut test_val = val;
debug!("test_val={}", bcx.val_to_string(test_val));
if opts.len() > 0 {
if !opts.is_empty() {
match opts[0] {
ConstantValue(..) | ConstantRange(..) => {
test_val = load_if_immediate(bcx, val, left_ty);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/base.rs
Expand Up @@ -2392,7 +2392,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
ccx.sess().bug("struct variant kind unexpected in get_item_val")
}
};
assert!(args.len() != 0);
assert!(!args.is_empty());
let ty = ty::node_id_to_type(ccx.tcx(), id);
let parent = ccx.tcx().map.get_parent(id);
let enm = ccx.tcx().map.expect_item(parent);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/callee.rs
Expand Up @@ -184,7 +184,7 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr)
bcx.fcx.param_substs);

// Nullary variants are not callable
assert!(vinfo.args.len() > 0);
assert!(!vinfo.args.is_empty());

Callee {
bcx: bcx,
Expand Down Expand Up @@ -495,7 +495,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(

match map_node {
ast_map::NodeVariant(v) => match v.node.kind {
ast::TupleVariantKind(ref args) => args.len() > 0,
ast::TupleVariantKind(ref args) => !args.is_empty(),
_ => false
},
ast_map::NodeStructCtor(_) => true,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/consts.rs
Expand Up @@ -781,7 +781,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let vinfo = ty::enum_variant_with_id(cx.tcx(),
enum_did,
variant_did);
if vinfo.args.len() > 0 {
if !vinfo.args.is_empty() {
// N-ary variant.
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_trans/trans/debuginfo.rs
Expand Up @@ -532,7 +532,7 @@ impl<'tcx> TypeMap<'tcx> {
// Maybe check that there is no self type here.

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

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

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

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

if sig.variadic {
if sig.inputs.len() > 0 {
if !sig.inputs.is_empty() {
output.push_str(", ...");
} else {
output.push_str("...");
Expand Down

0 comments on commit 10f15e7

Please sign in to comment.