Rollup merge of #122513 - petrochenkov:somehir4, r=fmease
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` Also replace a few `hir_node()` calls with `hir_node_by_def_id()`. Follow up to https://github.com/rust-lang/rust/pull/120943.
This commit is contained in:
commit
3d4464d4d7
37 changed files with 135 additions and 199 deletions
|
@ -2126,8 +2126,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
let TypeError::FixedArraySize(sz) = terr else {
|
||||
return None;
|
||||
};
|
||||
let tykind = match self.tcx.opt_hir_node_by_def_id(trace.cause.body_id) {
|
||||
Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })) => {
|
||||
let tykind = match self.tcx.hir_node_by_def_id(trace.cause.body_id) {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) => {
|
||||
let body = hir.body(*body_id);
|
||||
struct LetVisitor {
|
||||
span: Span,
|
||||
|
@ -2156,7 +2156,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
LetVisitor { span }.visit_body(body).break_value()
|
||||
}
|
||||
Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. })) => {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. }) => {
|
||||
Some(&ty.peel_refs().kind)
|
||||
}
|
||||
_ => None,
|
||||
|
@ -2527,15 +2527,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
.filter(|p| matches!(p.kind, ty::GenericParamDefKind::Lifetime))
|
||||
.map(|p| p.name)
|
||||
.collect::<Vec<_>>();
|
||||
if let Some(hir_id) = self.tcx.opt_local_def_id_to_hir_id(lifetime_scope) {
|
||||
// consider late-bound lifetimes ...
|
||||
used_names.extend(self.tcx.late_bound_vars(hir_id).into_iter().filter_map(|p| {
|
||||
match p {
|
||||
ty::BoundVariableKind::Region(lt) => lt.get_name(),
|
||||
_ => None,
|
||||
}
|
||||
}))
|
||||
}
|
||||
let hir_id = self.tcx.local_def_id_to_hir_id(lifetime_scope);
|
||||
// consider late-bound lifetimes ...
|
||||
used_names.extend(self.tcx.late_bound_vars(hir_id).into_iter().filter_map(
|
||||
|p| match p {
|
||||
ty::BoundVariableKind::Region(lt) => lt.get_name(),
|
||||
_ => None,
|
||||
},
|
||||
));
|
||||
(b'a'..=b'z')
|
||||
.map(|c| format!("'{}", c as char))
|
||||
.find(|candidate| !used_names.iter().any(|e| e.as_str() == candidate))
|
||||
|
|
|
@ -459,7 +459,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
tcx.hir().trait_impls(trait_did).iter().find_map(|&impl_did| {
|
||||
if let Node::Item(Item {
|
||||
kind: ItemKind::Impl(hir::Impl { self_ty, .. }), ..
|
||||
}) = tcx.opt_hir_node_by_def_id(impl_did)?
|
||||
}) = tcx.hir_node_by_def_id(impl_did)
|
||||
&& trait_objects.iter().all(|did| {
|
||||
// FIXME: we should check `self_ty` against the receiver
|
||||
// type in the `UnifyReceiver` context, but for now, use
|
||||
|
|
|
@ -804,23 +804,22 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
) -> bool {
|
||||
let tcx = self.tcx;
|
||||
|
||||
let Some(hir_id) = body_owner_def_id.as_local() else {
|
||||
return false;
|
||||
};
|
||||
let Some(hir_id) = tcx.opt_local_def_id_to_hir_id(hir_id) else {
|
||||
let Some(def_id) = body_owner_def_id.as_local() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// When `body_owner` is an `impl` or `trait` item, look in its associated types for
|
||||
// `expected` and point at it.
|
||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||
let parent_id = tcx.hir().get_parent_item(hir_id);
|
||||
let item = tcx.opt_hir_node_by_def_id(parent_id.def_id);
|
||||
let item = tcx.hir_node_by_def_id(parent_id.def_id);
|
||||
|
||||
debug!("expected_projection parent item {:?}", item);
|
||||
|
||||
let param_env = tcx.param_env(body_owner_def_id);
|
||||
|
||||
match item {
|
||||
Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Trait(.., items), .. })) => {
|
||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Trait(.., items), .. }) => {
|
||||
// FIXME: account for `#![feature(specialization)]`
|
||||
for item in &items[..] {
|
||||
match item.kind {
|
||||
|
@ -845,10 +844,10 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
}
|
||||
}
|
||||
}
|
||||
Some(hir::Node::Item(hir::Item {
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Impl(hir::Impl { items, .. }),
|
||||
..
|
||||
})) => {
|
||||
}) => {
|
||||
for item in &items[..] {
|
||||
if let hir::AssocItemKind::Type = item.kind {
|
||||
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue