Skip to content

Rename some name variables as ident. #139510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub mod typetree;
#[derive(Debug, Clone, Encodable, Decodable, HashStable_Generic)]
pub struct StrippedCfgItem<ModId = DefId> {
pub parent_module: ModId,
pub name: Ident,
pub ident: Ident,
pub cfg: MetaItem,
}

impl<ModId> StrippedCfgItem<ModId> {
pub fn map_mod_id<New>(self, f: impl FnOnce(ModId) -> New) -> StrippedCfgItem<New> {
StrippedCfgItem { parent_module: f(self.parent_module), name: self.name, cfg: self.cfg }
StrippedCfgItem { parent_module: f(self.parent_module), ident: self.ident, cfg: self.cfg }
}
}
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
(
// Disallow `impl Trait` in foreign items.
this.lower_fn_decl(fdec, i.id, sig.span, FnDeclKind::ExternFn, None),
this.lower_fn_params_to_names(fdec),
this.lower_fn_params_to_idents(fdec),
)
});

Expand Down Expand Up @@ -833,7 +833,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}) => {
// FIXME(contracts): Deny contract here since it won't apply to
// any impl method or callees.
let names = self.lower_fn_params_to_names(&sig.decl);
let idents = self.lower_fn_params_to_idents(&sig.decl);
let (generics, sig) = self.lower_method_sig(
generics,
sig,
Expand All @@ -851,7 +851,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
(
*ident,
generics,
hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)),
hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(idents)),
false,
)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
safety: self.lower_safety(f.safety, hir::Safety::Safe),
abi: self.lower_extern(f.ext),
decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None),
param_names: self.lower_fn_params_to_names(&f.decl),
param_idents: self.lower_fn_params_to_idents(&f.decl),
}))
}
TyKind::UnsafeBinder(f) => {
Expand Down Expand Up @@ -1494,7 +1494,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}))
}

fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
PatKind::Missing => None,
PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use super::*;
fn fun_to_string(
decl: &ast::FnDecl,
header: ast::FnHeader,
name: Ident,
ident: Ident,
generics: &ast::Generics,
) -> String {
to_string(|s| {
s.head("");
s.print_fn(decl, header, Some(name), generics);
s.print_fn(decl, header, Some(ident), generics);
s.end(); // Close the head box.
s.end(); // Close the outer box.
})
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,11 +2500,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
);
let ty::Tuple(params) = tupled_params.kind() else { return };

// Find the first argument with a matching type, get its name
let Some(this_name) = params.iter().zip(tcx.hir_body_param_names(closure.body)).find_map(
|(param_ty, name)| {
// Find the first argument with a matching type and get its identifier.
let Some(this_name) = params.iter().zip(tcx.hir_body_param_idents(closure.body)).find_map(
|(param_ty, ident)| {
// FIXME: also support deref for stuff like `Rc` arguments
if param_ty.peel_refs() == local_ty { name } else { None }
if param_ty.peel_refs() == local_ty { ident } else { None }
},
) else {
return;
Expand Down Expand Up @@ -3774,7 +3774,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
method_args,
*fn_span,
call_source.from_hir_call(),
self.infcx.tcx.fn_arg_names(method_did)[0],
self.infcx.tcx.fn_arg_idents(method_did)[0],
)
{
err.note(format!("borrow occurs due to deref coercion to `{deref_target_ty}`"));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
method_args,
*fn_span,
call_source.from_hir_call(),
self.infcx.tcx.fn_arg_names(method_did)[0],
self.infcx.tcx.fn_arg_idents(method_did)[0],
);

return FnSelfUse {
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use crate::errors;
struct ProcMacroDerive {
id: NodeId,
trait_name: Symbol,
function_name: Ident,
function_ident: Ident,
span: Span,
attrs: Vec<Symbol>,
}

struct ProcMacroDef {
id: NodeId,
function_name: Ident,
function_ident: Ident,
span: Span,
}

Expand Down Expand Up @@ -95,7 +95,7 @@ impl<'a> CollectProcMacros<'a> {
fn collect_custom_derive(
&mut self,
item: &'a ast::Item,
function_name: Ident,
function_ident: Ident,
attr: &'a ast::Attribute,
) {
let Some((trait_name, proc_attrs)) =
Expand All @@ -109,7 +109,7 @@ impl<'a> CollectProcMacros<'a> {
id: item.id,
span: item.span,
trait_name,
function_name,
function_ident,
attrs: proc_attrs,
}));
} else {
Expand All @@ -123,12 +123,12 @@ impl<'a> CollectProcMacros<'a> {
}
}

fn collect_attr_proc_macro(&mut self, item: &'a ast::Item, function_name: Ident) {
fn collect_attr_proc_macro(&mut self, item: &'a ast::Item, function_ident: Ident) {
if self.in_root && item.vis.kind.is_pub() {
self.macros.push(ProcMacro::Attr(ProcMacroDef {
id: item.id,
span: item.span,
function_name,
function_ident,
}));
} else {
let msg = if !self.in_root {
Expand All @@ -141,12 +141,12 @@ impl<'a> CollectProcMacros<'a> {
}
}

fn collect_bang_proc_macro(&mut self, item: &'a ast::Item, function_name: Ident) {
fn collect_bang_proc_macro(&mut self, item: &'a ast::Item, function_ident: Ident) {
if self.in_root && item.vis.kind.is_pub() {
self.macros.push(ProcMacro::Bang(ProcMacroDef {
id: item.id,
span: item.span,
function_name,
function_ident,
}));
} else {
let msg = if !self.in_root {
Expand Down Expand Up @@ -303,7 +303,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
ProcMacro::Derive(m) => m.span,
ProcMacro::Attr(m) | ProcMacro::Bang(m) => m.span,
};
let local_path = |cx: &ExtCtxt<'_>, name| cx.expr_path(cx.path(span, vec![name]));
let local_path = |cx: &ExtCtxt<'_>, ident| cx.expr_path(cx.path(span, vec![ident]));
let proc_macro_ty_method_path = |cx: &ExtCtxt<'_>, method| {
cx.expr_path(cx.path(
span.with_ctxt(harness_span.ctxt()),
Expand All @@ -327,7 +327,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
.map(|&s| cx.expr_str(span, s))
.collect::<ThinVec<_>>(),
),
local_path(cx, cd.function_name),
local_path(cx, cd.function_ident),
],
)
}
Expand All @@ -345,8 +345,8 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
harness_span,
proc_macro_ty_method_path(cx, ident),
thin_vec![
cx.expr_str(span, ca.function_name.name),
local_path(cx, ca.function_name),
cx.expr_str(span, ca.function_ident.name),
local_path(cx, ca.function_ident),
],
)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub(crate) fn maybe_create_entry_wrapper(
let termination_trait = tcx.require_lang_item(LangItem::Termination, None);
let report = tcx
.associated_items(termination_trait)
.find_by_name_and_kind(
.find_by_ident_and_kind(
tcx,
Ident::from_str("report"),
AssocKind::Fn,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ pub trait ResolverExpand {
/// HIR proc macros items back to their harness items.
fn declare_proc_macro(&mut self, id: NodeId);

fn append_stripped_cfg_item(&mut self, parent_node: NodeId, name: Ident, cfg: ast::MetaItem);
fn append_stripped_cfg_item(&mut self, parent_node: NodeId, ident: Ident, cfg: ast::MetaItem);

/// Tools registered with `#![register_tool]` and used by tool attributes and lints.
fn registered_tools(&self) -> &RegisteredTools;
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,9 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
collector.cx.dcx().emit_err(RemoveNodeNotSupported { span, descr: Self::descr() });
}

/// All of the names (items) declared by this node.
/// All of the identifiers (items) declared by this node.
/// This is an approximation and should only be used for diagnostics.
fn declared_names(&self) -> Vec<Ident> {
fn declared_idents(&self) -> Vec<Ident> {
vec![]
}
}
Expand Down Expand Up @@ -1306,7 +1306,7 @@ impl InvocationCollectorNode for P<ast::Item> {
res
}

fn declared_names(&self) -> Vec<Ident> {
fn declared_idents(&self) -> Vec<Ident> {
if let ItemKind::Use(ut) = &self.kind {
fn collect_use_tree_leaves(ut: &ast::UseTree, idents: &mut Vec<Ident>) {
match &ut.kind {
Expand Down Expand Up @@ -2061,10 +2061,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
}

if let Some(meta_item) = meta_item {
for name in node.declared_names() {
for ident in node.declared_idents() {
self.cx.resolver.append_stripped_cfg_item(
self.cx.current_expansion.lint_node_id,
name,
ident,
meta_item.clone(),
)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3399,9 +3399,9 @@ pub struct BareFnTy<'hir> {
pub abi: ExternAbi,
pub generic_params: &'hir [GenericParam<'hir>],
pub decl: &'hir FnDecl<'hir>,
// `Option` because bare fn parameter names are optional. We also end up
// `Option` because bare fn parameter identifiers are optional. We also end up
// with `None` in some error cases, e.g. invalid parameter patterns.
pub param_names: &'hir [Option<Ident>],
pub param_idents: &'hir [Option<Ident>],
}

#[derive(Debug, Clone, Copy, HashStable_Generic)]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(
try_visit!(visitor.visit_ident(foreign_item.ident));

match foreign_item.kind {
ForeignItemKind::Fn(ref sig, param_names, ref generics) => {
ForeignItemKind::Fn(ref sig, param_idents, ref generics) => {
try_visit!(visitor.visit_generics(generics));
try_visit!(visitor.visit_fn_decl(sig.decl));
for ident in param_names.iter().copied() {
for ident in param_idents.iter().copied() {
visit_opt!(visitor, visit_ident, ident);
}
}
Expand Down Expand Up @@ -1169,9 +1169,9 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(
try_visit!(visitor.visit_ty_unambig(ty));
visit_opt!(visitor, visit_nested_body, default);
}
TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
TraitItemKind::Fn(ref sig, TraitFn::Required(param_idents)) => {
try_visit!(visitor.visit_fn_decl(sig.decl));
for ident in param_names.iter().copied() {
for ident in param_idents.iter().copied() {
visit_opt!(visitor, visit_ident, ident);
}
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hir_analysis_ambiguous_assoc_item = ambiguous associated {$assoc_kind} `{$assoc_name}` in bounds of `{$qself}`
.label = ambiguous associated {$assoc_kind} `{$assoc_name}`
hir_analysis_ambiguous_assoc_item = ambiguous associated {$assoc_kind} `{$assoc_ident}` in bounds of `{$qself}`
.label = ambiguous associated {$assoc_kind} `{$assoc_ident}`

hir_analysis_ambiguous_lifetime_bound =
ambiguous lifetime bound, explicit lifetime bound required
Expand All @@ -12,13 +12,13 @@ hir_analysis_assoc_item_is_private = {$kind} `{$name}` is private
.label = private {$kind}
.defined_here_label = the {$kind} is defined here

hir_analysis_assoc_item_not_found = associated {$assoc_kind} `{$assoc_name}` not found for `{$qself}`
hir_analysis_assoc_item_not_found = associated {$assoc_kind} `{$assoc_ident}` not found for `{$qself}`

hir_analysis_assoc_item_not_found_found_in_other_trait_label = there is {$identically_named ->
[true] an
*[false] a similarly named
} associated {$assoc_kind} `{$suggested_name}` in the trait `{$trait_name}`
hir_analysis_assoc_item_not_found_label = associated {$assoc_kind} `{$assoc_name}` not found
hir_analysis_assoc_item_not_found_label = associated {$assoc_kind} `{$assoc_ident}` not found
hir_analysis_assoc_item_not_found_other_sugg = `{$qself}` has the following associated {$assoc_kind}
hir_analysis_assoc_item_not_found_similar_in_other_trait_qpath_sugg =
consider fully qualifying{$identically_named ->
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,11 @@ fn report_trait_method_mismatch<'tcx>(
// argument pattern and type.
let (sig, body) = tcx.hir_expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
let span = tcx
.hir_body_param_names(body)
.hir_body_param_idents(body)
.zip(sig.decl.inputs.iter())
.map(|(param_name, ty)| {
if let Some(param_name) = param_name {
param_name.span.to(ty.span)
.map(|(param_ident, ty)| {
if let Some(param_ident) = param_ident {
param_ident.span.to(ty.span)
} else {
ty.span
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
&self,
span: Span,
def_id: LocalDefId,
assoc_name: Ident,
assoc_ident: Ident,
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name))
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_ident))
}

fn lower_assoc_shared(
Expand Down
Loading
Loading