Skip to content

Commit c493ee4

Browse files
matthiaskrgrcalebcartwright
authored andcommitted
fix clippy::needless_borrow
1 parent d454e81 commit c493ee4

25 files changed

+91
-91
lines changed

src/attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl Rewrite for [ast::Attribute] {
451451
if next.is_doc_comment() {
452452
let snippet = context.snippet(missing_span);
453453
let (_, mlb) = has_newlines_before_after_comment(snippet);
454-
result.push_str(&mlb);
454+
result.push_str(mlb);
455455
}
456456
}
457457
result.push('\n');
@@ -484,7 +484,7 @@ impl Rewrite for [ast::Attribute] {
484484
if next.is_doc_comment() {
485485
let snippet = context.snippet(missing_span);
486486
let (_, mlb) = has_newlines_before_after_comment(snippet);
487-
result.push_str(&mlb);
487+
result.push_str(mlb);
488488
}
489489
}
490490
result.push('\n');

src/attr/doc_comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ mod tests {
7777
) {
7878
assert_eq!(
7979
expected_comment,
80-
format!("{}", DocCommentFormatter::new(&literal, style))
80+
format!("{}", DocCommentFormatter::new(literal, style))
8181
);
8282
}
8383
}

src/cargo-fmt/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ fn get_targets_root_only(
401401

402402
fn get_targets_recursive(
403403
manifest_path: Option<&Path>,
404-
mut targets: &mut BTreeSet<Target>,
404+
targets: &mut BTreeSet<Target>,
405405
visited: &mut BTreeSet<String>,
406406
) -> Result<(), io::Error> {
407407
let metadata = get_cargo_metadata(manifest_path)?;
408408
for package in &metadata.packages {
409-
add_targets(&package.targets, &mut targets);
409+
add_targets(&package.targets, targets);
410410

411411
// Look for local dependencies using information available since cargo v1.51
412412
// It's theoretically possible someone could use a newer version of rustfmt with
@@ -427,7 +427,7 @@ fn get_targets_recursive(
427427
.any(|p| p.manifest_path.eq(&manifest_path))
428428
{
429429
visited.insert(dependency.name.to_owned());
430-
get_targets_recursive(Some(&manifest_path), &mut targets, visited)?;
430+
get_targets_recursive(Some(&manifest_path), targets, visited)?;
431431
}
432432
}
433433
}

src/chains.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'a> ChainFormatterShared<'a> {
568568
} else {
569569
self.rewrites
570570
.iter()
571-
.map(|rw| utils::unicode_str_width(&rw))
571+
.map(|rw| utils::unicode_str_width(rw))
572572
.sum()
573573
} + last.tries;
574574
let one_line_budget = if self.child_count == 1 {
@@ -673,7 +673,7 @@ impl<'a> ChainFormatterShared<'a> {
673673
ChainItemKind::Comment(_, CommentPosition::Top) => result.push_str(&connector),
674674
_ => result.push_str(&connector),
675675
}
676-
result.push_str(&rewrite);
676+
result.push_str(rewrite);
677677
}
678678

679679
Some(result)

src/comment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ impl<'a> CommentRewrite<'a> {
563563
result.push_str(line);
564564
result.push_str(match iter.peek() {
565565
Some(next_line) if next_line.is_empty() => sep.trim_end(),
566-
Some(..) => &sep,
566+
Some(..) => sep,
567567
None => "",
568568
});
569569
}
@@ -622,7 +622,7 @@ impl<'a> CommentRewrite<'a> {
622622
let is_last = i == count_newlines(orig);
623623

624624
if let Some(ref mut ib) = self.item_block {
625-
if ib.add_line(&line) {
625+
if ib.add_line(line) {
626626
return false;
627627
}
628628
self.is_prev_line_multi_line = false;
@@ -684,8 +684,8 @@ impl<'a> CommentRewrite<'a> {
684684
self.item_block = None;
685685
if let Some(stripped) = line.strip_prefix("```") {
686686
self.code_block_attr = Some(CodeBlockAttribute::new(stripped))
687-
} else if self.fmt.config.wrap_comments() && ItemizedBlock::is_itemized_line(&line) {
688-
let ib = ItemizedBlock::new(&line);
687+
} else if self.fmt.config.wrap_comments() && ItemizedBlock::is_itemized_line(line) {
688+
let ib = ItemizedBlock::new(line);
689689
self.item_block = Some(ib);
690690
return false;
691691
}
@@ -941,7 +941,7 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a s
941941
{
942942
(&line[4..], true)
943943
} else if let CommentStyle::Custom(opener) = *style {
944-
if let Some(ref stripped) = line.strip_prefix(opener) {
944+
if let Some(stripped) = line.strip_prefix(opener) {
945945
(stripped, true)
946946
} else {
947947
(&line[opener.trim_end().len()..], false)
@@ -1570,7 +1570,7 @@ pub(crate) fn recover_comment_removed(
15701570
context.parse_sess.span_to_filename(span),
15711571
vec![FormattingError::from_span(
15721572
span,
1573-
&context.parse_sess,
1573+
context.parse_sess,
15741574
ErrorKind::LostComment,
15751575
)],
15761576
);
@@ -1675,7 +1675,7 @@ impl<'a> Iterator for CommentReducer<'a> {
16751675
fn remove_comment_header(comment: &str) -> &str {
16761676
if comment.starts_with("///") || comment.starts_with("//!") {
16771677
&comment[3..]
1678-
} else if let Some(ref stripped) = comment.strip_prefix("//") {
1678+
} else if let Some(stripped) = comment.strip_prefix("//") {
16791679
stripped
16801680
} else if (comment.starts_with("/**") && !comment.starts_with("/**/"))
16811681
|| comment.starts_with("/*!")

src/emitter/checkstyle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ mod tests {
121121
format!(r#"<file name="{}">"#, bin_file),
122122
format!(
123123
r#"<error line="2" severity="warning" message="Should be `{}`" />"#,
124-
XmlEscaped(&r#" println!("Hello, world!");"#),
124+
XmlEscaped(r#" println!("Hello, world!");"#),
125125
),
126126
String::from("</file>"),
127127
];
128128
let exp_lib_xml = vec![
129129
format!(r#"<file name="{}">"#, lib_file),
130130
format!(
131131
r#"<error line="2" severity="warning" message="Should be `{}`" />"#,
132-
XmlEscaped(&r#" println!("Greetings!");"#),
132+
XmlEscaped(r#" println!("Greetings!");"#),
133133
),
134134
String::from("</file>"),
135135
];

src/emitter/diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Emitter for DiffEmitter {
2323
}: FormattedFile<'_>,
2424
) -> Result<EmitterResult, io::Error> {
2525
const CONTEXT_SIZE: usize = 3;
26-
let mismatch = make_diff(&original_text, formatted_text, CONTEXT_SIZE);
26+
let mismatch = make_diff(original_text, formatted_text, CONTEXT_SIZE);
2727
let has_diff = !mismatch.is_empty();
2828

2929
if has_diff {

src/expr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub(crate) fn format_expr(
257257
}
258258
_ => false,
259259
},
260-
ast::ExprKind::Unary(_, ref expr) => needs_space_before_range(context, &expr),
260+
ast::ExprKind::Unary(_, ref expr) => needs_space_before_range(context, expr),
261261
_ => false,
262262
}
263263
}
@@ -423,7 +423,7 @@ fn rewrite_empty_block(
423423
prefix: &str,
424424
shape: Shape,
425425
) -> Option<String> {
426-
if block_has_statements(&block) {
426+
if block_has_statements(block) {
427427
return None;
428428
}
429429

@@ -1148,7 +1148,7 @@ pub(crate) fn is_empty_block(
11481148
block: &ast::Block,
11491149
attrs: Option<&[ast::Attribute]>,
11501150
) -> bool {
1151-
!block_has_statements(&block)
1151+
!block_has_statements(block)
11521152
&& !block_contains_comment(context, block)
11531153
&& attrs.map_or(true, |a| inner_attributes(a).is_empty())
11541154
}
@@ -1621,7 +1621,7 @@ fn rewrite_struct_lit<'a>(
16211621
};
16221622

16231623
let fields_str =
1624-
wrap_struct_field(context, &attrs, &fields_str, shape, v_shape, one_line_width)?;
1624+
wrap_struct_field(context, attrs, &fields_str, shape, v_shape, one_line_width)?;
16251625
Some(format!("{} {{{}}}", path_str, fields_str))
16261626

16271627
// FIXME if context.config.indent_style() == Visual, but we run out
@@ -1888,7 +1888,7 @@ pub(crate) fn rewrite_assign_rhs_expr<R: Rewrite>(
18881888
shape: Shape,
18891889
rhs_tactics: RhsTactics,
18901890
) -> Option<String> {
1891-
let last_line_width = last_line_width(&lhs).saturating_sub(if lhs.contains('\n') {
1891+
let last_line_width = last_line_width(lhs).saturating_sub(if lhs.contains('\n') {
18921892
shape.indent.width()
18931893
} else {
18941894
0
@@ -1947,7 +1947,7 @@ pub(crate) fn rewrite_assign_rhs_with_comments<S: Into<String>, R: Rewrite>(
19471947

19481948
if contains_comment {
19491949
let rhs = rhs.trim_start();
1950-
combine_strs_with_missing_comments(context, &lhs, &rhs, between_span, shape, allow_extend)
1950+
combine_strs_with_missing_comments(context, &lhs, rhs, between_span, shape, allow_extend)
19511951
} else {
19521952
Some(lhs + &rhs)
19531953
}

src/formatting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
155155
let snippet_provider = self.parse_session.snippet_provider(module.span);
156156
let mut visitor = FmtVisitor::from_parse_sess(
157157
&self.parse_session,
158-
&self.config,
158+
self.config,
159159
&snippet_provider,
160160
self.report.clone(),
161161
);
@@ -180,7 +180,7 @@ impl<'a, T: FormatHandler + 'a> FormatContext<'a, T> {
180180
&mut visitor.buffer,
181181
&path,
182182
&visitor.skipped_range.borrow(),
183-
&self.config,
183+
self.config,
184184
&self.report,
185185
);
186186

src/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl UseTree {
275275
shape: Shape,
276276
) -> Option<String> {
277277
let vis = self.visibility.as_ref().map_or(Cow::from(""), |vis| {
278-
crate::utils::format_visibility(context, &vis)
278+
crate::utils::format_visibility(context, vis)
279279
});
280280
let use_str = self
281281
.rewrite(context, shape.offset_left(vis.len())?)
@@ -929,7 +929,7 @@ impl Rewrite for UseTree {
929929
fn rewrite(&self, context: &RewriteContext<'_>, mut shape: Shape) -> Option<String> {
930930
let mut result = String::with_capacity(256);
931931
let mut iter = self.path.iter().peekable();
932-
while let Some(ref segment) = iter.next() {
932+
while let Some(segment) = iter.next() {
933933
let segment_str = segment.rewrite(context, shape)?;
934934
result.push_str(&segment_str);
935935
if iter.peek().is_some() {

0 commit comments

Comments
 (0)