Skip to content

Commit 369af01

Browse files
committed
Positive case of len() -> is_empty()
`s/(?<!\{ self)(?<=\.)len\(\) == 0/is_empty()/g`
1 parent edac3ce commit 369af01

Some content is hidden

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

70 files changed

+120
-120
lines changed

src/compiletest/runtest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
864864
}
865865
first = false;
866866
}
867-
if !failed && rest.len() == 0 {
867+
if !failed && rest.is_empty() {
868868
i += 1;
869869
}
870870
if i == num_check_lines {
@@ -1645,7 +1645,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
16451645
// codegen tests (vs. clang)
16461646

16471647
fn append_suffix_to_stem(p: &Path, suffix: &str) -> PathBuf {
1648-
if suffix.len() == 0 {
1648+
if suffix.is_empty() {
16491649
p.to_path_buf()
16501650
} else {
16511651
let mut stem = p.file_stem().unwrap().to_os_string();

src/doc/reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3788,7 +3788,7 @@ its type parameters are types:
37883788

37893789
```ignore
37903790
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
3791-
if xs.len() == 0 {
3791+
if xs.is_empty() {
37923792
return vec![];
37933793
}
37943794
let first: B = f(xs[0].clone());

src/libcollections/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ mod stack {
692692
// We've reached the root, so no matter what, we're done. We manually
693693
// access the root via the tree itself to avoid creating any dangling
694694
// pointers.
695-
if self.map.root.len() == 0 && !self.map.root.is_leaf() {
695+
if self.map.root.is_empty() && !self.map.root.is_leaf() {
696696
// We've emptied out the root, so make its only child the new root.
697697
// If it's a leaf, we just let it become empty.
698698
self.map.depth -= 1;

src/libcollections/btree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ impl<K, V> Node<K, V> {
10971097
/// When a node has no keys or values and only a single edge, extract that edge.
10981098
pub fn hoist_lone_child(&mut self) {
10991099
// Necessary for correctness, but in a private module
1100-
debug_assert!(self.len() == 0);
1100+
debug_assert!(self.is_empty());
11011101
debug_assert!(!self.is_leaf());
11021102

11031103
unsafe {

src/libcore/slice.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<T> SliceExt for [T] {
203203

204204
#[inline]
205205
fn first(&self) -> Option<&T> {
206-
if self.len() == 0 { None } else { Some(&self[0]) }
206+
if self.is_empty() { None } else { Some(&self[0]) }
207207
}
208208

209209
#[inline]
@@ -216,7 +216,7 @@ impl<T> SliceExt for [T] {
216216

217217
#[inline]
218218
fn last(&self) -> Option<&T> {
219-
if self.len() == 0 { None } else { Some(&self[self.len() - 1]) }
219+
if self.is_empty() { None } else { Some(&self[self.len() - 1]) }
220220
}
221221

222222
#[inline]
@@ -295,7 +295,7 @@ impl<T> SliceExt for [T] {
295295

296296
#[inline]
297297
fn first_mut(&mut self) -> Option<&mut T> {
298-
if self.len() == 0 { None } else { Some(&mut self[0]) }
298+
if self.is_empty() { None } else { Some(&mut self[0]) }
299299
}
300300

301301
#[inline]
@@ -1305,7 +1305,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
13051305

13061306
#[inline]
13071307
fn next(&mut self) -> Option<&'a [T]> {
1308-
if self.v.len() == 0 {
1308+
if self.v.is_empty() {
13091309
None
13101310
} else {
13111311
let chunksz = cmp::min(self.v.len(), self.size);
@@ -1317,7 +1317,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
13171317

13181318
#[inline]
13191319
fn size_hint(&self) -> (usize, Option<usize>) {
1320-
if self.v.len() == 0 {
1320+
if self.v.is_empty() {
13211321
(0, Some(0))
13221322
} else {
13231323
let n = self.v.len() / self.size;
@@ -1332,7 +1332,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
13321332
impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
13331333
#[inline]
13341334
fn next_back(&mut self) -> Option<&'a [T]> {
1335-
if self.v.len() == 0 {
1335+
if self.v.is_empty() {
13361336
None
13371337
} else {
13381338
let remainder = self.v.len() % self.size;
@@ -1383,7 +1383,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
13831383

13841384
#[inline]
13851385
fn next(&mut self) -> Option<&'a mut [T]> {
1386-
if self.v.len() == 0 {
1386+
if self.v.is_empty() {
13871387
None
13881388
} else {
13891389
let sz = cmp::min(self.v.len(), self.chunk_size);
@@ -1396,7 +1396,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
13961396

13971397
#[inline]
13981398
fn size_hint(&self) -> (usize, Option<usize>) {
1399-
if self.v.len() == 0 {
1399+
if self.v.is_empty() {
14001400
(0, Some(0))
14011401
} else {
14021402
let n = self.v.len() / self.chunk_size;
@@ -1411,7 +1411,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
14111411
impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
14121412
#[inline]
14131413
fn next_back(&mut self) -> Option<&'a mut [T]> {
1414-
if self.v.len() == 0 {
1414+
if self.v.is_empty() {
14151415
None
14161416
} else {
14171417
let remainder = self.v.len() % self.chunk_size;

src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ enum OldSearcher {
908908
impl OldSearcher {
909909
#[allow(dead_code)]
910910
fn new(haystack: &[u8], needle: &[u8]) -> OldSearcher {
911-
if needle.len() == 0 {
911+
if needle.is_empty() {
912912
// Handle specially
913913
unimplemented!()
914914
// FIXME: Tune this.

src/libcore/str/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher,
437437
{
438438
if m.done {
439439
SearchStep::Done
440-
} else if m.needle.len() == 0 && m.start <= m.end {
440+
} else if m.needle.is_empty() && m.start <= m.end {
441441
// Case for needle == ""
442442
if m.start == m.end {
443443
m.done = true;

src/liblog/directive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
4545
return (dirs, None);
4646
}
4747
mods.map(|m| { for s in m.split(',') {
48-
if s.len() == 0 { continue }
48+
if s.is_empty() { continue }
4949
let mut parts = s.split('=');
5050
let (log_level, name) = match (parts.next(), parts.next().map(|s| s.trim()), parts.next()) {
5151
(Some(part0), None, None) => {

src/librustc/metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
8080
(None, Some(sess)) => sess.err(s),
8181
}
8282
};
83-
if s.len() == 0 {
83+
if s.is_empty() {
8484
say("crate name must not be empty");
8585
}
8686
for c in s.chars() {

src/librustc/metadata/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
767767
get_type(cdata, field_ty.id.node, tcx).ty
768768
})
769769
.collect();
770-
let arg_names = if arg_names.len() == 0 { None } else { Some(arg_names) };
770+
let arg_names = if arg_names.is_empty() { None } else { Some(arg_names) };
771771

772772
(None, arg_tys, arg_names)
773773
}
@@ -1383,7 +1383,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)
13831383

13841384
debug!("found dylib deps: {}", formats.as_str_slice());
13851385
for spec in formats.as_str_slice().split(',') {
1386-
if spec.len() == 0 { continue }
1386+
if spec.is_empty() { continue }
13871387
let cnum = spec.split(':').nth(0).unwrap();
13881388
let link = spec.split(':').nth(1).unwrap();
13891389
let cnum: ast::CrateNum = cnum.parse().unwrap();

src/librustc/metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ fn encode_codemap(ecx: &EncodeContext, rbml_w: &mut Encoder) {
17501750

17511751
for filemap in &codemap.files.borrow()[..] {
17521752

1753-
if filemap.lines.borrow().len() == 0 || filemap.is_imported() {
1753+
if filemap.lines.borrow().is_empty() || filemap.is_imported() {
17541754
// No need to export empty filemaps, as they can't contain spans
17551755
// that need translation.
17561756
// Also no need to re-export imported filemaps, as any downstream

src/librustc/metadata/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a> Context<'a> {
517517
// library's metadata sections. In theory we should
518518
// read both, but reading dylib metadata is quite
519519
// slow.
520-
if m.len() == 0 {
520+
if m.is_empty() {
521521
return None
522522
} else if m.len() == 1 {
523523
return Some(m.into_iter().next().unwrap())

src/librustc/middle/check_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
239239
if let Some(DefLocal(_)) = def {
240240
if ty::enum_variants(cx.tcx, def_id).iter().any(|variant|
241241
token::get_name(variant.name) == token::get_name(ident.node.name)
242-
&& variant.args.len() == 0
242+
&& variant.args.is_empty()
243243
) {
244244
span_warn!(cx.tcx.sess, p.span, E0170,
245245
"pattern binding `{}` is named the same as one \
@@ -636,19 +636,19 @@ fn is_useful(cx: &MatchCheckCtxt,
636636
-> Usefulness {
637637
let &Matrix(ref rows) = matrix;
638638
debug!("{:?}", matrix);
639-
if rows.len() == 0 {
639+
if rows.is_empty() {
640640
return match witness {
641641
ConstructWitness => UsefulWithWitness(vec!()),
642642
LeaveOutWitness => Useful
643643
};
644644
}
645-
if rows[0].len() == 0 {
645+
if rows[0].is_empty() {
646646
return NotUseful;
647647
}
648648
assert!(rows.iter().all(|r| r.len() == v.len()));
649649
let real_pat = match rows.iter().find(|r| (*r)[0].id != DUMMY_NODE_ID) {
650650
Some(r) => raw_pat(r[0]),
651-
None if v.len() == 0 => return NotUseful,
651+
None if v.is_empty() => return NotUseful,
652652
None => v[0]
653653
};
654654
let left_ty = if real_pat.id == DUMMY_NODE_ID {

src/librustc/middle/infer/error_reporting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12401240
let lifetimes =
12411241
path.segments.last().unwrap().parameters.lifetimes();
12421242
let mut insert = Vec::new();
1243-
if lifetimes.len() == 0 {
1243+
if lifetimes.is_empty() {
12441244
let anon = self.cur_anon.get();
12451245
for (i, a) in (anon..anon+expected).enumerate() {
12461246
if anon_nums.contains(&a) {
@@ -1360,7 +1360,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
13601360

13611361
ast::AngleBracketedParameters(ref data) => {
13621362
let mut new_lts = Vec::new();
1363-
if data.lifetimes.len() == 0 {
1363+
if data.lifetimes.is_empty() {
13641364
// traverse once to see if there's a need to insert lifetime
13651365
let need_insert = (0..expected).any(|i| {
13661366
indexes.contains(&i)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
8888
Err(_) => "/tmp/constraints.node%.dot".to_string(),
8989
};
9090

91-
if output_template.len() == 0 {
91+
if output_template.is_empty() {
9292
tcx.sess.bug("empty string provided as RUST_REGION_GRAPH");
9393
}
9494

src/librustc/middle/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
716716
None => {
717717
// Vanilla 'break' or 'loop', so use the enclosing
718718
// loop scope
719-
if self.loop_scope.len() == 0 {
719+
if self.loop_scope.is_empty() {
720720
self.ir.tcx.sess.span_bug(sp, "break outside loop");
721721
} else {
722722
*self.loop_scope.last().unwrap()
@@ -1586,7 +1586,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15861586

15871587
fn should_warn(&self, var: Variable) -> Option<String> {
15881588
let name = self.ir.variable_name(var);
1589-
if name.len() == 0 || name.as_bytes()[0] == ('_' as u8) {
1589+
if name.is_empty() || name.as_bytes()[0] == ('_' as u8) {
15901590
None
15911591
} else {
15921592
Some(name)

src/librustc/middle/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<T> VecPerParamSpace<T> {
361361
pub fn get_self<'a>(&'a self) -> Option<&'a T> {
362362
let v = self.get_slice(SelfSpace);
363363
assert!(v.len() <= 1);
364-
if v.len() == 0 { None } else { Some(&v[0]) }
364+
if v.is_empty() { None } else { Some(&v[0]) }
365365
}
366366

367367
pub fn len(&self, space: ParamSpace) -> usize {

src/librustc/middle/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
298298
self.predicates.len(),
299299
errors.len());
300300

301-
if errors.len() == 0 {
301+
if errors.is_empty() {
302302
Ok(())
303303
} else {
304304
Err(errors)

src/librustc/middle/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
698698
// is checked for in `evaluate_stack` (and hence users
699699
// who might care about this case, like coherence, should use
700700
// that function).
701-
if candidates.len() == 0 {
701+
if candidates.is_empty() {
702702
return Err(Unimplemented);
703703
}
704704

@@ -881,7 +881,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
881881
try!(self.assemble_candidates_from_caller_bounds(stack, &mut candidates));
882882
// Default implementations have lower priority, so we only
883883
// consider triggering a default if there is no other impl that can apply.
884-
if candidates.vec.len() == 0 {
884+
if candidates.vec.is_empty() {
885885
try!(self.assemble_candidates_from_default_impls(obligation, &mut candidates));
886886
}
887887
debug!("candidate list size: {}", candidates.vec.len());

src/librustc/middle/ty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3093,7 +3093,7 @@ pub fn mk_trait<'tcx>(cx: &ctxt<'tcx>,
30933093
}
30943094

30953095
fn bound_list_is_sorted(bounds: &[ty::PolyProjectionPredicate]) -> bool {
3096-
bounds.len() == 0 ||
3096+
bounds.is_empty() ||
30973097
bounds[1..].iter().enumerate().all(
30983098
|(index, bound)| bounds[index].sort_key() <= bound.sort_key())
30993099
}
@@ -3744,7 +3744,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
37443744
if variants.len() == 2 {
37453745
let mut data_idx = 0;
37463746

3747-
if variants[0].args.len() == 0 {
3747+
if variants[0].args.is_empty() {
37483748
data_idx = 1;
37493749
}
37503750

@@ -4257,10 +4257,10 @@ pub fn type_is_c_like_enum(cx: &ctxt, ty: Ty) -> bool {
42574257
match ty.sty {
42584258
ty_enum(did, _) => {
42594259
let variants = enum_variants(cx, did);
4260-
if variants.len() == 0 {
4260+
if variants.is_empty() {
42614261
false
42624262
} else {
4263-
variants.iter().all(|v| v.args.len() == 0)
4263+
variants.iter().all(|v| v.args.is_empty())
42644264
}
42654265
}
42664266
_ => false

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
902902
};
903903
output_types.sort();
904904
output_types.dedup();
905-
if output_types.len() == 0 {
905+
if output_types.is_empty() {
906906
output_types.push(OutputTypeExe);
907907
}
908908

src/librustc/util/ppaux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ impl<'tcx, T> UserString<'tcx> for ty::Binder<T>
12641264
let names: Vec<_> = names.iter().map(|s| &s[..]).collect();
12651265

12661266
let value_str = unbound_value.user_string(tcx);
1267-
if names.len() == 0 {
1267+
if names.is_empty() {
12681268
value_str
12691269
} else {
12701270
format!("for<{}> {}", names.connect(","), value_str)

src/librustc_driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,9 @@ pub fn collect_crate_types(session: &Session,
885885
// command line, then reuse the empty `base` Vec to hold the types that
886886
// will be found in crate attributes.
887887
let mut base = session.opts.crate_types.clone();
888-
if base.len() == 0 {
888+
if base.is_empty() {
889889
base.extend(attr_types.into_iter());
890-
if base.len() == 0 {
890+
if base.is_empty() {
891891
base.push(link::default_output_for_target(session));
892892
}
893893
base.sort();

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl RustcDefaultCalls {
424424
odir: &Option<PathBuf>,
425425
ofile: &Option<PathBuf>)
426426
-> Compilation {
427-
if sess.opts.prints.len() == 0 {
427+
if sess.opts.prints.is_empty() {
428428
return Compilation::Continue;
429429
}
430430

src/librustc_driver/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ fn print_flowgraph<W: Write>(variants: Vec<borrowck_dot::Variant>,
676676
};
677677

678678
match code {
679-
_ if variants.len() == 0 => {
679+
_ if variants.is_empty() => {
680680
let r = dot::render(&lcfg, &mut out);
681681
return expand_err_details(r);
682682
}

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
767767
f.name
768768
}).collect::<Vec<_>>();
769769

770-
if fields.len() == 0 {
770+
if fields.is_empty() {
771771
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
772772
}
773773

0 commit comments

Comments
 (0)