mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-14 13:06:49 +00:00
commit
ca39467cde
@ -216,7 +216,7 @@ impl Rewrite for ast::Block {
|
||||
// Extract comment between unsafe and block start.
|
||||
let trimmed = &snippet[6..open_pos].trim();
|
||||
|
||||
if trimmed.len() > 0 {
|
||||
if !trimmed.is_empty() {
|
||||
// 9 = "unsafe {".len(), 7 = "unsafe ".len()
|
||||
format!("unsafe {} ", rewrite_comment(trimmed, true, width - 9, offset + 7))
|
||||
} else {
|
||||
@ -733,7 +733,7 @@ fn rewrite_call(context: &RewriteContext,
|
||||
let callee_str = try_opt!(callee.rewrite(context, max_callee_width, offset));
|
||||
debug!("rewrite_call, callee_str: `{}`", callee_str);
|
||||
|
||||
if args.len() == 0 {
|
||||
if args.is_empty() {
|
||||
return Some(format!("{}()", callee_str));
|
||||
}
|
||||
|
||||
@ -799,7 +799,7 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
|
||||
offset: usize)
|
||||
-> Option<String> {
|
||||
debug!("rewrite_struct_lit: width {}, offset {}", width, offset);
|
||||
assert!(fields.len() > 0 || base.is_some());
|
||||
assert!(!fields.is_empty() || base.is_some());
|
||||
|
||||
enum StructLitField<'a> {
|
||||
Regular(&'a ast::Field),
|
||||
@ -1008,7 +1008,7 @@ fn rewrite_unary_op(context: &RewriteContext,
|
||||
ast::UnOp::UnNeg => "-",
|
||||
};
|
||||
|
||||
let subexpr = try_opt!(expr.rewrite(context, width - operator_str.len(), offset));
|
||||
let subexpr = try_opt!(expr.rewrite(context, try_opt!(width.checked_sub(operator_str.len())), offset));
|
||||
|
||||
Some(format!("{}{}", operator_str, subexpr))
|
||||
}
|
||||
|
@ -51,13 +51,13 @@ impl Rewrite for ast::ViewPath {
|
||||
|
||||
fn rewrite_single_use_list(path_str: String, vpi: ast::PathListItem) -> String {
|
||||
if let ast::PathListItem_::PathListIdent{ name, .. } = vpi.node {
|
||||
if path_str.len() == 0 {
|
||||
if path_str.is_empty() {
|
||||
name.to_string()
|
||||
} else {
|
||||
format!("{}::{}", path_str, name)
|
||||
}
|
||||
} else {
|
||||
if path_str.len() != 0 {
|
||||
if !path_str.is_empty() {
|
||||
path_str
|
||||
} else {
|
||||
// This catches the import: use {self}, which is a compiler error, so we just
|
||||
@ -86,7 +86,7 @@ pub fn rewrite_use_list(width: usize,
|
||||
}
|
||||
|
||||
// 2 = ::
|
||||
let path_separation_w = if path_str.len() > 0 {
|
||||
let path_separation_w = if !path_str.is_empty() {
|
||||
2
|
||||
} else {
|
||||
0
|
||||
@ -151,7 +151,7 @@ pub fn rewrite_use_list(width: usize,
|
||||
|
||||
let list = write_list(&items[first_index..], &fmt);
|
||||
|
||||
Some(if path_str.len() == 0 {
|
||||
Some(if path_str.is_empty() {
|
||||
format!("{{{}}}", list)
|
||||
} else {
|
||||
format!("{}::{{{}}}", path_str, list)
|
||||
|
26
src/items.rs
26
src/items.rs
@ -178,7 +178,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
result.push(')');
|
||||
|
||||
// Return type.
|
||||
if ret_str.len() > 0 {
|
||||
if !ret_str.is_empty() {
|
||||
// If we've already gone multi-line, or the return type would push
|
||||
// over the max width, then put the return type on a new line.
|
||||
if result.contains("\n") ||
|
||||
@ -200,11 +200,11 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
// Comment between return type and the end of the decl.
|
||||
let snippet_lo = fd.output.span().hi;
|
||||
if where_clause.predicates.len() == 0 {
|
||||
if where_clause.predicates.is_empty() {
|
||||
let snippet_hi = span.hi;
|
||||
let snippet = self.snippet(codemap::mk_sp(snippet_lo, snippet_hi));
|
||||
let snippet = snippet.trim();
|
||||
if snippet.len() > 0 {
|
||||
if !snippet.is_empty() {
|
||||
result.push(' ');
|
||||
result.push_str(snippet);
|
||||
}
|
||||
@ -342,7 +342,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
fn newline_for_brace(&self, where_clause: &ast::WhereClause) -> bool {
|
||||
match self.config.fn_brace_style {
|
||||
BraceStyle::AlwaysNextLine => true,
|
||||
BraceStyle::SameLineWhere if where_clause.predicates.len() > 0 => true,
|
||||
BraceStyle::SameLineWhere if !where_clause.predicates.is_empty() => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -399,7 +399,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
let mut result = String::new();
|
||||
|
||||
if types.len() > 0 {
|
||||
if !types.is_empty() {
|
||||
let items = itemize_list(self.codemap,
|
||||
types.iter(),
|
||||
")",
|
||||
@ -482,7 +482,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
let header_str = self.format_header(item_name, ident, vis);
|
||||
result.push_str(&header_str);
|
||||
|
||||
if struct_def.fields.len() == 0 {
|
||||
if struct_def.fields.is_empty() {
|
||||
result.push(';');
|
||||
return result;
|
||||
}
|
||||
@ -513,7 +513,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
terminator,
|
||||
|field| {
|
||||
// Include attributes and doc comments, if present
|
||||
if field.node.attrs.len() > 0 {
|
||||
if !field.node.attrs.is_empty() {
|
||||
field.node.attrs[0].span.lo
|
||||
} else {
|
||||
field.span.lo
|
||||
@ -602,7 +602,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
-> String {
|
||||
let mut result = self.rewrite_generics(generics, offset, span);
|
||||
|
||||
if generics.where_clause.predicates.len() > 0 || result.contains('\n') {
|
||||
if !generics.where_clause.predicates.is_empty() || result.contains('\n') {
|
||||
result.push_str(&self.rewrite_where_clause(&generics.where_clause,
|
||||
self.config,
|
||||
self.block_indent,
|
||||
@ -635,7 +635,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
let indent = self.block_indent + self.config.tab_spaces;
|
||||
let mut attr_str = self.rewrite_attrs(&field.node.attrs, indent);
|
||||
if attr_str.len() > 0 {
|
||||
if !attr_str.is_empty() {
|
||||
attr_str.push('\n');
|
||||
attr_str.push_str(&make_indent(indent));
|
||||
}
|
||||
@ -651,7 +651,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
// there is a where clause at all.
|
||||
let lifetimes: &[_] = &generics.lifetimes;
|
||||
let tys: &[_] = &generics.ty_params;
|
||||
if lifetimes.len() + tys.len() == 0 {
|
||||
if lifetimes.is_empty() && tys.is_empty() {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
@ -671,7 +671,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
// Extract comments between generics.
|
||||
let lt_spans = lifetimes.iter().map(|l| {
|
||||
let hi = if l.bounds.len() == 0 {
|
||||
let hi = if l.bounds.is_empty() {
|
||||
l.lifetime.span.hi
|
||||
} else {
|
||||
l.bounds[l.bounds.len() - 1].span.hi
|
||||
@ -705,7 +705,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
indent: usize,
|
||||
span_end: BytePos)
|
||||
-> String {
|
||||
if where_clause.predicates.len() == 0 {
|
||||
if where_clause.predicates.is_empty() {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
@ -833,7 +833,7 @@ fn span_for_ty_param(ty: &ast::TyParam) -> Span {
|
||||
if let Some(ref def) = ty.default {
|
||||
return codemap::mk_sp(lo, def.span.hi);
|
||||
}
|
||||
if ty.bounds.len() == 0 {
|
||||
if ty.bounds.is_empty() {
|
||||
return ty.span;
|
||||
}
|
||||
let hi = match ty.bounds[ty.bounds.len() - 1] {
|
||||
|
@ -92,7 +92,7 @@ impl ListItem {
|
||||
// FIXME: this has grown into a monstrosity
|
||||
// TODO: add unit tests
|
||||
pub fn write_list<'b>(items: &[ListItem], formatting: &ListFormatting<'b>) -> String {
|
||||
if items.len() == 0 {
|
||||
if items.is_empty() {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
|
||||
(self.get_lo)(&item)))
|
||||
.unwrap();
|
||||
let pre_snippet = pre_snippet.trim();
|
||||
let pre_comment = if pre_snippet.len() > 0 {
|
||||
let pre_comment = if !pre_snippet.is_empty() {
|
||||
Some(pre_snippet.to_owned())
|
||||
} else {
|
||||
None
|
||||
@ -328,7 +328,7 @@ impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
|
||||
post_snippet = post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space);
|
||||
}
|
||||
|
||||
let post_comment = if post_snippet.len() > 0 {
|
||||
let post_comment = if !post_snippet.is_empty() {
|
||||
Some(post_snippet.to_owned())
|
||||
} else {
|
||||
None
|
||||
|
14
src/types.rs
14
src/types.rs
@ -190,9 +190,9 @@ fn rewrite_segment(segment: &ast::PathSegment,
|
||||
let offset = offset + ident_len;
|
||||
|
||||
let params = match segment.parameters {
|
||||
ast::PathParameters::AngleBracketedParameters(ref data) if data.lifetimes.len() > 0 ||
|
||||
data.types.len() > 0 ||
|
||||
data.bindings.len() > 0 => {
|
||||
ast::PathParameters::AngleBracketedParameters(ref data) if !data.lifetimes.is_empty() ||
|
||||
!data.types.is_empty() ||
|
||||
!data.bindings.is_empty() => {
|
||||
let param_list = data.lifetimes.iter()
|
||||
.map(SegmentParam::LifeTime)
|
||||
.chain(data.types.iter()
|
||||
@ -267,7 +267,7 @@ impl Rewrite for ast::WherePredicate {
|
||||
ref bounded_ty,
|
||||
ref bounds,
|
||||
..}) => {
|
||||
if bound_lifetimes.len() > 0 {
|
||||
if !bound_lifetimes.is_empty() {
|
||||
let lifetime_str = bound_lifetimes.iter().map(|lt| {
|
||||
lt.rewrite(context, width, offset).unwrap()
|
||||
}).collect::<Vec<_>>().join(", ");
|
||||
@ -319,7 +319,7 @@ impl Rewrite for ast::WherePredicate {
|
||||
|
||||
impl Rewrite for ast::LifetimeDef {
|
||||
fn rewrite(&self, _: &RewriteContext, _: usize, _: usize) -> Option<String> {
|
||||
if self.bounds.len() == 0 {
|
||||
if self.bounds.is_empty() {
|
||||
Some(pprust::lifetime_to_string(&self.lifetime))
|
||||
} else {
|
||||
Some(format!("{}: {}",
|
||||
@ -351,7 +351,7 @@ impl Rewrite for ast::TyParam {
|
||||
fn rewrite(&self, context: &RewriteContext, width: usize, offset: usize) -> Option<String> {
|
||||
let mut result = String::with_capacity(128);
|
||||
result.push_str(&self.ident.to_string());
|
||||
if self.bounds.len() > 0 {
|
||||
if !self.bounds.is_empty() {
|
||||
result.push_str(": ");
|
||||
|
||||
let bounds = self.bounds.iter().map(|ty_bound| {
|
||||
@ -372,7 +372,7 @@ impl Rewrite for ast::TyParam {
|
||||
// FIXME: this assumes everything will fit on one line
|
||||
impl Rewrite for ast::PolyTraitRef {
|
||||
fn rewrite(&self, context: &RewriteContext, width: usize, offset: usize) -> Option<String> {
|
||||
if self.bound_lifetimes.len() > 0 {
|
||||
if !self.bound_lifetimes.is_empty() {
|
||||
let lifetime_str = self.bound_lifetimes.iter().map(|lt| {
|
||||
lt.rewrite(context, width, offset).unwrap()
|
||||
}).collect::<Vec<_>>().join(", ");
|
||||
|
@ -267,7 +267,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
|
||||
// Returns true if we should skip the following item.
|
||||
pub fn visit_attrs(&mut self, attrs: &[ast::Attribute]) -> bool {
|
||||
if attrs.len() == 0 {
|
||||
if attrs.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
// with the usual doc comment token.
|
||||
let multi_line = a_str.starts_with("//") && comment.matches('\n').count() > 1;
|
||||
let comment = comment.trim();
|
||||
if comment.len() > 0 {
|
||||
if !comment.is_empty() {
|
||||
result.push_str(&indent);
|
||||
result.push_str(comment);
|
||||
result.push('\n');
|
||||
@ -355,7 +355,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
};
|
||||
// 1 = ";"
|
||||
match vp.rewrite(&context, self.config.max_width - offset - 1, offset) {
|
||||
Some(ref s) if s.len() == 0 => {
|
||||
Some(ref s) if s.is_empty() => {
|
||||
// Format up to last newline
|
||||
let prev_span = codemap::mk_sp(self.last_pos, span.lo);
|
||||
let span_end = match self.snippet(prev_span).rfind('\n') {
|
||||
|
Loading…
Reference in New Issue
Block a user