1
Fork 0

Remove redundant to_ident_string calls

This commit is contained in:
Michael Goulet 2025-01-27 01:21:40 +00:00
parent ac1c6c50f4
commit c08624d8d2
10 changed files with 14 additions and 18 deletions

View file

@ -157,7 +157,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
{ {
cx.dcx().emit_err(RequiresMaybeSized { cx.dcx().emit_err(RequiresMaybeSized {
span: pointee_ty_ident.span, span: pointee_ty_ident.span,
name: pointee_ty_ident.name.to_ident_string(), name: pointee_ty_ident,
}); });
return; return;
} }
@ -471,5 +471,5 @@ struct TooManyPointees {
struct RequiresMaybeSized { struct RequiresMaybeSized {
#[primary_span] #[primary_span]
span: Span, span: Span,
name: String, name: Ident,
} }

View file

@ -495,7 +495,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
.iter() .iter()
.any(|constraint| constraint.ident.name == item.name) .any(|constraint| constraint.ident.name == item.name)
}) })
.map(|item| item.name.to_ident_string()) .map(|item| self.tcx.item_ident(item.def_id).to_string())
.collect() .collect()
} else { } else {
Vec::default() Vec::default()

View file

@ -3337,10 +3337,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}) })
.map(|mut field_path| { .map(|mut field_path| {
field_path.pop(); field_path.pop();
field_path field_path.iter().map(|id| format!("{}.", id)).collect::<String>()
.iter()
.map(|id| format!("{}.", id.name.to_ident_string()))
.collect::<String>()
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
candidate_fields.sort(); candidate_fields.sort();

View file

@ -453,7 +453,7 @@ fn report_unexpected_variant_res(
); );
let fields = fields let fields = fields
.iter() .iter()
.map(|field| format!("{}: _", field.name.to_ident_string())) .map(|field| format!("{}: _", field.ident(tcx)))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "); .join(", ");
let sugg = format!(" {{ {} }}", fields); let sugg = format!(" {{ {} }}", fields);

View file

@ -2714,7 +2714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.map(|field_path| { .map(|field_path| {
field_path field_path
.iter() .iter()
.map(|id| id.name.to_ident_string()) .map(|id| id.to_string())
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(".") .join(".")
}) })

View file

@ -343,5 +343,5 @@ fn path_span_without_args(path: &Path<'_>) -> Span {
/// Return a "error message-able" ident for the last segment of the `Path` /// Return a "error message-able" ident for the last segment of the `Path`
fn path_name_to_string(path: &Path<'_>) -> String { fn path_name_to_string(path: &Path<'_>) -> String {
path.segments.last().unwrap().ident.name.to_ident_string() path.segments.last().unwrap().ident.to_string()
} }

View file

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

View file

@ -5,7 +5,7 @@ use rustc_middle::mir::AssertKind;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::lint::{self, Lint}; use rustc_session::lint::{self, Lint};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::{Span, Symbol}; use rustc_span::{Ident, Span, Symbol};
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
@ -114,7 +114,7 @@ pub(crate) struct FnItemRef {
#[suggestion(code = "{sugg}", applicability = "unspecified")] #[suggestion(code = "{sugg}", applicability = "unspecified")]
pub span: Span, pub span: Span,
pub sugg: String, pub sugg: String,
pub ident: String, pub ident: Ident,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]

View file

@ -168,7 +168,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
s s
} }
}; };
let ident = self.tcx.item_name(fn_id).to_ident_string(); let ident = self.tcx.item_ident(fn_id);
let ty_params = fn_args.types().map(|ty| format!("{ty}")); let ty_params = fn_args.types().map(|ty| format!("{ty}"));
let const_params = fn_args.consts().map(|c| format!("{c}")); let const_params = fn_args.consts().map(|c| format!("{c}"));
let params = ty_params.chain(const_params).join(", "); let params = ty_params.chain(const_params).join(", ");
@ -177,7 +177,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
let ret = if fn_sig.output().skip_binder().is_unit() { "" } else { " -> _" }; let ret = if fn_sig.output().skip_binder().is_unit() { "" } else { " -> _" };
let sugg = format!( let sugg = format!(
"{} as {}{}fn({}{}){}", "{} as {}{}fn({}{}){}",
if params.is_empty() { ident.clone() } else { format!("{ident}::<{params}>") }, if params.is_empty() { ident.to_string() } else { format!("{ident}::<{params}>") },
unsafety, unsafety,
abi, abi,
vec!["_"; num_args].join(", "), vec!["_"; num_args].join(", "),

View file

@ -1636,13 +1636,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
.enumerate() .enumerate()
.map(|(idx, new)| (new, old_fields.get(idx))) .map(|(idx, new)| (new, old_fields.get(idx)))
.map(|(new, old)| { .map(|(new, old)| {
let new = new.name.to_ident_string();
if let Some(Some(old)) = old if let Some(Some(old)) = old
&& new != *old && new.as_str() != old
{ {
format!("{new}: {old}") format!("{new}: {old}")
} else { } else {
new new.to_string()
} }
}) })
.collect::<Vec<String>>() .collect::<Vec<String>>()