}
}
- pub fn name_by_hir_id(&self, id: HirId) -> Name {
+ pub fn name(&self, id: HirId) -> Name {
match self.get_by_hir_id(id) {
Node::Item(i) => i.ident.name,
Node::ForeignItem(fi) => fi.ident.name,
Node::Lifetime(lt) => lt.name.ident().name,
Node::GenericParam(param) => param.name.ident().name,
Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name,
- Node::Ctor(..) => self.name_by_hir_id(self.get_parent_item(id)),
+ Node::Ctor(..) => self.name(self.get_parent_item(id)),
_ => bug!("no name for {}", self.node_to_string(id))
}
}
format!(" for lifetime parameter `{}` in coherence check", name)
}
infer::UpvarRegion(ref upvar_id, _) => {
- let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
+ let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
format!(" for capture of `{}` by closure", var_name)
}
infer::NLL(..) => bug!("NLL variable found in lexical phase"),
"...so that reference does not outlive borrowed content");
}
infer::ReborrowUpvar(span, ref upvar_id) => {
- let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
+ let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
err.span_note(span,
&format!("...so that closure can access `{}`", var_name));
}
err.span_note(span,
&format!("...so that captured variable `{}` does not outlive the \
enclosing closure",
- self.tcx.hir().name_by_hir_id(id)));
+ self.tcx.hir().name(id)));
}
infer::IndexSlice(span) => {
err.span_note(span, "...so that slice is not indexed outside the lifetime");
err
}
infer::ReborrowUpvar(span, ref upvar_id) => {
- let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id);
+ let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
let mut err = struct_span_err!(self.tcx.sess,
span,
E0313,
E0474,
"captured variable `{}` does not outlive the \
enclosing closure",
- self.tcx.hir().name_by_hir_id(id));
+ self.tcx.hir().name(id));
self.tcx.note_and_explain_region(region_scope_tree, &mut err,
"captured variable is valid for ", sup, "");
self.tcx.note_and_explain_region(region_scope_tree, &mut err,
if let Some(upvars) = tcx.upvars(def_id) {
for (&var_id, place) in upvars.keys().zip(places) {
- let var_name = tcx.hir().name_by_hir_id(var_id);
+ let var_name = tcx.hir().name(var_id);
struct_fmt.field(&var_name.as_str(), place);
}
}
if let Some(upvars) = tcx.upvars(def_id) {
for (&var_id, place) in upvars.keys().zip(places) {
- let var_name = tcx.hir().name_by_hir_id(var_id);
+ let var_name = tcx.hir().name(var_id);
struct_fmt.field(&var_name.as_str(), place);
}
}
p!(
write("{}{}:",
sep,
- self.tcx().hir().name_by_hir_id(var_id)),
+ self.tcx().hir().name(var_id)),
print(upvar_ty));
sep = ", ";
}
p!(
write("{}{}:",
sep,
- self.tcx().hir().name_by_hir_id(var_id)),
+ self.tcx().hir().name(var_id)),
print(upvar_ty));
sep = ", ";
}
impl fmt::Debug for ty::UpvarId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = ty::tls::with(|tcx| {
- tcx.hir().name_by_hir_id(self.var_path.hir_id)
+ tcx.hir().name(self.var_path.hir_id)
});
write!(f, "UpvarId({:?};`{}`;{:?})",
self.var_path.hir_id,
out: &mut String) {
match loan_path.kind {
LpUpvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id: id }, closure_expr_id: _ }) => {
- out.push_str(&self.tcx.hir().name_by_hir_id(id).as_str());
+ out.push_str(&self.tcx.hir().name(id).as_str());
}
LpVar(id) => {
- out.push_str(&self.tcx.hir().name_by_hir_id(id).as_str());
+ out.push_str(&self.tcx.hir().name(id).as_str());
}
LpDowncast(ref lp_base, variant_def_id) => {
format!(
"...but `{}` will be dropped here, when the function `{}` returns",
name,
- self.infcx.tcx.hir().name_by_hir_id(fn_hir_id),
+ self.infcx.tcx.hir().name(fn_hir_id),
),
);
let (&var_id, _) = self.infcx.tcx.upvars(def_id).unwrap()
.get_index(field.index()).unwrap();
- self.infcx.tcx.hir().name_by_hir_id(var_id).to_string()
+ self.infcx.tcx.hir().name(var_id).to_string()
}
_ => {
// Might need a revision when the fields in trait RFC is implemented
ty::UpvarCapture::ByRef(..) => true,
};
let mut upvar = Upvar {
- name: tcx.hir().name_by_hir_id(var_hir_id),
+ name: tcx.hir().name(var_hir_id),
var_hir_id,
by_ref,
mutability: Mutability::Not,
let upvar_hir_id = upvars[upvar_index].var_hir_id;
debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id);
- let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id);
+ let upvar_name = tcx.hir().name(upvar_hir_id);
let upvar_span = tcx.hir().span(upvar_hir_id);
debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}",
upvar_name, upvar_span);
owner: fn_def_id.index,
local_id: *late_bound,
};
- let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str();
+ let name = tcx.hir().name(hir_id).as_interned_str();
let region_def_id = tcx.hir().local_def_id_from_hir_id(hir_id);
let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion {
scope: fn_def_id,
let generics = cx.tcx.generics_of(item_def_id);
let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
let index = generics.param_def_id_to_index[&local_def_id];
- let name = cx.tcx.hir().name_by_hir_id(hir_id).as_interned_str();
+ let name = cx.tcx.hir().name(hir_id).as_interned_str();
let val = ConstValue::Param(ty::ParamConst::new(index, name));
ExprKind::Literal {
literal: cx.tcx.mk_const(
{
let tcx = self.tcx();
let lifetime_name = |def_id| {
- tcx.hir().name_by_hir_id(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str()
+ tcx.hir().name(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str()
};
let r = match tcx.named_region(lifetime.hir_id) {
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id];
- tcx.mk_ty_param(index, tcx.hir().name_by_hir_id(hir_id).as_interned_str())
+ tcx.mk_ty_param(index, tcx.hir().name(hir_id).as_interned_str())
}
Res::SelfTy(Some(_), None) => {
// `Self` in trait or type alias.
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id_from_hir_id(hir_id)];
- let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str();
+ let name = tcx.hir().name(hir_id).as_interned_str();
const_.val = ConstValue::Param(ty::ParamConst::new(index, name));
}
}
fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> ast::Name {
- tcx.hir().name_by_hir_id(var_hir_id)
+ tcx.hir().name(var_hir_id)
}
match parent_node.or(self.mod_ids.last().cloned()) {
Some(parent) if parent != hir::CRATE_HIR_ID => {
// FIXME: can we pull the parent module's name from elsewhere?
- Some(self.cx.tcx.hir().name_by_hir_id(parent).to_string())
+ Some(self.cx.tcx.hir().name(parent).to_string())
}
_ => None,
}