remove unnecessary to_string and String::new

This commit is contained in:
Takayuki Maeda 2022-06-13 15:48:40 +09:00
parent e34621c24e
commit f2d9acfc01
16 changed files with 19 additions and 19 deletions

View File

@ -90,7 +90,7 @@ fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg
diag.span_suggestion(
span,
"use an inclusive range",
sugg.to_owned(),
sugg,
Applicability::MaybeIncorrect,
);
}

View File

@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for AsUnderscore {
diag.span_suggestion(
ty.span,
"consider giving the type explicitly",
format!("{}", ty_resolved),
ty_resolved,
Applicability::MachineApplicable,
);
}

View File

@ -44,7 +44,7 @@ impl EarlyLintPass for EmptyStructsWithBrackets {
diagnostic.span_suggestion_hidden(
span_after_ident,
"remove the brackets",
";".to_string(),
";",
Applicability::MachineApplicable);
},
);

View File

@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
diag.span_suggestion(
sugg_span,
"make this a static item",
"static".to_string(),
"static",
Applicability::MachineApplicable,
);
}

View File

@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
diag.span_suggestion(
block.span,
"move the body of the async block to the enclosing function",
body_snip.to_string(),
body_snip,
Applicability::MachineApplicable
);
}

View File

@ -113,7 +113,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
diag.span_suggestion(
arm1.span,
"try removing the arm",
String::new(),
"",
Applicability::MaybeIncorrect,
)
.help("or try changing either arm body")

View File

@ -176,13 +176,13 @@ fn check_manual_split_once_indirect(
diag.span_suggestion(
first.span,
&remove_msg,
String::new(),
"",
app,
);
diag.span_suggestion(
second.span,
&remove_msg,
String::new(),
"",
app,
);
});

View File

@ -85,7 +85,7 @@ pub fn check_for_loop_iter(
match addr_of_expr.kind {
ExprKind::AddrOf(_, _, referent) => {
let span = addr_of_expr.span.with_hi(referent.span.lo());
diag.span_suggestion(span, "remove this `&`", String::new(), applicability);
diag.span_suggestion(span, "remove this `&`", "", applicability);
}
_ => unreachable!(),
}

View File

@ -318,7 +318,7 @@ fn check<'tcx>(
diag.span_suggestion(
usage.stmt.span.shrink_to_hi(),
"add a semicolon after the `if` expression",
";".to_string(),
";",
applicability,
);
}
@ -353,7 +353,7 @@ fn check<'tcx>(
diag.span_suggestion(
usage.stmt.span.shrink_to_hi(),
"add a semicolon after the `match` expression",
";".to_string(),
";",
applicability,
);
}

View File

@ -258,7 +258,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
diag.span_suggestion(
input.span,
"consider changing the type to",
"&str".to_string(),
"&str",
Applicability::Unspecified,
);

View File

@ -255,7 +255,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
diag.span_suggestion(
sugg_span,
"remove this",
String::new(),
"",
app,
);
if clone_usage.cloned_used {

View File

@ -55,7 +55,7 @@ pub(super) fn check<'tcx>(
sugg
};
diag.span_suggestion(e.span, "consider using", sugg.to_string(), Applicability::Unspecified);
diag.span_suggestion(e.span, "consider using", sugg, Applicability::Unspecified);
},
);
true

View File

@ -25,7 +25,7 @@ pub(super) fn check<'tcx>(
|diag| {
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
let sugg = arg.as_ty(cx.tcx.mk_ptr(*to_ty));
diag.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified);
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
}
},
);

View File

@ -73,7 +73,7 @@ pub(super) fn check<'tcx>(
diag.span_suggestion(
e.span,
"try",
sugg.to_string(),
sugg,
Applicability::Unspecified,
);
},

View File

@ -46,7 +46,7 @@ pub(super) fn check<'tcx>(
arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty)
};
diag.span_suggestion(e.span, "try", sugg.to_string(), Applicability::Unspecified);
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
}
},
);
@ -64,7 +64,7 @@ pub(super) fn check<'tcx>(
diag.span_suggestion(
e.span,
"try",
arg.as_ty(&to_ty.to_string()).to_string(),
arg.as_ty(&to_ty.to_string()),
Applicability::Unspecified,
);
}

View File

@ -92,7 +92,7 @@ pub fn get_attr<'a>(
diag.span_suggestion(
attr_segments[1].ident.span,
"consider using",
new_name.to_string(),
new_name,
Applicability::MachineApplicable,
);
diag.emit();