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() {

src/items.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'a> FnSig<'a> {
226226
fn to_str(&self, context: &RewriteContext<'_>) -> String {
227227
let mut result = String::with_capacity(128);
228228
// Vis defaultness constness unsafety abi.
229-
result.push_str(&*format_visibility(context, &self.visibility));
229+
result.push_str(&*format_visibility(context, self.visibility));
230230
result.push_str(format_defaultness(self.defaultness));
231231
result.push_str(format_constness(self.constness));
232232
result.push_str(format_async(&self.is_async));
@@ -1220,7 +1220,7 @@ impl<'a> Rewrite for TraitAliasBounds<'a> {
12201220
} else if fits_single_line {
12211221
Cow::from(" ")
12221222
} else {
1223-
shape.indent.to_string_with_newline(&context.config)
1223+
shape.indent.to_string_with_newline(context.config)
12241224
};
12251225

12261226
Some(format!("{}{}{}", generic_bounds_str, space, where_str))
@@ -1238,7 +1238,7 @@ pub(crate) fn format_trait_alias(
12381238
let alias = rewrite_ident(context, ident);
12391239
// 6 = "trait ", 2 = " ="
12401240
let g_shape = shape.offset_left(6)?.sub_width(2)?;
1241-
let generics_str = rewrite_generics(context, &alias, generics, g_shape)?;
1241+
let generics_str = rewrite_generics(context, alias, generics, g_shape)?;
12421242
let vis_str = format_visibility(context, vis);
12431243
let lhs = format!("{}trait {} =", vis_str, generics_str);
12441244
// 1 = ";"
@@ -1386,7 +1386,7 @@ fn format_empty_struct_or_tuple(
13861386
closer: &str,
13871387
) {
13881388
// 3 = " {}" or "();"
1389-
let used_width = last_line_used_width(&result, offset.width()) + 3;
1389+
let used_width = last_line_used_width(result, offset.width()) + 3;
13901390
if used_width > context.config.max_width() {
13911391
result.push_str(&offset.to_string_with_newline(context.config))
13921392
}
@@ -2066,7 +2066,7 @@ fn rewrite_explicit_self(
20662066
)?;
20672067
Some(combine_strs_with_missing_comments(
20682068
context,
2069-
&param_attrs,
2069+
param_attrs,
20702070
&format!("&{} {}self", lifetime_str, mut_str),
20712071
span,
20722072
shape,
@@ -2075,7 +2075,7 @@ fn rewrite_explicit_self(
20752075
}
20762076
None => Some(combine_strs_with_missing_comments(
20772077
context,
2078-
&param_attrs,
2078+
param_attrs,
20792079
&format!("&{}self", mut_str),
20802080
span,
20812081
shape,
@@ -2091,7 +2091,7 @@ fn rewrite_explicit_self(
20912091

20922092
Some(combine_strs_with_missing_comments(
20932093
context,
2094-
&param_attrs,
2094+
param_attrs,
20952095
&format!("{}self: {}", format_mutability(mutability), type_str),
20962096
span,
20972097
shape,
@@ -2100,7 +2100,7 @@ fn rewrite_explicit_self(
21002100
}
21012101
ast::SelfKind::Value(mutability) => Some(combine_strs_with_missing_comments(
21022102
context,
2103-
&param_attrs,
2103+
param_attrs,
21042104
&format!("{}self", format_mutability(mutability)),
21052105
span,
21062106
shape,
@@ -2226,7 +2226,7 @@ fn rewrite_fn_base(
22262226
}
22272227

22282228
// Skip `pub(crate)`.
2229-
let lo_after_visibility = get_bytepos_after_visibility(&fn_sig.visibility, span);
2229+
let lo_after_visibility = get_bytepos_after_visibility(fn_sig.visibility, span);
22302230
// A conservative estimation, the goal is to be over all parens in generics
22312231
let params_start = fn_sig
22322232
.generics
@@ -2984,7 +2984,7 @@ fn format_header(
29842984
let mut result = String::with_capacity(128);
29852985
let shape = Shape::indented(offset, context.config);
29862986

2987-
result.push_str(&format_visibility(context, vis).trim());
2987+
result.push_str(format_visibility(context, vis).trim());
29882988

29892989
// Check for a missing comment between the visibility and the item name.
29902990
let after_vis = vis.span.hi();
@@ -3005,7 +3005,7 @@ fn format_header(
30053005
}
30063006
}
30073007

3008-
result.push_str(&rewrite_ident(context, ident));
3008+
result.push_str(rewrite_ident(context, ident));
30093009

30103010
result
30113011
}
@@ -3133,7 +3133,7 @@ impl Rewrite for ast::ForeignItem {
31333133
let inner_attrs = inner_attributes(&self.attrs);
31343134
let fn_ctxt = visit::FnCtxt::Foreign;
31353135
visitor.visit_fn(
3136-
visit::FnKind::Fn(fn_ctxt, self.ident, &fn_sig, &self.vis, Some(body)),
3136+
visit::FnKind::Fn(fn_ctxt, self.ident, fn_sig, &self.vis, Some(body)),
31373137
generics,
31383138
&fn_sig.decl,
31393139
self.span,
@@ -3146,7 +3146,7 @@ impl Rewrite for ast::ForeignItem {
31463146
context,
31473147
shape.indent,
31483148
self.ident,
3149-
&FnSig::from_method_sig(&fn_sig, generics, &self.vis),
3149+
&FnSig::from_method_sig(fn_sig, generics, &self.vis),
31503150
span,
31513151
FnBraceStyle::None,
31523152
)
@@ -3171,7 +3171,7 @@ impl Rewrite for ast::ForeignItem {
31713171
let ast::TyAliasKind(_, ref generics, ref generic_bounds, ref type_default) =
31723172
**ty_alias_kind;
31733173
rewrite_type(
3174-
&context,
3174+
context,
31753175
shape.indent,
31763176
self.ident,
31773177
&self.vis,
@@ -3229,7 +3229,7 @@ fn rewrite_attrs(
32293229
combine_strs_with_missing_comments(
32303230
context,
32313231
&attrs_str,
3232-
&item_str,
3232+
item_str,
32333233
missed_span,
32343234
shape,
32353235
allow_extend,

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl FormatReport {
283283
writeln!(
284284
t,
285285
"{}",
286-
FormatReportFormatterBuilder::new(&self)
286+
FormatReportFormatterBuilder::new(self)
287287
.enable_colors(true)
288288
.build()
289289
)?;
@@ -297,7 +297,7 @@ impl FormatReport {
297297
impl fmt::Display for FormatReport {
298298
// Prints all the formatting errors.
299299
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
300-
write!(fmt, "{}", FormatReportFormatterBuilder::new(&self).build())?;
300+
write!(fmt, "{}", FormatReportFormatterBuilder::new(self).build())?;
301301
Ok(())
302302
}
303303
}

0 commit comments

Comments
 (0)