Skip to content

Commit

Permalink
Fix adjacent code
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Feb 23, 2025
1 parent acd3cff commit cb609f7
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Lint {
/// Returns the lints in a `HashMap`, grouped by the different lint groups
#[must_use]
fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
lints.map(|lint| (lint.group.to_string(), lint)).into_group_map()
lints.map(|lint| (lint.group.clone(), lint)).into_group_map()
}
}

Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/blocks_in_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
cond.span,
BRACED_EXPR_MESSAGE,
"try",
snippet_block_with_applicability(cx, ex.span, "..", Some(expr.span), &mut applicability)
.to_string(),
snippet_block_with_applicability(cx, ex.span, "..", Some(expr.span), &mut applicability),
applicability,
);
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ fn lint_branches_sharing_code<'tcx>(
let cond_snippet = reindent_multiline(&snippet(cx, cond_span, "_"), false, None);
let cond_indent = indent_of(cx, cond_span);
let moved_snippet = reindent_multiline(&snippet(cx, span, "_"), true, None);
let suggestion = moved_snippet.to_string() + "\n" + &cond_snippet + "{";
let suggestion = moved_snippet + "\n" + &cond_snippet + "{";
let suggestion = reindent_multiline(&suggestion, true, cond_indent);
(replace_span, suggestion.to_string())
(replace_span, suggestion)
});
let end_suggestion = res.end_span(last_block, sm).map(|span| {
let moved_snipped = reindent_multiline(&snippet(cx, span, "_"), true, None);
Expand All @@ -263,7 +263,7 @@ fn lint_branches_sharing_code<'tcx>(
.then_some(range.start - 4..range.end)
})
.map_or(span, |range| range.with_ctxt(span.ctxt()));
(span, suggestion.to_string())
(span, suggestion.clone())
});

let (span, msg, end_span) = match (&start_suggestion, &end_suggestion) {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/if_not_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl LateLintPass<'_> for IfNotElse {
e.span,
msg,
"try",
make_sugg(cx, &cond.kind, cond_inner.span, els.span, "..", Some(e.span)).to_string(),
make_sugg(cx, &cond.kind, cond_inner.span, els.span, "..", Some(e.span)),
Applicability::MachineApplicable,
),
_ => span_lint_and_help(cx, IF_NOT_ELSE, e.span, msg, None, help),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/manual_async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
format!("{} async {}", vis_snip, &header_snip[vis_snip.len() + 1..ret_pos])
};

let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block.span)).to_string();
let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block.span));

diag.multipart_suggestion(
"make the function `async` and return the output of the future directly",
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/matches/match_single_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
Some(expr.span),
&mut app,
)
.0
.to_string();
.0;

// Do we need to add ';' to suggestion ?
if let Node::Stmt(stmt) = cx.tcx.parent_hir_node(expr.hir_id)
Expand Down
6 changes: 2 additions & 4 deletions clippy_lints/src/matches/single_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ fn report_single_pattern(cx: &LateContext<'_>, ex: &Expr<'_>, arm: &Arm<'_>, exp
let (sugg, help) = if is_unit_expr(arm.body) {
(String::new(), "`match` expression can be removed")
} else {
let mut sugg = snippet_block_with_context(cx, arm.body.span, ctxt, "..", Some(expr.span), &mut app)
.0
.to_string();
let mut sugg = snippet_block_with_context(cx, arm.body.span, ctxt, "..", Some(expr.span), &mut app).0;
if let Node::Stmt(stmt) = cx.tcx.parent_hir_node(expr.hir_id)
&& let StmtKind::Expr(_) = stmt.kind
&& match arm.body.kind {
Expand All @@ -109,7 +107,7 @@ fn report_single_pattern(cx: &LateContext<'_>, ex: &Expr<'_>, arm: &Arm<'_>, exp
}
(sugg, "try")
};
span_lint_and_sugg(cx, lint, expr.span, msg, help, sugg.to_string(), app);
span_lint_and_sugg(cx, lint, expr.span, msg, help, sugg, app);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/unnecessary_sort_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub(super) fn check<'tcx>(
{
format!("{}::cmp::Reverse({})", std_or_core, trigger.closure_body)
} else {
trigger.closure_body.to_string()
trigger.closure_body
},
),
if trigger.reverse {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/redundant_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl EarlyLintPass for RedundantElse {
els.span.with_lo(then.span.hi()),
"redundant else block",
"remove the `else` block and move the contents out",
make_sugg(cx, els.span, "..", Some(expr.span)).to_string(),
make_sugg(cx, els.span, "..", Some(expr.span)),
app,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lintcheck/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn read_crates(toml_path: &Path) -> (Vec<CrateWithSource>, RecursiveOptions)
crate_sources.push(CrateWithSource {
name: tk.name.clone(),
source: CrateSource::CratesIo {
version: version.to_string(),
version: version.clone(),
},
file_link: tk.file_link(DEFAULT_DOCS_LINK),
options: tk.options.clone(),
Expand Down
2 changes: 1 addition & 1 deletion lintcheck/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
let same_in_both_hashmaps = old_stats
.iter()
.filter(|(old_key, old_val)| new_stats.get::<&String>(old_key) == Some(old_val))
.map(|(k, v)| (k.to_string(), *v))
.map(|(k, v)| (k.clone(), *v))
.collect::<Vec<(String, usize)>>();

let mut old_stats_deduped = old_stats;
Expand Down

0 comments on commit cb609f7

Please sign in to comment.