Skip to content

Commit

Permalink
Cargo update and clippy (rust-lang#2643)
Browse files Browse the repository at this point in the history
  • Loading branch information
topecongiro authored Apr 24, 2018
1 parent fbdd0e8 commit ac8ae00
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 126 deletions.
147 changes: 70 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ env_logger = "0.5"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.5.1"
rustc-ap-syntax = "103.0.0"
rustc-ap-syntax = "110.0.0"

[dev-dependencies]
assert_cli = "0.5"
Expand Down
14 changes: 4 additions & 10 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,11 +1661,7 @@ fn rewrite_struct_lit<'a>(
let nested_shape = shape_for_tactic(tactic, h_shape, v_shape);

let ends_with_comma = span_ends_with_comma(context, span);
let force_no_trailing_comma = if context.inside_macro() && !ends_with_comma {
true
} else {
false
};
let force_no_trailing_comma = context.inside_macro() && !ends_with_comma;

let fmt = struct_lit_formatting(
nested_shape,
Expand Down Expand Up @@ -1846,12 +1842,10 @@ where
} else {
Some(SeparatorTactic::Never)
}
} else if items.len() == 1 {
Some(SeparatorTactic::Always)
} else {
if items.len() == 1 {
Some(SeparatorTactic::Always)
} else {
None
}
None
};
overflow::rewrite_with_parens(
context,
Expand Down
11 changes: 6 additions & 5 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl UseTree {

// Normalise foo::self -> foo.
if let UseSegment::Slf(None) = last {
if self.path.len() > 0 {
if !self.path.is_empty() {
return self;
}
}
Expand Down Expand Up @@ -494,8 +494,8 @@ impl UseTree {
UseSegment::List(list) => {
let prefix = &self.path[..self.path.len() - 1];
let mut result = vec![];
for nested_use_tree in list.into_iter() {
for mut flattend in nested_use_tree.clone().flatten().iter_mut() {
for nested_use_tree in list {
for mut flattend in &mut nested_use_tree.clone().flatten() {
let mut new_path = prefix.to_vec();
new_path.append(&mut flattend.path);
result.push(UseTree {
Expand Down Expand Up @@ -672,15 +672,16 @@ fn rewrite_nested_use_tree(
list_items.push(ListItem::from_str(use_tree.rewrite(context, nested_shape)?));
}
}
let (tactic, remaining_width) = if use_tree_list.iter().any(|use_segment| {
let has_nested_list = use_tree_list.iter().any(|use_segment| {
use_segment
.path
.last()
.map_or(false, |last_segment| match last_segment {
UseSegment::List(..) => true,
_ => false,
})
}) {
});
let (tactic, remaining_width) = if has_nested_list {
(DefinitiveListTactic::Vertical, 0)
} else {
let remaining_width = shape.width.checked_sub(2).unwrap_or(0);
Expand Down
12 changes: 1 addition & 11 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2722,17 +2722,7 @@ impl Rewrite for ast::ForeignItem {
let mut_str = if is_mutable { "mut " } else { "" };
let prefix = format!("{}static {}{}:", vis, mut_str, self.ident);
// 1 = ;
let shape = shape.sub_width(1)?;
ty.rewrite(context, shape).map(|ty_str| {
// 1 = space between prefix and type.
let sep = if prefix.len() + ty_str.len() + 1 <= shape.width {
Cow::from(" ")
} else {
let nested_indent = shape.indent.block_indent(context.config);
nested_indent.to_string_with_newline(context.config)
};
format!("{}{}{};", prefix, sep, ty_str)
})
rewrite_assign_rhs(context, prefix, &**ty, shape.sub_width(1)?).map(|s| s + ";")
}
ast::ForeignItemKind::Ty => {
let vis = format_visibility(&self.vis);
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,24 @@ impl FormatReport {
write!(t, "{} ", error.msg_prefix())?;
t.reset()?;
t.attr(term::Attr::Bold)?;
write!(t, "{}\n", error.kind)?;
writeln!(t, "{}", error.kind)?;

// Second line: file info
write!(t, "{}--> ", &prefix_spaces[1..])?;
t.reset()?;
write!(t, "{}:{}\n", file, error.line)?;
writeln!(t, "{}:{}", file, error.line)?;

// Third to fifth lines: show the line which triggered error, if available.
if !error.line_buffer.is_empty() {
let (space_len, target_len) = error.format_len();
t.attr(term::Attr::Bold)?;
write!(t, "{}|\n{} | ", prefix_spaces, error.line)?;
t.reset()?;
write!(t, "{}\n", error.line_buffer)?;
writeln!(t, "{}", error.line_buffer)?;
t.attr(term::Attr::Bold)?;
write!(t, "{}| ", prefix_spaces)?;
t.fg(term::color::RED)?;
write!(t, "{}\n", target_str(space_len, target_len))?;
writeln!(t, "{}", target_str(space_len, target_len))?;
t.reset()?;
}

Expand All @@ -247,9 +247,9 @@ impl FormatReport {
t.attr(term::Attr::Bold)?;
write!(t, "{}= note: ", prefix_spaces)?;
t.reset()?;
write!(t, "{}\n", error.msg_suffix())?;
writeln!(t, "{}", error.msg_suffix())?;
} else {
write!(t, "\n")?;
writeln!(t)?;
}
t.reset()?;
}
Expand Down Expand Up @@ -307,9 +307,9 @@ impl fmt::Display for FormatReport {
format!("{}note= ", prefix_spaces)
};

write!(
writeln!(
fmt,
"{}\n{}\n{}\n{}{}\n",
"{}\n{}\n{}\n{}{}",
error_info,
file_info,
error_line_buffer,
Expand All @@ -319,9 +319,9 @@ impl fmt::Display for FormatReport {
}
}
if !self.file_error_map.is_empty() {
write!(
writeln!(
fmt,
"warning: rustfmt may have failed to format. See previous {} errors.\n",
"warning: rustfmt may have failed to format. See previous {} errors.",
self.warning_count(),
)?;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ where

debug_assert_eq!(
visitor.line_number,
::utils::count_newlines(&format!("{}", visitor.buffer))
::utils::count_newlines(&visitor.buffer)
);

let filename = path.clone();
Expand Down Expand Up @@ -627,7 +627,7 @@ fn enclose_in_main_block(s: &str, config: &Config) -> String {
}
result.push_str(&line);
result.push('\n');
need_indent = !(kind.is_string() && !line.ends_with('\\'));
need_indent = !kind.is_string() || line.ends_with('\\');
}
result.push('}');
result
Expand Down Expand Up @@ -680,7 +680,7 @@ pub fn format_code_block(code_snippet: &str, config: &Config) -> Option<String>
line
};
result.push_str(trimmed_line);
is_indented = !(kind.is_string() && !line.ends_with('\\'));
is_indented = !kind.is_string() || line.ends_with('\\');
}
Some(result)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ where
let item = item.as_ref();
let inner_item_width = item.inner_as_ref().len();
if !first
&& (item.is_different_group() || !item.post_comment.is_some()
&& (item.is_different_group() || item.post_comment.is_none()
|| inner_item_width + overhead > max_budget)
{
return max_width;
Expand Down
10 changes: 5 additions & 5 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl MacroArgKind {
let another = another
.as_ref()
.and_then(|a| a.rewrite(context, shape, use_multiple_lines))
.unwrap_or("".to_owned());
.unwrap_or_else(|| "".to_owned());
let repeat_tok = pprust::token_to_string(tok);

Some(format!("${}{}{}{}{}", lhs, inner, rhs, another, repeat_tok))
Expand Down Expand Up @@ -685,7 +685,7 @@ impl MacroArgParser {
match iter.next() {
Some(TokenTree::Token(sp, Token::Ident(ref ident, _))) => {
self.result.push(ParsedMacroArg {
kind: MacroArgKind::MetaVariable(ident.clone(), self.buf.clone()),
kind: MacroArgKind::MetaVariable(*ident, self.buf.clone()),
span: mk_sp(self.lo, sp.hi()),
});

Expand Down Expand Up @@ -718,7 +718,7 @@ impl MacroArgParser {
let mut hi = span.hi();

// Parse '*', '+' or '?.
while let Some(ref tok) = iter.next() {
for ref tok in iter {
self.set_last_tok(tok);
if first {
first = false;
Expand Down Expand Up @@ -1080,7 +1080,7 @@ fn indent_macro_snippet(
.min()?;

Some(
String::from(first_line) + "\n"
first_line + "\n"
+ &trimmed_lines
.iter()
.map(
Expand Down Expand Up @@ -1250,7 +1250,7 @@ impl MacroBranch {
if !l.is_empty() && need_indent {
s += &indent_str;
}
(s + l + "\n", !(kind.is_string() && !l.ends_with('\\')))
(s + l + "\n", !kind.is_string() || l.ends_with('\\'))
},
)
.0;
Expand Down
2 changes: 1 addition & 1 deletion src/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn rewrite_reorderable_items(
.into_iter()
.map(|use_tree| ListItem {
item: use_tree.rewrite_top_level(context, nested_shape),
..use_tree.list_item.unwrap_or_else(|| ListItem::empty())
..use_tree.list_item.unwrap_or_else(ListItem::empty)
})
.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/rustfmt_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ where

for mismatch in diff {
let title = get_section_title(mismatch.line_number);
writer.writeln(&format!("{}", title), None);
writer.writeln(&title, None);

for line in mismatch.lines {
match line {
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ fn rewrite_bounded_lifetime(
) -> Option<String> {
let result = lt.rewrite(context, shape)?;

if bounds.len() == 0 {
if bounds.is_empty() {
Some(result)
} else {
let colon = type_bound_colon(context);
Expand Down

0 comments on commit ac8ae00

Please sign in to comment.