Skip to content

Commit

Permalink
Remove redundant to_ident_string calls
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jan 27, 2025
1 parent ac1c6c5 commit c08624d
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
{
cx.dcx().emit_err(RequiresMaybeSized {
span: pointee_ty_ident.span,
name: pointee_ty_ident.name.to_ident_string(),
name: pointee_ty_ident,
});
return;
}
Expand Down Expand Up @@ -471,5 +471,5 @@ struct TooManyPointees {
struct RequiresMaybeSized {
#[primary_span]
span: Span,
name: String,
name: Ident,
}
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
.iter()
.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()
} else {
Vec::default()
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3337,10 +3337,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
.map(|mut field_path| {
field_path.pop();
field_path
.iter()
.map(|id| format!("{}.", id.name.to_ident_string()))
.collect::<String>()
field_path.iter().map(|id| format!("{}.", id)).collect::<String>()
})
.collect::<Vec<_>>();
candidate_fields.sort();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ fn report_unexpected_variant_res(
);
let fields = fields
.iter()
.map(|field| format!("{}: _", field.name.to_ident_string()))
.map(|field| format!("{}: _", field.ident(tcx)))
.collect::<Vec<_>>()
.join(", ");
let sugg = format!(" {{ {} }}", fields);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.map(|field_path| {
field_path
.iter()
.map(|id| id.name.to_ident_string())
.map(|id| id.to_string())
.collect::<Vec<String>>()
.join(".")
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
fn path_name_to_string(path: &Path<'_>) -> String {
path.segments.last().unwrap().ident.name.to_ident_string()
path.segments.last().unwrap().ident.to_string()
}
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
match path.res {
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();
return Some(format!("{}{}", name, gen_args(cx, path_segment)));
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_middle::mir::AssertKind;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::{self, Lint};
use rustc_span::def_id::DefId;
use rustc_span::{Span, Symbol};
use rustc_span::{Ident, Span, Symbol};

use crate::fluent_generated as fluent;

Expand Down Expand Up @@ -114,7 +114,7 @@ pub(crate) struct FnItemRef {
#[suggestion(code = "{sugg}", applicability = "unspecified")]
pub span: Span,
pub sugg: String,
pub ident: String,
pub ident: Ident,
}

#[derive(Diagnostic)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/function_item_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
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 const_params = fn_args.consts().map(|c| format!("{c}"));
let params = ty_params.chain(const_params).join(", ");
Expand All @@ -177,7 +177,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
let ret = if fn_sig.output().skip_binder().is_unit() { "" } else { " -> _" };
let sugg = format!(
"{} as {}{}fn({}{}){}",
if params.is_empty() { ident.clone() } else { format!("{ident}::<{params}>") },
if params.is_empty() { ident.to_string() } else { format!("{ident}::<{params}>") },
unsafety,
abi,
vec!["_"; num_args].join(", "),
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,13 +1636,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
.enumerate()
.map(|(idx, new)| (new, old_fields.get(idx)))
.map(|(new, old)| {
let new = new.name.to_ident_string();
if let Some(Some(old)) = old
&& new != *old
&& new.as_str() != old
{
format!("{new}: {old}")
} else {
new
new.to_string()
}
})
.collect::<Vec<String>>()
Expand Down

0 comments on commit c08624d

Please sign in to comment.