Skip to content

Commit 8461d3f

Browse files
committed
Remove unnecessary string allocation
1 parent 3bc089e commit 8461d3f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

clippy_lints/src/manual_is_ascii_check.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::ast::RangeLimits;
99
use rustc_errors::Applicability;
1010
use rustc_hir::{Expr, ExprKind, Node, Param, PatKind, RangeEnd};
1111
use rustc_lint::{LateContext, LateLintPass};
12-
use rustc_middle::ty;
12+
use rustc_middle::ty::{self, Ty};
1313
use rustc_session::impl_lint_pass;
1414
use rustc_span::{Span, sym};
1515

@@ -123,15 +123,14 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsAsciiCheck {
123123
extract_msrv_attr!(LateContext);
124124
}
125125

126-
fn get_ty_sugg(cx: &LateContext<'_>, arg: &Expr<'_>) -> Option<(Span, String)> {
126+
fn get_ty_sugg<'tcx>(cx: &LateContext<'tcx>, arg: &Expr<'_>) -> Option<(Span, Ty<'tcx>)> {
127127
let local_hid = path_to_local(arg)?;
128128
if let Node::Param(Param { ty_span, span, .. }) = cx.tcx.parent_hir_node(local_hid)
129129
// `ty_span` and `span` are the same for inferred type, thus a type suggestion must be given
130130
&& ty_span == span
131131
{
132132
let arg_type = cx.typeck_results().expr_ty(arg);
133-
let ty_str = arg_type.to_string();
134-
return Some((*ty_span, ty_str));
133+
return Some((*ty_span, arg_type));
135134
}
136135
None
137136
}
@@ -141,7 +140,7 @@ fn check_is_ascii(
141140
span: Span,
142141
recv: &Expr<'_>,
143142
range: &CharRange,
144-
ty_sugg: Option<(Span, String)>,
143+
ty_sugg: Option<(Span, Ty<'_>)>,
145144
) {
146145
let sugg = match range {
147146
CharRange::UpperChar => "is_ascii_uppercase",
@@ -155,8 +154,8 @@ fn check_is_ascii(
155154
let mut app = Applicability::MachineApplicable;
156155
let recv = Sugg::hir_with_context(cx, recv, span.ctxt(), default_snip, &mut app).maybe_par();
157156
let mut suggestion = vec![(span, format!("{recv}.{sugg}()"))];
158-
if let Some((ty_span, ty_str)) = ty_sugg {
159-
suggestion.push((ty_span, format!("{recv}: {ty_str}")));
157+
if let Some((ty_span, ty)) = ty_sugg {
158+
suggestion.push((ty_span, format!("{recv}: {ty}")));
160159
}
161160

162161
span_lint_and_then(

0 commit comments

Comments
 (0)