Skip to content

Commit c08624d

Browse files
Remove redundant to_ident_string calls
1 parent ac1c6c5 commit c08624d

File tree

10 files changed

+14
-18
lines changed

10 files changed

+14
-18
lines changed

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
157157
{
158158
cx.dcx().emit_err(RequiresMaybeSized {
159159
span: pointee_ty_ident.span,
160-
name: pointee_ty_ident.name.to_ident_string(),
160+
name: pointee_ty_ident,
161161
});
162162
return;
163163
}
@@ -471,5 +471,5 @@ struct TooManyPointees {
471471
struct RequiresMaybeSized {
472472
#[primary_span]
473473
span: Span,
474-
name: String,
474+
name: Ident,
475475
}

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
495495
.iter()
496496
.any(|constraint| constraint.ident.name == item.name)
497497
})
498-
.map(|item| item.name.to_ident_string())
498+
.map(|item| self.tcx.item_ident(item.def_id).to_string())
499499
.collect()
500500
} else {
501501
Vec::default()

compiler/rustc_hir_typeck/src/expr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3337,10 +3337,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33373337
})
33383338
.map(|mut field_path| {
33393339
field_path.pop();
3340-
field_path
3341-
.iter()
3342-
.map(|id| format!("{}.", id.name.to_ident_string()))
3343-
.collect::<String>()
3340+
field_path.iter().map(|id| format!("{}.", id)).collect::<String>()
33443341
})
33453342
.collect::<Vec<_>>();
33463343
candidate_fields.sort();

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ fn report_unexpected_variant_res(
453453
);
454454
let fields = fields
455455
.iter()
456-
.map(|field| format!("{}: _", field.name.to_ident_string()))
456+
.map(|field| format!("{}: _", field.ident(tcx)))
457457
.collect::<Vec<_>>()
458458
.join(", ");
459459
let sugg = format!(" {{ {} }}", fields);

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2714,7 +2714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27142714
.map(|field_path| {
27152715
field_path
27162716
.iter()
2717-
.map(|id| id.name.to_ident_string())
2717+
.map(|id| id.to_string())
27182718
.collect::<Vec<String>>()
27192719
.join(".")
27202720
})

compiler/rustc_lint/src/non_local_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,5 +343,5 @@ fn path_span_without_args(path: &Path<'_>) -> Span {
343343

344344
/// Return a "error message-able" ident for the last segment of the `Path`
345345
fn path_name_to_string(path: &Path<'_>) -> String {
346-
path.segments.last().unwrap().ident.name.to_ident_string()
346+
path.segments.last().unwrap().ident.to_string()
347347
}

compiler/rustc_lint/src/pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
4545
if let TyKind::Path(QPath::Resolved(_, path)) = &ty.kind {
4646
match path.res {
4747
Res::Def(_, def_id) if cx.tcx.has_attr(def_id, sym::rustc_pass_by_value) => {
48-
let name = cx.tcx.item_name(def_id).to_ident_string();
48+
let name = cx.tcx.item_ident(def_id);
4949
let path_segment = path.segments.last().unwrap();
5050
return Some(format!("{}{}", name, gen_args(cx, path_segment)));
5151
}

compiler/rustc_mir_transform/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::mir::AssertKind;
55
use rustc_middle::ty::TyCtxt;
66
use rustc_session::lint::{self, Lint};
77
use rustc_span::def_id::DefId;
8-
use rustc_span::{Span, Symbol};
8+
use rustc_span::{Ident, Span, Symbol};
99

1010
use crate::fluent_generated as fluent;
1111

@@ -114,7 +114,7 @@ pub(crate) struct FnItemRef {
114114
#[suggestion(code = "{sugg}", applicability = "unspecified")]
115115
pub span: Span,
116116
pub sugg: String,
117-
pub ident: String,
117+
pub ident: Ident,
118118
}
119119

120120
#[derive(Diagnostic)]

compiler/rustc_mir_transform/src/function_item_references.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
168168
s
169169
}
170170
};
171-
let ident = self.tcx.item_name(fn_id).to_ident_string();
171+
let ident = self.tcx.item_ident(fn_id);
172172
let ty_params = fn_args.types().map(|ty| format!("{ty}"));
173173
let const_params = fn_args.consts().map(|c| format!("{c}"));
174174
let params = ty_params.chain(const_params).join(", ");
@@ -177,7 +177,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
177177
let ret = if fn_sig.output().skip_binder().is_unit() { "" } else { " -> _" };
178178
let sugg = format!(
179179
"{} as {}{}fn({}{}){}",
180-
if params.is_empty() { ident.clone() } else { format!("{ident}::<{params}>") },
180+
if params.is_empty() { ident.to_string() } else { format!("{ident}::<{params}>") },
181181
unsafety,
182182
abi,
183183
vec!["_"; num_args].join(", "),

compiler/rustc_resolve/src/late/diagnostics.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1636,13 +1636,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
16361636
.enumerate()
16371637
.map(|(idx, new)| (new, old_fields.get(idx)))
16381638
.map(|(new, old)| {
1639-
let new = new.name.to_ident_string();
16401639
if let Some(Some(old)) = old
1641-
&& new != *old
1640+
&& new.as_str() != old
16421641
{
16431642
format!("{new}: {old}")
16441643
} else {
1645-
new
1644+
new.to_string()
16461645
}
16471646
})
16481647
.collect::<Vec<String>>()

0 commit comments

Comments
 (0)