Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Positive case of len() -> is_empty()
`s/(?<!\{ self)(?<=\.)len\(\) == 0/is_empty()/g`
  • Loading branch information
tamird committed Apr 15, 2015
commit 29ac04402d53d358a1f6200bea45a301ff05b2d1
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
}
first = false;
}
if !failed && rest.len() == 0 {
if !failed && rest.is_empty() {
i += 1;
}
if i == num_check_lines {
Expand Down Expand Up @@ -1662,7 +1662,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
// codegen tests (vs. clang)

fn append_suffix_to_stem(p: &Path, suffix: &str) -> PathBuf {
if suffix.len() == 0 {
if suffix.is_empty() {
p.to_path_buf()
} else {
let mut stem = p.file_stem().unwrap().to_os_string();
Expand Down
2 changes: 1 addition & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3788,7 +3788,7 @@ its type parameters are types:

```ignore
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
if xs.len() == 0 {
if xs.is_empty() {
return vec![];
}
let first: B = f(xs[0].clone());
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ mod stack {
// We've reached the root, so no matter what, we're done. We manually
// access the root via the tree itself to avoid creating any dangling
// pointers.
if self.map.root.len() == 0 && !self.map.root.is_leaf() {
if self.map.root.is_empty() && !self.map.root.is_leaf() {
// We've emptied out the root, so make its only child the new root.
// If it's a leaf, we just let it become empty.
self.map.depth -= 1;
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ impl<K, V> Node<K, V> {
/// When a node has no keys or values and only a single edge, extract that edge.
pub fn hoist_lone_child(&mut self) {
// Necessary for correctness, but in a private module
debug_assert!(self.len() == 0);
debug_assert!(self.is_empty());
debug_assert!(!self.is_leaf());

unsafe {
Expand Down
18 changes: 9 additions & 9 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<T> SliceExt for [T] {

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

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

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

#[inline]
Expand Down Expand Up @@ -296,7 +296,7 @@ impl<T> SliceExt for [T] {

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

#[inline]
Expand Down Expand Up @@ -1306,7 +1306,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {

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

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
if self.v.len() == 0 {
if self.v.is_empty() {
(0, Some(0))
} else {
let n = self.v.len() / self.size;
Expand All @@ -1333,7 +1333,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a [T]> {
if self.v.len() == 0 {
if self.v.is_empty() {
None
} else {
let remainder = self.v.len() % self.size;
Expand Down Expand Up @@ -1384,7 +1384,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {

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

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
if self.v.len() == 0 {
if self.v.is_empty() {
(0, Some(0))
} else {
let n = self.v.len() / self.chunk_size;
Expand All @@ -1412,7 +1412,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<&'a mut [T]> {
if self.v.len() == 0 {
if self.v.is_empty() {
None
} else {
let remainder = self.v.len() % self.chunk_size;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ enum OldSearcher {
impl OldSearcher {
#[allow(dead_code)]
fn new(haystack: &[u8], needle: &[u8]) -> OldSearcher {
if needle.len() == 0 {
if needle.is_empty() {
// Handle specially
unimplemented!()
// FIXME: Tune this.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher,
{
if m.state.done() {
SearchStep::Done
} else if m.needle.len() == 0 && m.start <= m.end {
} else if m.needle.is_empty() && m.start <= m.end {
// Case for needle == ""
if let State::Reject(a, b) = m.state.take() {
SearchStep::Reject(a, b)
Expand Down
2 changes: 1 addition & 1 deletion src/liblog/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
return (dirs, None);
}
mods.map(|m| { for s in m.split(',') {
if s.len() == 0 { continue }
if s.is_empty() { continue }
let mut parts = s.split('=');
let (log_level, name) = match (parts.next(), parts.next().map(|s| s.trim()), parts.next()) {
(Some(part0), None, None) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
(None, Some(sess)) => sess.err(s),
}
};
if s.len() == 0 {
if s.is_empty() {
say("crate name must not be empty");
}
for c in s.chars() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
get_type(cdata, field_ty.id.node, tcx).ty
})
.collect();
let arg_names = if arg_names.len() == 0 { None } else { Some(arg_names) };
let arg_names = if arg_names.is_empty() { None } else { Some(arg_names) };

(None, arg_tys, arg_names)
}
Expand Down Expand Up @@ -1383,7 +1383,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)

debug!("found dylib deps: {}", formats.as_str_slice());
for spec in formats.as_str_slice().split(',') {
if spec.len() == 0 { continue }
if spec.is_empty() { continue }
let cnum = spec.split(':').nth(0).unwrap();
let link = spec.split(':').nth(1).unwrap();
let cnum: ast::CrateNum = cnum.parse().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ fn encode_codemap(ecx: &EncodeContext, rbml_w: &mut Encoder) {

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

if filemap.lines.borrow().len() == 0 || filemap.is_imported() {
if filemap.lines.borrow().is_empty() || filemap.is_imported() {
// No need to export empty filemaps, as they can't contain spans
// that need translation.
// Also no need to re-export imported filemaps, as any downstream
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl<'a> Context<'a> {
// library's metadata sections. In theory we should
// read both, but reading dylib metadata is quite
// slow.
if m.len() == 0 {
if m.is_empty() {
return None
} else if m.len() == 1 {
return Some(m.into_iter().next().unwrap())
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
if let Some(DefLocal(_)) = def {
if ty::enum_variants(cx.tcx, def_id).iter().any(|variant|
token::get_name(variant.name) == token::get_name(ident.node.name)
&& variant.args.len() == 0
&& variant.args.is_empty()
) {
span_warn!(cx.tcx.sess, p.span, E0170,
"pattern binding `{}` is named the same as one \
Expand Down Expand Up @@ -636,19 +636,19 @@ fn is_useful(cx: &MatchCheckCtxt,
-> Usefulness {
let &Matrix(ref rows) = matrix;
debug!("{:?}", matrix);
if rows.len() == 0 {
if rows.is_empty() {
return match witness {
ConstructWitness => UsefulWithWitness(vec!()),
LeaveOutWitness => Useful
};
}
if rows[0].len() == 0 {
if rows[0].is_empty() {
return NotUseful;
}
assert!(rows.iter().all(|r| r.len() == v.len()));
let real_pat = match rows.iter().find(|r| (*r)[0].id != DUMMY_NODE_ID) {
Some(r) => raw_pat(r[0]),
None if v.len() == 0 => return NotUseful,
None if v.is_empty() => return NotUseful,
None => v[0]
};
let left_ty = if real_pat.id == DUMMY_NODE_ID {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
let lifetimes =
path.segments.last().unwrap().parameters.lifetimes();
let mut insert = Vec::new();
if lifetimes.len() == 0 {
if lifetimes.is_empty() {
let anon = self.cur_anon.get();
for (i, a) in (anon..anon+expected).enumerate() {
if anon_nums.contains(&a) {
Expand Down Expand Up @@ -1361,7 +1361,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {

ast::AngleBracketedParameters(ref data) => {
let mut new_lts = Vec::new();
if data.lifetimes.len() == 0 {
if data.lifetimes.is_empty() {
// traverse once to see if there's a need to insert lifetime
let need_insert = (0..expected).any(|i| {
indexes.contains(&i)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/region_inference/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
Err(_) => "/tmp/constraints.node%.dot".to_string(),
};

if output_template.len() == 0 {
if output_template.is_empty() {
tcx.sess.bug("empty string provided as RUST_REGION_GRAPH");
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
None => {
// Vanilla 'break' or 'loop', so use the enclosing
// loop scope
if self.loop_scope.len() == 0 {
if self.loop_scope.is_empty() {
self.ir.tcx.sess.span_bug(sp, "break outside loop");
} else {
*self.loop_scope.last().unwrap()
Expand Down Expand Up @@ -1586,7 +1586,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

fn should_warn(&self, var: Variable) -> Option<String> {
let name = self.ir.variable_name(var);
if name.len() == 0 || name.as_bytes()[0] == ('_' as u8) {
if name.is_empty() || name.as_bytes()[0] == ('_' as u8) {
None
} else {
Some(name)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl<T> VecPerParamSpace<T> {
pub fn get_self<'a>(&'a self) -> Option<&'a T> {
let v = self.get_slice(SelfSpace);
assert!(v.len() <= 1);
if v.len() == 0 { None } else { Some(&v[0]) }
if v.is_empty() { None } else { Some(&v[0]) }
}

pub fn len(&self, space: ParamSpace) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
self.predicates.len(),
errors.len());

if errors.len() == 0 {
if errors.is_empty() {
Ok(())
} else {
Err(errors)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// is checked for in `evaluate_stack` (and hence users
// who might care about this case, like coherence, should use
// that function).
if candidates.len() == 0 {
if candidates.is_empty() {
return Err(Unimplemented);
}

Expand Down Expand Up @@ -873,7 +873,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
try!(self.assemble_candidates_from_caller_bounds(stack, &mut candidates));
// Default implementations have lower priority, so we only
// consider triggering a default if there is no other impl that can apply.
if candidates.vec.len() == 0 {
if candidates.vec.is_empty() {
try!(self.assemble_candidates_from_default_impls(obligation, &mut candidates));
}
debug!("candidate list size: {}", candidates.vec.len());
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,7 @@ pub fn mk_trait<'tcx>(cx: &ctxt<'tcx>,
}

fn bound_list_is_sorted(bounds: &[ty::PolyProjectionPredicate]) -> bool {
bounds.len() == 0 ||
bounds.is_empty() ||
bounds[1..].iter().enumerate().all(
|(index, bound)| bounds[index].sort_key() <= bound.sort_key())
}
Expand Down Expand Up @@ -3687,7 +3687,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
if variants.len() == 2 {
let mut data_idx = 0;

if variants[0].args.len() == 0 {
if variants[0].args.is_empty() {
data_idx = 1;
}

Expand Down Expand Up @@ -4200,10 +4200,10 @@ pub fn type_is_c_like_enum(cx: &ctxt, ty: Ty) -> bool {
match ty.sty {
ty_enum(did, _) => {
let variants = enum_variants(cx, did);
if variants.len() == 0 {
if variants.is_empty() {
false
} else {
variants.iter().all(|v| v.args.len() == 0)
variants.iter().all(|v| v.args.is_empty())
}
}
_ => false
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
};
output_types.sort();
output_types.dedup();
if output_types.len() == 0 {
if output_types.is_empty() {
output_types.push(OutputTypeExe);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ impl<'tcx, T> UserString<'tcx> for ty::Binder<T>
let names: Vec<_> = names.iter().map(|s| &s[..]).collect();

let value_str = unbound_value.user_string(tcx);
if names.len() == 0 {
if names.is_empty() {
value_str
} else {
format!("for<{}> {}", names.connect(","), value_str)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,9 @@ pub fn collect_crate_types(session: &Session,
// command line, then reuse the empty `base` Vec to hold the types that
// will be found in crate attributes.
let mut base = session.opts.crate_types.clone();
if base.len() == 0 {
if base.is_empty() {
base.extend(attr_types.into_iter());
if base.len() == 0 {
if base.is_empty() {
base.push(link::default_output_for_target(session));
}
base.sort();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ impl RustcDefaultCalls {
odir: &Option<PathBuf>,
ofile: &Option<PathBuf>)
-> Compilation {
if sess.opts.prints.len() == 0 {
if sess.opts.prints.is_empty() {
return Compilation::Continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ fn print_flowgraph<W: Write>(variants: Vec<borrowck_dot::Variant>,
};

match code {
_ if variants.len() == 0 => {
_ if variants.is_empty() => {
let r = dot::render(&lcfg, &mut out);
return expand_err_details(r);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
f.name
}).collect::<Vec<_>>();

if fields.len() == 0 {
if fields.is_empty() {
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
}

Expand Down
Loading