about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-16 03:22:21 +0000
committerbors <bors@rust-lang.org>2015-04-16 03:22:21 +0000
commit288809c8f35d9b37f2e4f5c3ac168f56dbc3bbc4 (patch)
tree2606f4c9c39c215161feb41a74348d7e07d79c1c /src/libsyntax
parente40449e0d545561c73a9b9b324b5971b533a87b7 (diff)
parentc55ae1dc3094912c935fb95cf915841af0259305 (diff)
downloadrust-288809c8f35d9b37f2e4f5c3ac168f56dbc3bbc4.tar.gz
rust-288809c8f35d9b37f2e4f5c3ac168f56dbc3bbc4.zip
Auto merge of #23682 - tamird:DRY-is-empty, r=alexcrichton
r? @alexcrichton 
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs10
-rw-r--r--src/libsyntax/codemap.rs8
-rw-r--r--src/libsyntax/ext/asm.rs6
-rw-r--r--src/libsyntax/ext/base.rs2
-rw-r--r--src/libsyntax/ext/deriving/clone.rs2
-rw-r--r--src/libsyntax/ext/deriving/encodable.rs2
-rw-r--r--src/libsyntax/ext/deriving/generic/mod.rs4
-rw-r--r--src/libsyntax/ext/env.rs2
-rw-r--r--src/libsyntax/ext/expand.rs4
-rw-r--r--src/libsyntax/ext/format.rs2
-rw-r--r--src/libsyntax/ext/mtwt.rs2
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs10
-rw-r--r--src/libsyntax/parse/lexer/comments.rs4
-rw-r--r--src/libsyntax/parse/parser.rs18
-rw-r--r--src/libsyntax/print/pp.rs2
-rw-r--r--src/libsyntax/print/pprust.rs10
16 files changed, 44 insertions, 44 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 40390765dde..26463df1871 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -429,14 +429,14 @@ pub struct Generics {
 }
 
 impl Generics {
-    pub fn is_parameterized(&self) -> bool {
-        self.lifetimes.len() + self.ty_params.len() > 0
-    }
     pub fn is_lt_parameterized(&self) -> bool {
-        self.lifetimes.len() > 0
+        !self.lifetimes.is_empty()
     }
     pub fn is_type_parameterized(&self) -> bool {
-        self.ty_params.len() > 0
+        !self.ty_params.is_empty()
+    }
+    pub fn is_parameterized(&self) -> bool {
+        self.is_lt_parameterized() || self.is_type_parameterized()
     }
 }
 
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 5bbf79d0477..a0bde8f6c52 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -360,7 +360,7 @@ impl Encodable for FileMap {
                     // store the length
                     try! { s.emit_u32(lines.len() as u32) };
 
-                    if lines.len() > 0 {
+                    if !lines.is_empty() {
                         // In order to preserve some space, we exploit the fact that
                         // the lines list is sorted and individual lines are
                         // probably not that long. Because of that we can store lines
@@ -569,7 +569,7 @@ impl CodeMap {
         // accidentally overflowing into the next filemap in case the last byte
         // of span is also the last byte of filemap, which leads to incorrect
         // results from CodeMap.span_to_*.
-        if src.len() > 0 && !src.ends_with("\n") {
+        if !src.is_empty() && !src.ends_with("\n") {
             src.push('\n');
         }
 
@@ -652,7 +652,7 @@ impl CodeMap {
     }
 
     pub fn span_to_string(&self, sp: Span) -> String {
-        if self.files.borrow().len() == 0 && sp == DUMMY_SP {
+        if self.files.borrow().is_empty() && sp == DUMMY_SP {
             return "no-location".to_string();
         }
 
@@ -808,7 +808,7 @@ impl CodeMap {
         loop {
             let lines = files[a].lines.borrow();
             let lines = lines;
-            if lines.len() > 0 {
+            if !lines.is_empty() {
                 break;
             }
             if a == 0 {
diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs
index f2b45d89f73..69159690328 100644
--- a/src/libsyntax/ext/asm.rs
+++ b/src/libsyntax/ext/asm.rs
@@ -90,7 +90,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
                       p.token != token::Colon &&
                       p.token != token::ModSep {
 
-                    if outputs.len() != 0 {
+                    if !outputs.is_empty() {
                         panictry!(p.eat(&token::Comma));
                     }
 
@@ -130,7 +130,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
                       p.token != token::Colon &&
                       p.token != token::ModSep {
 
-                    if inputs.len() != 0 {
+                    if !inputs.is_empty() {
                         panictry!(p.eat(&token::Comma));
                     }
 
@@ -154,7 +154,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
                       p.token != token::Colon &&
                       p.token != token::ModSep {
 
-                    if clobs.len() != 0 {
+                    if !clobs.is_empty() {
                         panictry!(p.eat(&token::Comma));
                     }
 
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 9994fad3e31..9e36c75dda4 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -774,7 +774,7 @@ pub fn check_zero_tts(cx: &ExtCtxt,
                       sp: Span,
                       tts: &[ast::TokenTree],
                       name: &str) {
-    if tts.len() != 0 {
+    if !tts.is_empty() {
         cx.span_err(sp, &format!("{} takes no arguments", name));
     }
 }
diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs
index f89f3ab55f3..95eb68ca0d3 100644
--- a/src/libsyntax/ext/deriving/clone.rs
+++ b/src/libsyntax/ext/deriving/clone.rs
@@ -89,7 +89,7 @@ fn cs_clone(
         }
     }
 
-    if all_fields.len() >= 1 && all_fields[0].name.is_none() {
+    if !all_fields.is_empty() && all_fields[0].name.is_none() {
         // enum-like
         let subcalls = all_fields.iter().map(subcall).collect();
         let path = cx.expr_path(ctor_path);
diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs
index 06255f46779..6425e6a28ec 100644
--- a/src/libsyntax/ext/deriving/encodable.rs
+++ b/src/libsyntax/ext/deriving/encodable.rs
@@ -240,7 +240,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span,
             let encoder = cx.expr_ident(trait_span, blkarg);
             let emit_variant_arg = cx.ident_of("emit_enum_variant_arg");
             let mut stmts = Vec::new();
-            if fields.len() > 0 {
+            if !fields.is_empty() {
                 let last = fields.len() - 1;
                 for (i, &FieldInfo { ref self_, span, .. }) in fields.iter().enumerate() {
                     let enc = cx.expr_method_call(span, self_.clone(),
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs
index ac96375095e..7f6f29df530 100644
--- a/src/libsyntax/ext/deriving/generic/mod.rs
+++ b/src/libsyntax/ext/deriving/generic/mod.rs
@@ -912,7 +912,7 @@ impl<'a> MethodDef<'a> {
         }
 
         // transpose raw_fields
-        let fields = if raw_fields.len() > 0 {
+        let fields = if !raw_fields.is_empty() {
             let mut raw_fields = raw_fields.into_iter().map(|v| v.into_iter());
             let first_field = raw_fields.next().unwrap();
             let mut other_fields: Vec<vec::IntoIter<(Span, Option<Ident>, P<Expr>)>>
@@ -1248,7 +1248,7 @@ impl<'a> MethodDef<'a> {
 
             match_arms.push(catch_all_match_arm);
 
-        } else if variants.len() == 0 {
+        } else if variants.is_empty() {
             // As an additional wrinkle, For a zero-variant enum A,
             // currently the compiler
             // will accept `fn (a: &Self) { match   *a   { } }`
diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs
index f72303985e7..2ca74644b3b 100644
--- a/src/libsyntax/ext/env.rs
+++ b/src/libsyntax/ext/env.rs
@@ -65,7 +65,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenT
 pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
                        -> Box<base::MacResult+'cx> {
     let mut exprs = match get_exprs_from_tts(cx, sp, tts) {
-        Some(ref exprs) if exprs.len() == 0 => {
+        Some(ref exprs) if exprs.is_empty() => {
             cx.span_err(sp, "env! takes 1 or 2 arguments");
             return DummyResult::expr(sp);
         }
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index b65798b8a49..74ec219af15 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -841,7 +841,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
 fn expand_arm(arm: ast::Arm, fld: &mut MacroExpander) -> ast::Arm {
     // expand pats... they might contain macro uses:
     let expanded_pats = arm.pats.move_map(|pat| fld.fold_pat(pat));
-    if expanded_pats.len() == 0 {
+    if expanded_pats.is_empty() {
         panic!("encountered match arm with 0 patterns");
     }
     // all of the pats must have the same set of bindings, so use the
@@ -1887,7 +1887,7 @@ mod test {
             let binding_name = mtwt::resolve(bindings[binding_idx]);
             let binding_marks = mtwt::marksof(bindings[binding_idx].ctxt, invalid_name);
             // shouldmatch can't name varrefs that don't exist:
-            assert!((shouldmatch.len() == 0) ||
+            assert!((shouldmatch.is_empty()) ||
                     (varrefs.len() > *shouldmatch.iter().max().unwrap()));
             for (idx,varref) in varrefs.iter().enumerate() {
                 let print_hygiene_debug_info = || {
diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs
index 374f6fa5040..4fe5ab15545 100644
--- a/src/libsyntax/ext/format.rs
+++ b/src/libsyntax/ext/format.rs
@@ -688,7 +688,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
     loop {
         match parser.next() {
             Some(piece) => {
-                if parser.errors.len() > 0 { break }
+                if !parser.errors.is_empty() { break }
                 cx.verify_piece(&piece);
                 match cx.trans_piece(&piece) {
                     Some(piece) => {
diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs
index f514f72d565..ce83b84efee 100644
--- a/src/libsyntax/ext/mtwt.rs
+++ b/src/libsyntax/ext/mtwt.rs
@@ -266,7 +266,7 @@ pub fn outer_mark(ctxt: SyntaxContext) -> Mrk {
 /// Push a name... unless it matches the one on top, in which
 /// case pop and discard (so two of the same marks cancel)
 fn xor_push(marks: &mut Vec<Mrk>, mark: Mrk) {
-    if (marks.len() > 0) && (*marks.last().unwrap() == mark) {
+    if (!marks.is_empty()) && (*marks.last().unwrap() == mark) {
         marks.pop().unwrap();
     } else {
         marks.push(mark);
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index 4e0b74401a2..9c3a556b210 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -457,7 +457,7 @@ pub fn parse(sess: &ParseSess,
                 return Failure(sp, "unexpected end of macro invocation".to_string());
             }
         } else {
-            if (bb_eis.len() > 0 && next_eis.len() > 0)
+            if (!bb_eis.is_empty() && !next_eis.is_empty())
                 || bb_eis.len() > 1 {
                 let nts = bb_eis.iter().map(|ei| {
                     match ei.top_elts.get_tt(ei.idx) {
@@ -472,12 +472,12 @@ pub fn parse(sess: &ParseSess,
                     "local ambiguity: multiple parsing options: \
                      built-in NTs {} or {} other options.",
                     nts, next_eis.len()).to_string());
-            } else if bb_eis.len() == 0 && next_eis.len() == 0 {
+            } else if bb_eis.is_empty() && next_eis.is_empty() {
                 return Failure(sp, format!("no rules expected the token `{}`",
                             pprust::token_to_string(&tok)).to_string());
-            } else if next_eis.len() > 0 {
+            } else if !next_eis.is_empty() {
                 /* Now process the next token */
-                while next_eis.len() > 0 {
+                while !next_eis.is_empty() {
                     cur_eis.push(next_eis.pop().unwrap());
                 }
                 rdr.next_token();
@@ -504,7 +504,7 @@ pub fn parse(sess: &ParseSess,
             }
         }
 
-        assert!(cur_eis.len() > 0);
+        assert!(!cur_eis.is_empty());
     }
 }
 
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs
index 277f5365db3..bda01d5a654 100644
--- a/src/libsyntax/parse/lexer/comments.rs
+++ b/src/libsyntax/parse/lexer/comments.rs
@@ -63,7 +63,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
         let mut i = 0;
         let mut j = lines.len();
         // first line of all-stars should be omitted
-        if lines.len() > 0 &&
+        if !lines.is_empty() &&
                 lines[0].chars().all(|c| c == '*') {
             i += 1;
         }
@@ -294,7 +294,7 @@ fn read_block_comment(rdr: &mut StringReader,
                 }
             }
         }
-        if curr_line.len() != 0 {
+        if !curr_line.is_empty() {
             trim_whitespace_prefix_and_push_line(&mut lines,
                                                  curr_line,
                                                  col);
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index bef2068f0dd..0515d1ae945 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -449,7 +449,7 @@ impl<'a> Parser<'a> {
                     (format!("expected one of {}, found `{}`",
                              expect,
                              actual))
-                } else if expected.len() == 0 {
+                } else if expected.is_empty() {
                     (format!("unexpected token: `{}`",
                              actual))
                 } else {
@@ -1244,7 +1244,7 @@ impl<'a> Parser<'a> {
 
         // In type grammar, `+` is treated like a binary operator,
         // and hence both L and R side are required.
-        if bounds.len() == 0 {
+        if bounds.is_empty() {
             let last_span = self.last_span;
             self.span_err(last_span,
                           "at least one type parameter bound \
@@ -2191,7 +2191,7 @@ impl<'a> Parser<'a> {
                                                  &[token::CloseDelim(token::Brace)]));
                             }
 
-                            if fields.len() == 0 && base.is_none() {
+                            if fields.is_empty() && base.is_none() {
                                 let last_span = self.last_span;
                                 self.span_err(last_span,
                                               "structure literal must either \
@@ -2254,7 +2254,7 @@ impl<'a> Parser<'a> {
                         (Vec::new(), Vec::new(), Vec::new())
                     };
 
-                    if bindings.len() > 0 {
+                    if !bindings.is_empty() {
                         let last_span = self.last_span;
                         self.span_err(last_span, "type bindings are only permitted on trait paths");
                     }
@@ -3024,7 +3024,7 @@ impl<'a> Parser<'a> {
                 try!(self.expect(&token::Comma));
 
                 if self.token == token::CloseDelim(token::Bracket)
-                        && (before_slice || after.len() != 0) {
+                        && (before_slice || !after.is_empty()) {
                     break
                 }
             }
@@ -3914,7 +3914,7 @@ impl<'a> Parser<'a> {
                         let hi = self.span.hi;
                         let span = mk_sp(lo, hi);
 
-                        if bounds.len() == 0 {
+                        if bounds.is_empty() {
                             self.span_err(span,
                                           "each predicate in a `where` clause must have \
                                            at least one bound in it");
@@ -4572,7 +4572,7 @@ impl<'a> Parser<'a> {
                 fields.push(try!(self.parse_struct_decl_field(true)));
             }
 
-            if fields.len() == 0 {
+            if fields.is_empty() {
                 return Err(self.fatal(&format!("unit-like struct definition should be \
                     written as `struct {};`",
                     token::get_ident(class_name.clone()))));
@@ -4611,7 +4611,7 @@ impl<'a> Parser<'a> {
                     Ok(spanned(lo, p.span.hi, struct_field_))
                 }));
 
-            if fields.len() == 0 {
+            if fields.is_empty() {
                 return Err(self.fatal(&format!("unit-like struct definition should be \
                     written as `struct {};`",
                     token::get_ident(class_name.clone()))));
@@ -5023,7 +5023,7 @@ impl<'a> Parser<'a> {
                 all_nullary = false;
                 let start_span = self.span;
                 let struct_def = try!(self.parse_struct_def());
-                if struct_def.fields.len() == 0 {
+                if struct_def.fields.is_empty() {
                     self.span_err(start_span,
                         &format!("unit-like struct variant should be written \
                                  without braces, as `{},`",
diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs
index ebfd970f3db..3fd4e31b477 100644
--- a/src/libsyntax/print/pp.rs
+++ b/src/libsyntax/print/pp.rs
@@ -565,7 +565,7 @@ impl<'a> Printer<'a> {
           Token::End => {
             debug!("print End -> pop End");
             let print_stack = &mut self.print_stack;
-            assert!((print_stack.len() != 0));
+            assert!((!print_stack.is_empty()));
             print_stack.pop().unwrap();
             Ok(())
           }
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 3f883fb1172..c51b5d03978 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1656,7 +1656,7 @@ impl<'a> State<'a> {
         try!(self.print_expr(&*args[0]));
         try!(word(&mut self.s, "."));
         try!(self.print_ident(ident.node));
-        if tys.len() > 0 {
+        if !tys.is_empty() {
             try!(word(&mut self.s, "::<"));
             try!(self.commasep(Inconsistent, tys,
                                |s, ty| s.print_type(&**ty)));
@@ -1956,7 +1956,7 @@ impl<'a> State<'a> {
                     options.push("intel");
                 }
 
-                if options.len() > 0 {
+                if !options.is_empty() {
                     try!(space(&mut self.s));
                     try!(self.word_space(":"));
                     try!(self.commasep(Inconsistent, &*options,
@@ -2214,7 +2214,7 @@ impl<'a> State<'a> {
                     },
                     |f| f.node.pat.span));
                 if etc {
-                    if fields.len() != 0 { try!(self.word_space(",")); }
+                    if !fields.is_empty() { try!(self.word_space(",")); }
                     try!(word(&mut self.s, ".."));
                 }
                 try!(space(&mut self.s));
@@ -2546,7 +2546,7 @@ impl<'a> State<'a> {
 
     pub fn print_where_clause(&mut self, where_clause: &ast::WhereClause)
                               -> io::Result<()> {
-        if where_clause.predicates.len() == 0 {
+        if where_clause.predicates.is_empty() {
             return Ok(())
         }
 
@@ -2727,7 +2727,7 @@ impl<'a> State<'a> {
                        opt_explicit_self: Option<&ast::ExplicitSelf_>)
                        -> io::Result<()> {
         try!(self.ibox(indent_unit));
-        if generics.lifetimes.len() > 0 || generics.ty_params.len() > 0 {
+        if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() {
             try!(word(&mut self.s, "for"));
             try!(self.print_generics(generics));
         }