Skip to content

Commit 74590be

Browse files
committed
s/(?<!\{ self)(?<=\.)len\(\) == 0/is_empty()/g
1 parent 242ed0b commit 74590be

Some content is hidden

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

69 files changed

+119
-119
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
@@ -3853,7 +3853,7 @@ its type parameters are types:
38533853

38543854
```ignore
38553855
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
3856-
if xs.len() == 0 {
3856+
if xs.is_empty() {
38573857
return vec![];
38583858
}
38593859
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
@@ -1095,7 +1095,7 @@ impl<K, V> Node<K, V> {
10951095
/// When a node has no keys or values and only a single edge, extract that edge.
10961096
pub fn hoist_lone_child(&mut self) {
10971097
// Necessary for correctness, but in a private module
1098-
debug_assert!(self.len() == 0);
1098+
debug_assert!(self.is_empty());
10991099
debug_assert!(!self.is_leaf());
11001100

11011101
unsafe {

src/libcore/slice.rs

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

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

210210
#[inline]
@@ -217,7 +217,7 @@ impl<T> SliceExt for [T] {
217217

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

223223
#[inline]
@@ -311,7 +311,7 @@ impl<T> SliceExt for [T] {
311311

312312
#[inline]
313313
fn first_mut(&mut self) -> Option<&mut T> {
314-
if self.len() == 0 { None } else { Some(&mut self[0]) }
314+
if self.is_empty() { None } else { Some(&mut self[0]) }
315315
}
316316

317317
#[inline]
@@ -1492,7 +1492,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
14921492

14931493
#[inline]
14941494
fn next(&mut self) -> Option<&'a [T]> {
1495-
if self.v.len() == 0 {
1495+
if self.v.is_empty() {
14961496
None
14971497
} else {
14981498
let chunksz = cmp::min(self.v.len(), self.size);
@@ -1504,7 +1504,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
15041504

15051505
#[inline]
15061506
fn size_hint(&self) -> (usize, Option<usize>) {
1507-
if self.v.len() == 0 {
1507+
if self.v.is_empty() {
15081508
(0, Some(0))
15091509
} else {
15101510
let n = self.v.len() / self.size;
@@ -1519,7 +1519,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
15191519
impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
15201520
#[inline]
15211521
fn next_back(&mut self) -> Option<&'a [T]> {
1522-
if self.v.len() == 0 {
1522+
if self.v.is_empty() {
15231523
None
15241524
} else {
15251525
let remainder = self.v.len() % self.size;
@@ -1570,7 +1570,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
15701570

15711571
#[inline]
15721572
fn next(&mut self) -> Option<&'a mut [T]> {
1573-
if self.v.len() == 0 {
1573+
if self.v.is_empty() {
15741574
None
15751575
} else {
15761576
let sz = cmp::min(self.v.len(), self.chunk_size);
@@ -1583,7 +1583,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
15831583

15841584
#[inline]
15851585
fn size_hint(&self) -> (usize, Option<usize>) {
1586-
if self.v.len() == 0 {
1586+
if self.v.is_empty() {
15871587
(0, Some(0))
15881588
} else {
15891589
let n = self.v.len() / self.chunk_size;
@@ -1598,7 +1598,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
15981598
impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
15991599
#[inline]
16001600
fn next_back(&mut self) -> Option<&'a mut [T]> {
1601-
if self.v.len() == 0 {
1601+
if self.v.is_empty() {
16021602
None
16031603
} else {
16041604
let remainder = self.v.len() % self.chunk_size;

src/libcore/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ enum OldSearcher {
10131013
impl OldSearcher {
10141014
#[allow(dead_code)]
10151015
fn new(haystack: &[u8], needle: &[u8]) -> OldSearcher {
1016-
if needle.len() == 0 {
1016+
if needle.is_empty() {
10171017
// Handle specially
10181018
unimplemented!()
10191019
// FIXME: Tune this.

src/libcore/str/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher,
406406
{
407407
if m.done {
408408
SearchStep::Done
409-
} else if m.needle.len() == 0 && m.start <= m.end {
409+
} else if m.needle.is_empty() && m.start <= m.end {
410410
// Case for needle == ""
411411
if m.start == m.end {
412412
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
@@ -82,7 +82,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
8282
(None, Some(sess)) => sess.err(s),
8383
}
8484
};
85-
if s.len() == 0 {
85+
if s.is_empty() {
8686
say("crate name must not be empty", false);
8787
} else if s.contains("-") {
8888
say(&format!("crate names soon cannot contain hyphens: {}", s), true);

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
@@ -1751,7 +1751,7 @@ fn encode_codemap(ecx: &EncodeContext, rbml_w: &mut Encoder) {
17511751

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

1754-
if filemap.lines.borrow().len() == 0 || filemap.is_imported() {
1754+
if filemap.lines.borrow().is_empty() || filemap.is_imported() {
17551755
// No need to export empty filemaps, as they can't contain spans
17561756
// that need translation.
17571757
// 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) -> uint {

src/librustc/middle/traits/fulfill.rs

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

299-
if errors.len() == 0 {
299+
if errors.is_empty() {
300300
Ok(())
301301
} else {
302302
Err(errors)

src/librustc/middle/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
686686
// is checked for in `evaluate_stack` (and hence users
687687
// who might care about this case, like coherence, should use
688688
// that function).
689-
if candidates.len() == 0 {
689+
if candidates.is_empty() {
690690
return Err(Unimplemented);
691691
}
692692

@@ -848,7 +848,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
848848
try!(self.assemble_candidates_from_caller_bounds(stack, &mut candidates));
849849
// Default implementations have lower priority, so we only
850850
// consider triggering a default if there is no other impl that can apply.
851-
if candidates.vec.len() == 0 {
851+
if candidates.vec.is_empty() {
852852
try!(self.assemble_candidates_from_default_impls(obligation, &mut candidates));
853853
}
854854
debug!("candidate list size: {}", candidates.vec.len());

src/librustc/middle/ty.rs

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

30653065
fn bound_list_is_sorted(bounds: &[ty::PolyProjectionPredicate]) -> bool {
3066-
bounds.len() == 0 ||
3066+
bounds.is_empty() ||
30673067
bounds[1..].iter().enumerate().all(
30683068
|(index, bound)| bounds[index].sort_key() <= bound.sort_key())
30693069
}
@@ -3720,7 +3720,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
37203720
if variants.len() == 2 {
37213721
let mut data_idx = 0;
37223722

3723-
if variants[0].args.len() == 0 {
3723+
if variants[0].args.is_empty() {
37243724
data_idx = 1;
37253725
}
37263726

@@ -4233,10 +4233,10 @@ pub fn type_is_c_like_enum(cx: &ctxt, ty: Ty) -> bool {
42334233
match ty.sty {
42344234
ty_enum(did, _) => {
42354235
let variants = enum_variants(cx, did);
4236-
if variants.len() == 0 {
4236+
if variants.is_empty() {
42374237
false
42384238
} else {
4239-
variants.iter().all(|v| v.args.len() == 0)
4239+
variants.iter().all(|v| v.args.is_empty())
42404240
}
42414241
}
42424242
_ => false

src/librustc/session/config.rs

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

src/librustc/util/ppaux.rs

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

12721272
let value_str = unbound_value.user_string(tcx);
1273-
if names.len() == 0 {
1273+
if names.is_empty() {
12741274
value_str
12751275
} else {
12761276
format!("for<{}> {}", names.connect(","), value_str)

src/librustc_driver/driver.rs

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

src/librustc_driver/lib.rs

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

src/librustc_driver/pretty.rs

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

674674
match code {
675-
_ if variants.len() == 0 => {
675+
_ if variants.is_empty() => {
676676
let r = dot::render(&lcfg, &mut out);
677677
return expand_err_details(r);
678678
}

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)