Rename some name
variables as ident
.
It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk.
This commit is contained in:
parent
d4f880f8ce
commit
1b3fc585cb
52 changed files with 238 additions and 229 deletions
|
@ -281,7 +281,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn hir_body_param_names(self, id: BodyId) -> impl Iterator<Item = Option<Ident>> {
|
||||
pub fn hir_body_param_idents(self, id: BodyId) -> impl Iterator<Item = Option<Ident>> {
|
||||
self.hir_body(id).params.iter().map(|param| match param.pat.kind {
|
||||
PatKind::Binding(_, _, ident, _) => Some(ident),
|
||||
PatKind::Wild => Some(Ident::new(kw::Underscore, param.pat.span)),
|
||||
|
|
|
@ -215,9 +215,9 @@ pub fn provide(providers: &mut Providers) {
|
|||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||
tcx.hir_opt_ident_span(hir_id)
|
||||
};
|
||||
providers.fn_arg_names = |tcx, def_id| {
|
||||
providers.fn_arg_idents = |tcx, def_id| {
|
||||
if let Some(body_id) = tcx.hir_node_by_def_id(def_id).body_id() {
|
||||
tcx.arena.alloc_from_iter(tcx.hir_body_param_names(body_id))
|
||||
tcx.arena.alloc_from_iter(tcx.hir_body_param_idents(body_id))
|
||||
} else if let Node::TraitItem(&TraitItem {
|
||||
kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
|
||||
..
|
||||
|
@ -231,7 +231,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
} else {
|
||||
span_bug!(
|
||||
tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
|
||||
"fn_arg_names: unexpected item {:?}",
|
||||
"fn_arg_idents: unexpected item {:?}",
|
||||
def_id
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1435,8 +1435,8 @@ rustc_queries! {
|
|||
desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
|
||||
}
|
||||
|
||||
query fn_arg_names(def_id: DefId) -> &'tcx [Option<rustc_span::Ident>] {
|
||||
desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
|
||||
query fn_arg_idents(def_id: DefId) -> &'tcx [Option<rustc_span::Ident>] {
|
||||
desc { |tcx| "looking up function parameter idents for `{}`", tcx.def_path_str(def_id) }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
||||
|
|
|
@ -199,8 +199,8 @@ impl AssocItems {
|
|||
self.items.get_by_key(name)
|
||||
}
|
||||
|
||||
/// Returns the associated item with the given name and `AssocKind`, if one exists.
|
||||
pub fn find_by_name_and_kind(
|
||||
/// Returns the associated item with the given ident and `AssocKind`, if one exists.
|
||||
pub fn find_by_ident_and_kind(
|
||||
&self,
|
||||
tcx: TyCtxt<'_>,
|
||||
ident: Ident,
|
||||
|
@ -212,8 +212,8 @@ impl AssocItems {
|
|||
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
|
||||
}
|
||||
|
||||
/// Returns the associated item with the given name and any of `AssocKind`, if one exists.
|
||||
pub fn find_by_name_and_kinds(
|
||||
/// Returns the associated item with the given ident and any of `AssocKind`, if one exists.
|
||||
pub fn find_by_ident_and_kinds(
|
||||
&self,
|
||||
tcx: TyCtxt<'_>,
|
||||
ident: Ident,
|
||||
|
@ -221,11 +221,11 @@ impl AssocItems {
|
|||
kinds: &[AssocKind],
|
||||
parent_def_id: DefId,
|
||||
) -> Option<&ty::AssocItem> {
|
||||
kinds.iter().find_map(|kind| self.find_by_name_and_kind(tcx, ident, *kind, parent_def_id))
|
||||
kinds.iter().find_map(|kind| self.find_by_ident_and_kind(tcx, ident, *kind, parent_def_id))
|
||||
}
|
||||
|
||||
/// Returns the associated item with the given name in the given `Namespace`, if one exists.
|
||||
pub fn find_by_name_and_namespace(
|
||||
/// Returns the associated item with the given ident in the given `Namespace`, if one exists.
|
||||
pub fn find_by_ident_and_namespace(
|
||||
&self,
|
||||
tcx: TyCtxt<'_>,
|
||||
ident: Ident,
|
||||
|
|
|
@ -1939,15 +1939,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// Hygienically compares a use-site name (`use_name`) for a field or an associated item with
|
||||
/// its supposed definition name (`def_name`). The method also needs `DefId` of the supposed
|
||||
/// definition's parent/scope to perform comparison.
|
||||
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
|
||||
// We could use `Ident::eq` here, but we deliberately don't. The name
|
||||
pub fn hygienic_eq(self, use_ident: Ident, def_ident: Ident, def_parent_def_id: DefId) -> bool {
|
||||
// We could use `Ident::eq` here, but we deliberately don't. The ident
|
||||
// comparison fails frequently, and we want to avoid the expensive
|
||||
// `normalize_to_macros_2_0()` calls required for the span comparison whenever possible.
|
||||
use_name.name == def_name.name
|
||||
&& use_name
|
||||
use_ident.name == def_ident.name
|
||||
&& use_ident
|
||||
.span
|
||||
.ctxt()
|
||||
.hygienic_eq(def_name.span.ctxt(), self.expn_that_defined(def_parent_def_id))
|
||||
.hygienic_eq(def_ident.span.ctxt(), self.expn_that_defined(def_parent_def_id))
|
||||
}
|
||||
|
||||
pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue