Skip to content

Clippy 2/2 #2992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn is_derive(attr: &ast::Attribute) -> bool {
}

/// Returns the arguments of `#[derive(...)]`.
fn get_derive_spans<'a>(attr: &ast::Attribute) -> Option<Vec<Span>> {
fn get_derive_spans(attr: &ast::Attribute) -> Option<Vec<Span>> {
attr.meta_item_list().map(|meta_item_list| {
meta_item_list
.iter()
Expand Down
14 changes: 7 additions & 7 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
match determine_operation(&matches)? {
Operation::Help(HelpOp::None) => {
print_usage_to_stdout(opts, "");
return Ok(0);
Ok(0)
}
Operation::Help(HelpOp::Config) => {
Config::print_docs(&mut stdout(), options.unstable_features);
return Ok(0);
Ok(0)
}
Operation::Help(HelpOp::FileLines) => {
print_help_file_lines();
return Ok(0);
Ok(0)
}
Operation::Version => {
print_version();
return Ok(0);
Ok(0)
}
Operation::ConfigOutputDefault { path } => {
let toml = Config::default().all_options().to_toml().map_err(err_msg)?;
Expand All @@ -194,13 +194,13 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
} else {
io::stdout().write_all(toml.as_bytes())?;
}
return Ok(0);
Ok(0)
}
Operation::Stdin { input } => format_string(input, options),
Operation::Format {
files,
minimal_config_path,
} => format(files, minimal_config_path, options),
} => format(files, minimal_config_path, &options),
}
}

Expand Down Expand Up @@ -236,7 +236,7 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32, failure:
fn format(
files: Vec<PathBuf>,
minimal_config_path: Option<String>,
options: GetOptsOptions,
options: &GetOptsOptions,
) -> Result<i32, failure::Error> {
options.verify_file_lines(&files);
let (config, config_path) = load_config(None, Some(options.clone()))?;
Expand Down
6 changes: 3 additions & 3 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn custom_opener(s: &str) -> &str {
s.lines().next().map_or("", |first_line| {
first_line
.find(' ')
.map_or(first_line, |space_index| &first_line[0..space_index + 1])
.map_or(first_line, |space_index| &first_line[0..=space_index])
})
}

Expand Down Expand Up @@ -1151,7 +1151,7 @@ pub fn recover_comment_removed(
context.report.append(
context.source_map.span_to_filename(span).into(),
vec![FormattingError::from_span(
&span,
span,
&context.source_map,
ErrorKind::LostComment,
)],
Expand Down Expand Up @@ -1428,7 +1428,7 @@ mod test {

#[test]
fn test_remove_trailing_white_spaces() {
let s = format!(" r#\"\n test\n \"#");
let s = " r#\"\n test\n \"#";
assert_eq!(remove_trailing_white_spaces(&s), s);
}

Expand Down
4 changes: 2 additions & 2 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ configuration_option_enum! { Color:

impl Color {
/// Whether we should use a coloured terminal.
pub fn use_colored_tty(&self) -> bool {
pub fn use_colored_tty(self) -> bool {
match self {
Color::Always => true,
Color::Never => false,
Expand Down Expand Up @@ -417,7 +417,7 @@ configuration_option_enum!{ Edition:
}

impl Edition {
pub(crate) fn to_libsyntax_pos_edition(&self) -> syntax_pos::edition::Edition {
pub(crate) fn to_libsyntax_pos_edition(self) -> syntax_pos::edition::Edition {
match self {
Edition::Edition2015 => syntax_pos::edition::Edition::Edition2015,
Edition::Edition2018 => syntax_pos::edition::Edition::Edition2018,
Expand Down
14 changes: 7 additions & 7 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn format_expr(
)
})
}
ast::ExprKind::Unary(ref op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
ast::ExprKind::Unary(op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
ast::ExprKind::Struct(ref path, ref fields, ref base) => rewrite_struct_lit(
context,
path,
Expand Down Expand Up @@ -1519,7 +1519,7 @@ fn rewrite_index(
}
}

fn struct_lit_can_be_aligned(fields: &[ast::Field], base: &Option<&ast::Expr>) -> bool {
fn struct_lit_can_be_aligned(fields: &[ast::Field], base: Option<&ast::Expr>) -> bool {
if base.is_some() {
return false;
}
Expand Down Expand Up @@ -1555,7 +1555,7 @@ fn rewrite_struct_lit<'a>(

let one_line_width = h_shape.map_or(0, |shape| shape.width);
let body_lo = context.snippet_provider.span_after(span, "{");
let fields_str = if struct_lit_can_be_aligned(fields, &base)
let fields_str = if struct_lit_can_be_aligned(fields, base)
&& context.config.struct_field_align_threshold() > 0
{
rewrite_with_alignment(
Expand Down Expand Up @@ -1676,7 +1676,7 @@ pub fn rewrite_field(
};
let name = context.snippet(field.ident.span);
if field.is_shorthand {
Some(attrs_str + &name)
Some(attrs_str + name)
} else {
let mut separator = String::from(struct_lit_field_separator(context.config));
for _ in 0..prefix_max_width.saturating_sub(name.len()) {
Expand All @@ -1688,7 +1688,7 @@ pub fn rewrite_field(

match expr {
Some(ref e) if e.as_str() == name && context.config.use_field_init_shorthand() => {
Some(attrs_str + &name)
Some(attrs_str + name)
}
Some(e) => Some(format!("{}{}{}{}", attrs_str, name, separator, e)),
None => {
Expand Down Expand Up @@ -1827,12 +1827,12 @@ pub fn rewrite_unary_suffix<R: Rewrite>(

fn rewrite_unary_op(
context: &RewriteContext,
op: &ast::UnOp,
op: ast::UnOp,
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
// For some reason, an UnOp is not spanned like BinOp!
let operator_str = match *op {
let operator_str = match op {
ast::UnOp::Deref => "*",
ast::UnOp::Not => "!",
ast::UnOp::Neg => "-",
Expand Down
2 changes: 1 addition & 1 deletion src/format-diff/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ where

#[test]
fn scan_simple_git_diff() {
const DIFF: &'static str = include_str!("test/bindgen.diff");
const DIFF: &str = include_str!("test/bindgen.diff");
let (files, ranges) = scan_diff(DIFF.as_bytes(), 1, r".*\.rs").expect("scan_diff failed?");

assert!(
Expand Down
10 changes: 5 additions & 5 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> {
fn handle_formatted_file(
&mut self,
path: FileName,
mut result: String,
result: String,
report: &mut FormatReport,
) -> Result<(), ErrorKind> {
if let Some(ref mut out) = self.out {
match source_file::write_file(&mut result, &path, out, &self.config) {
match source_file::write_file(&result, &path, out, &self.config) {
Ok(b) if b => report.add_diff(),
Err(e) => {
// Create a new error with path_str to help users see which files failed
Expand All @@ -224,7 +224,7 @@ pub(crate) struct FormattingError {

impl FormattingError {
pub(crate) fn from_span(
span: &Span,
span: Span,
source_map: &SourceMap,
kind: ErrorKind,
) -> FormattingError {
Expand All @@ -234,13 +234,13 @@ impl FormattingError {
kind,
is_string: false,
line_buffer: source_map
.span_to_lines(*span)
.span_to_lines(span)
.ok()
.and_then(|fl| {
fl.file
.get_line(fl.lines[0].line_index)
.map(|l| l.into_owned())
}).unwrap_or_else(|| String::new()),
}).unwrap_or_else(String::new),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn merge_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
for tree in trees.iter_mut() {
if tree.share_prefix(&use_tree) {
tree.merge(use_tree);
tree.merge(&use_tree);
return;
}
}
Expand Down Expand Up @@ -536,7 +536,7 @@ impl UseTree {
}
}

fn merge(&mut self, other: UseTree) {
fn merge(&mut self, other: &UseTree) {
let mut new_path = vec![];
for (a, b) in self
.path
Expand Down
2 changes: 1 addition & 1 deletion src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ where
formatted_comment = rewrite_post_comment(&mut item_max_width)?;
comment_alignment = post_comment_alignment(item_max_width, inner_item.len());
}
for _ in 0..(comment_alignment + 1) {
for _ in 0..=comment_alignment {
result.push(' ');
}
// An additional space for the missing trailing separator.
Expand Down
18 changes: 9 additions & 9 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,12 @@ enum MacroArgKind {

fn delim_token_to_str(
context: &RewriteContext,
delim_token: &DelimToken,
delim_token: DelimToken,
shape: Shape,
use_multiple_lines: bool,
inner_is_empty: bool,
) -> (String, String) {
let (lhs, rhs) = match *delim_token {
let (lhs, rhs) = match delim_token {
DelimToken::Paren => ("(", ")"),
DelimToken::Bracket => ("[", "]"),
DelimToken::Brace => {
Expand Down Expand Up @@ -612,7 +612,7 @@ impl MacroArgKind {
MacroArgKind::MetaVariable(ty, ref name) => {
Some(format!("${}:{}", name, ty.name.as_str()))
}
MacroArgKind::Repeat(ref delim_tok, ref args, ref another, ref tok) => {
MacroArgKind::Repeat(delim_tok, ref args, ref another, ref tok) => {
let (lhs, inner, rhs) = rewrite_delimited_inner(delim_tok, args)?;
let another = another
.as_ref()
Expand All @@ -622,7 +622,7 @@ impl MacroArgKind {

Some(format!("${}{}{}{}{}", lhs, inner, rhs, another, repeat_tok))
}
MacroArgKind::Delimited(ref delim_tok, ref args) => {
MacroArgKind::Delimited(delim_tok, ref args) => {
rewrite_delimited_inner(delim_tok, args)
.map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs))
}
Expand Down Expand Up @@ -755,8 +755,8 @@ impl MacroArgParser {
let mut hi = span.hi();

// Parse '*', '+' or '?.
for ref tok in iter {
self.set_last_tok(tok);
for tok in iter {
self.set_last_tok(&tok);
if first {
first = false;
lo = tok.span().lo();
Expand Down Expand Up @@ -977,7 +977,7 @@ enum SpaceState {
fn force_space_before(tok: &Token) -> bool {
debug!("tok: force_space_before {:?}", tok);

match *tok {
match tok {
Token::Eq
| Token::Lt
| Token::Le
Expand All @@ -1002,7 +1002,7 @@ fn force_space_before(tok: &Token) -> bool {
}

fn ident_like(tok: &Token) -> bool {
match *tok {
match tok {
Token::Ident(..) | Token::Literal(..) | Token::Lifetime(_) => true,
_ => false,
}
Expand All @@ -1011,7 +1011,7 @@ fn ident_like(tok: &Token) -> bool {
fn next_space(tok: &Token) -> SpaceState {
debug!("next_space: {:?}", tok);

match *tok {
match tok {
Token::Not
| Token::BinOp(BinOpToken::And)
| Token::Tilde
Expand Down
2 changes: 1 addition & 1 deletion src/missed_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'a> FmtVisitor<'a> {
self.push_str("\n");
status.last_wspace = None;
} else {
self.push_str(&snippet[status.line_start..i + 1]);
self.push_str(&snippet[status.line_start..=i]);
}

status.cur_line += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
(true, DefinitiveListTactic::Horizontal, placeholder @ Some(..)) => {
list_items[self.items.len() - 1].item = placeholder;
}
_ if self.items.len() >= 1 => {
_ if !self.items.is_empty() => {
list_items[self.items.len() - 1].item = self
.items
.last()
Expand Down
12 changes: 6 additions & 6 deletions src/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,21 @@ impl ReorderableItemKind {
}
}

fn is_same_item_kind(&self, item: &ast::Item) -> bool {
ReorderableItemKind::from(item) == *self
fn is_same_item_kind(self, item: &ast::Item) -> bool {
ReorderableItemKind::from(item) == self
}

fn is_reorderable(&self, config: &Config) -> bool {
match *self {
fn is_reorderable(self, config: &Config) -> bool {
match self {
ReorderableItemKind::ExternCrate => config.reorder_imports(),
ReorderableItemKind::Mod => config.reorder_modules(),
ReorderableItemKind::Use => config.reorder_imports(),
ReorderableItemKind::Other => false,
}
}

fn in_group(&self) -> bool {
match *self {
fn in_group(self) -> bool {
match self {
ReorderableItemKind::ExternCrate
| ReorderableItemKind::Mod
| ReorderableItemKind::Use => true,
Expand Down
2 changes: 1 addition & 1 deletion src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Indent {
};
let num_chars = num_tabs + num_spaces;
if num_tabs == 0 && num_chars + offset <= INDENT_BUFFER_LEN {
Cow::from(&INDENT_BUFFER[offset..num_chars + 1])
Cow::from(&INDENT_BUFFER[offset..=num_chars])
} else {
let mut indent = String::with_capacity(num_chars + if offset == 0 { 1 } else { 0 });
if offset == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn verify_config_test_names() {
// `print_diff` selects the approach not used.
fn write_message(msg: &str) {
let mut writer = OutputWriter::new(Color::Auto);
writer.writeln(&format!("{}", msg), None);
writer.writeln(msg, None);
}

// Integration tests. The files in the tests/source are formatted and compared
Expand Down Expand Up @@ -949,7 +949,7 @@ fn rustfmt() -> PathBuf {
me.is_file() || me.with_extension("exe").is_file(),
"no rustfmt bin, try running `cargo build` before testing"
);
return me;
me
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/vertical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
} else {
("", fields.len() - 1)
};
let init = &fields[0..group_index + 1];
let init = &fields[0..=group_index];
let rest = &fields[group_index + 1..];
let init_last_pos = if rest.is_empty() {
span.hi()
Expand Down
Loading