Skip to content

Commit 2291be7

Browse files
authored
Merge pull request #2992 from max-sixty/clippy2
Clippy 2/2
2 parents a67208f + 968affc commit 2291be7

17 files changed

+52
-52
lines changed

src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn is_derive(attr: &ast::Attribute) -> bool {
4848
}
4949

5050
/// Returns the arguments of `#[derive(...)]`.
51-
fn get_derive_spans<'a>(attr: &ast::Attribute) -> Option<Vec<Span>> {
51+
fn get_derive_spans(attr: &ast::Attribute) -> Option<Vec<Span>> {
5252
attr.meta_item_list().map(|meta_item_list| {
5353
meta_item_list
5454
.iter()

src/bin/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,19 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
172172
match determine_operation(&matches)? {
173173
Operation::Help(HelpOp::None) => {
174174
print_usage_to_stdout(opts, "");
175-
return Ok(0);
175+
Ok(0)
176176
}
177177
Operation::Help(HelpOp::Config) => {
178178
Config::print_docs(&mut stdout(), options.unstable_features);
179-
return Ok(0);
179+
Ok(0)
180180
}
181181
Operation::Help(HelpOp::FileLines) => {
182182
print_help_file_lines();
183-
return Ok(0);
183+
Ok(0)
184184
}
185185
Operation::Version => {
186186
print_version();
187-
return Ok(0);
187+
Ok(0)
188188
}
189189
Operation::ConfigOutputDefault { path } => {
190190
let toml = Config::default().all_options().to_toml().map_err(err_msg)?;
@@ -194,13 +194,13 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
194194
} else {
195195
io::stdout().write_all(toml.as_bytes())?;
196196
}
197-
return Ok(0);
197+
Ok(0)
198198
}
199199
Operation::Stdin { input } => format_string(input, options),
200200
Operation::Format {
201201
files,
202202
minimal_config_path,
203-
} => format(files, minimal_config_path, options),
203+
} => format(files, minimal_config_path, &options),
204204
}
205205
}
206206

@@ -236,7 +236,7 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32, failure:
236236
fn format(
237237
files: Vec<PathBuf>,
238238
minimal_config_path: Option<String>,
239-
options: GetOptsOptions,
239+
options: &GetOptsOptions,
240240
) -> Result<i32, failure::Error> {
241241
options.verify_file_lines(&files);
242242
let (config, config_path) = load_config(None, Some(options.clone()))?;

src/comment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn custom_opener(s: &str) -> &str {
4747
s.lines().next().map_or("", |first_line| {
4848
first_line
4949
.find(' ')
50-
.map_or(first_line, |space_index| &first_line[0..space_index + 1])
50+
.map_or(first_line, |space_index| &first_line[0..=space_index])
5151
})
5252
}
5353

@@ -1151,7 +1151,7 @@ pub fn recover_comment_removed(
11511151
context.report.append(
11521152
context.source_map.span_to_filename(span).into(),
11531153
vec![FormattingError::from_span(
1154-
&span,
1154+
span,
11551155
&context.source_map,
11561156
ErrorKind::LostComment,
11571157
)],
@@ -1428,7 +1428,7 @@ mod test {
14281428

14291429
#[test]
14301430
fn test_remove_trailing_white_spaces() {
1431-
let s = format!(" r#\"\n test\n \"#");
1431+
let s = " r#\"\n test\n \"#";
14321432
assert_eq!(remove_trailing_white_spaces(&s), s);
14331433
}
14341434

src/config/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ configuration_option_enum! { Color:
279279

280280
impl Color {
281281
/// Whether we should use a coloured terminal.
282-
pub fn use_colored_tty(&self) -> bool {
282+
pub fn use_colored_tty(self) -> bool {
283283
match self {
284284
Color::Always => true,
285285
Color::Never => false,
@@ -432,7 +432,7 @@ configuration_option_enum!{ Edition:
432432
}
433433

434434
impl Edition {
435-
pub(crate) fn to_libsyntax_pos_edition(&self) -> syntax_pos::edition::Edition {
435+
pub(crate) fn to_libsyntax_pos_edition(self) -> syntax_pos::edition::Edition {
436436
match self {
437437
Edition::Edition2015 => syntax_pos::edition::Edition::Edition2015,
438438
Edition::Edition2018 => syntax_pos::edition::Edition::Edition2018,

src/expr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn format_expr(
100100
)
101101
})
102102
}
103-
ast::ExprKind::Unary(ref op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
103+
ast::ExprKind::Unary(op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
104104
ast::ExprKind::Struct(ref path, ref fields, ref base) => rewrite_struct_lit(
105105
context,
106106
path,
@@ -1519,7 +1519,7 @@ fn rewrite_index(
15191519
}
15201520
}
15211521

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

15561556
let one_line_width = h_shape.map_or(0, |shape| shape.width);
15571557
let body_lo = context.snippet_provider.span_after(span, "{");
1558-
let fields_str = if struct_lit_can_be_aligned(fields, &base)
1558+
let fields_str = if struct_lit_can_be_aligned(fields, base)
15591559
&& context.config.struct_field_align_threshold() > 0
15601560
{
15611561
rewrite_with_alignment(
@@ -1676,7 +1676,7 @@ pub fn rewrite_field(
16761676
};
16771677
let name = context.snippet(field.ident.span);
16781678
if field.is_shorthand {
1679-
Some(attrs_str + &name)
1679+
Some(attrs_str + name)
16801680
} else {
16811681
let mut separator = String::from(struct_lit_field_separator(context.config));
16821682
for _ in 0..prefix_max_width.saturating_sub(name.len()) {
@@ -1688,7 +1688,7 @@ pub fn rewrite_field(
16881688

16891689
match expr {
16901690
Some(ref e) if e.as_str() == name && context.config.use_field_init_shorthand() => {
1691-
Some(attrs_str + &name)
1691+
Some(attrs_str + name)
16921692
}
16931693
Some(e) => Some(format!("{}{}{}{}", attrs_str, name, separator, e)),
16941694
None => {
@@ -1827,12 +1827,12 @@ pub fn rewrite_unary_suffix<R: Rewrite>(
18271827

18281828
fn rewrite_unary_op(
18291829
context: &RewriteContext,
1830-
op: &ast::UnOp,
1830+
op: ast::UnOp,
18311831
expr: &ast::Expr,
18321832
shape: Shape,
18331833
) -> Option<String> {
18341834
// For some reason, an UnOp is not spanned like BinOp!
1835-
let operator_str = match *op {
1835+
let operator_str = match op {
18361836
ast::UnOp::Deref => "*",
18371837
ast::UnOp::Not => "!",
18381838
ast::UnOp::Neg => "-",

src/format-diff/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ where
214214

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

220220
assert!(

src/formatting.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> {
194194
fn handle_formatted_file(
195195
&mut self,
196196
path: FileName,
197-
mut result: String,
197+
result: String,
198198
report: &mut FormatReport,
199199
) -> Result<(), ErrorKind> {
200200
if let Some(ref mut out) = self.out {
201-
match source_file::write_file(&mut result, &path, out, &self.config) {
201+
match source_file::write_file(&result, &path, out, &self.config) {
202202
Ok(b) if b => report.add_diff(),
203203
Err(e) => {
204204
// Create a new error with path_str to help users see which files failed
@@ -224,7 +224,7 @@ pub(crate) struct FormattingError {
224224

225225
impl FormattingError {
226226
pub(crate) fn from_span(
227-
span: &Span,
227+
span: Span,
228228
source_map: &SourceMap,
229229
kind: ErrorKind,
230230
) -> FormattingError {
@@ -234,13 +234,13 @@ impl FormattingError {
234234
kind,
235235
is_string: false,
236236
line_buffer: source_map
237-
.span_to_lines(*span)
237+
.span_to_lines(span)
238238
.ok()
239239
.and_then(|fl| {
240240
fl.file
241241
.get_line(fl.lines[0].line_index)
242242
.map(|l| l.into_owned())
243-
}).unwrap_or_else(|| String::new()),
243+
}).unwrap_or_else(String::new),
244244
}
245245
}
246246

src/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub fn merge_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
179179
fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
180180
for tree in trees.iter_mut() {
181181
if tree.share_prefix(&use_tree) {
182-
tree.merge(use_tree);
182+
tree.merge(&use_tree);
183183
return;
184184
}
185185
}
@@ -536,7 +536,7 @@ impl UseTree {
536536
}
537537
}
538538

539-
fn merge(&mut self, other: UseTree) {
539+
fn merge(&mut self, other: &UseTree) {
540540
let mut new_path = vec![];
541541
for (a, b) in self
542542
.path

src/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ where
475475
formatted_comment = rewrite_post_comment(&mut item_max_width)?;
476476
comment_alignment = post_comment_alignment(item_max_width, inner_item.len());
477477
}
478-
for _ in 0..(comment_alignment + 1) {
478+
for _ in 0..=comment_alignment {
479479
result.push(' ');
480480
}
481481
// An additional space for the missing trailing separator.

src/macros.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,12 @@ enum MacroArgKind {
524524

525525
fn delim_token_to_str(
526526
context: &RewriteContext,
527-
delim_token: &DelimToken,
527+
delim_token: DelimToken,
528528
shape: Shape,
529529
use_multiple_lines: bool,
530530
inner_is_empty: bool,
531531
) -> (String, String) {
532-
let (lhs, rhs) = match *delim_token {
532+
let (lhs, rhs) = match delim_token {
533533
DelimToken::Paren => ("(", ")"),
534534
DelimToken::Bracket => ("[", "]"),
535535
DelimToken::Brace => {
@@ -612,7 +612,7 @@ impl MacroArgKind {
612612
MacroArgKind::MetaVariable(ty, ref name) => {
613613
Some(format!("${}:{}", name, ty.name.as_str()))
614614
}
615-
MacroArgKind::Repeat(ref delim_tok, ref args, ref another, ref tok) => {
615+
MacroArgKind::Repeat(delim_tok, ref args, ref another, ref tok) => {
616616
let (lhs, inner, rhs) = rewrite_delimited_inner(delim_tok, args)?;
617617
let another = another
618618
.as_ref()
@@ -622,7 +622,7 @@ impl MacroArgKind {
622622

623623
Some(format!("${}{}{}{}{}", lhs, inner, rhs, another, repeat_tok))
624624
}
625-
MacroArgKind::Delimited(ref delim_tok, ref args) => {
625+
MacroArgKind::Delimited(delim_tok, ref args) => {
626626
rewrite_delimited_inner(delim_tok, args)
627627
.map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs))
628628
}
@@ -755,8 +755,8 @@ impl MacroArgParser {
755755
let mut hi = span.hi();
756756

757757
// Parse '*', '+' or '?.
758-
for ref tok in iter {
759-
self.set_last_tok(tok);
758+
for tok in iter {
759+
self.set_last_tok(&tok);
760760
if first {
761761
first = false;
762762
lo = tok.span().lo();
@@ -977,7 +977,7 @@ enum SpaceState {
977977
fn force_space_before(tok: &Token) -> bool {
978978
debug!("tok: force_space_before {:?}", tok);
979979

980-
match *tok {
980+
match tok {
981981
Token::Eq
982982
| Token::Lt
983983
| Token::Le
@@ -1002,7 +1002,7 @@ fn force_space_before(tok: &Token) -> bool {
10021002
}
10031003

10041004
fn ident_like(tok: &Token) -> bool {
1005-
match *tok {
1005+
match tok {
10061006
Token::Ident(..) | Token::Literal(..) | Token::Lifetime(_) => true,
10071007
_ => false,
10081008
}
@@ -1011,7 +1011,7 @@ fn ident_like(tok: &Token) -> bool {
10111011
fn next_space(tok: &Token) -> SpaceState {
10121012
debug!("next_space: {:?}", tok);
10131013

1014-
match *tok {
1014+
match tok {
10151015
Token::Not
10161016
| Token::BinOp(BinOpToken::And)
10171017
| Token::Tilde

src/missed_spans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a> FmtVisitor<'a> {
315315
self.push_str("\n");
316316
status.last_wspace = None;
317317
} else {
318-
self.push_str(&snippet[status.line_start..i + 1]);
318+
self.push_str(&snippet[status.line_start..=i]);
319319
}
320320

321321
status.cur_line += 1;

src/overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
291291
(true, DefinitiveListTactic::Horizontal, placeholder @ Some(..)) => {
292292
list_items[self.items.len() - 1].item = placeholder;
293293
}
294-
_ if self.items.len() >= 1 => {
294+
_ if !self.items.is_empty() => {
295295
list_items[self.items.len() - 1].item = self
296296
.items
297297
.last()

src/reorder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,21 @@ impl ReorderableItemKind {
193193
}
194194
}
195195

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

200-
fn is_reorderable(&self, config: &Config) -> bool {
201-
match *self {
200+
fn is_reorderable(self, config: &Config) -> bool {
201+
match self {
202202
ReorderableItemKind::ExternCrate => config.reorder_imports(),
203203
ReorderableItemKind::Mod => config.reorder_modules(),
204204
ReorderableItemKind::Use => config.reorder_imports(),
205205
ReorderableItemKind::Other => false,
206206
}
207207
}
208208

209-
fn in_group(&self) -> bool {
210-
match *self {
209+
fn in_group(self) -> bool {
210+
match self {
211211
ReorderableItemKind::ExternCrate
212212
| ReorderableItemKind::Mod
213213
| ReorderableItemKind::Use => true,

src/shape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Indent {
9191
};
9292
let num_chars = num_tabs + num_spaces;
9393
if num_tabs == 0 && num_chars + offset <= INDENT_BUFFER_LEN {
94-
Cow::from(&INDENT_BUFFER[offset..num_chars + 1])
94+
Cow::from(&INDENT_BUFFER[offset..=num_chars])
9595
} else {
9696
let mut indent = String::with_capacity(num_chars + if offset == 0 { 1 } else { 0 });
9797
if offset == 0 {

src/test/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn verify_config_test_names() {
102102
// `print_diff` selects the approach not used.
103103
fn write_message(msg: &str) {
104104
let mut writer = OutputWriter::new(Color::Auto);
105-
writer.writeln(&format!("{}", msg), None);
105+
writer.writeln(msg, None);
106106
}
107107

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

955955
#[test]

src/vertical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
126126
} else {
127127
("", fields.len() - 1)
128128
};
129-
let init = &fields[0..group_index + 1];
129+
let init = &fields[0..=group_index];
130130
let rest = &fields[group_index + 1..];
131131
let init_last_pos = if rest.is_empty() {
132132
span.hi()

0 commit comments

Comments
 (0)