Simplify bound var resolution.
This commit is contained in:
parent
c7cb45a791
commit
6ec58a44e2
4 changed files with 39 additions and 44 deletions
|
@ -1,9 +1,9 @@
|
|||
//! Name resolution for lifetimes and late-bound type and const variables: type declarations.
|
||||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::ItemLocalId;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::{ItemLocalId, OwnerId};
|
||||
use rustc_macros::{Decodable, Encodable, HashStable, TyDecodable, TyEncodable};
|
||||
|
||||
use crate::ty;
|
||||
|
@ -47,11 +47,11 @@ pub enum ObjectLifetimeDefault {
|
|||
|
||||
/// Maps the id of each lifetime reference to the lifetime decl
|
||||
/// that it corresponds to.
|
||||
#[derive(Default, HashStable, Debug)]
|
||||
#[derive(HashStable, Debug)]
|
||||
pub struct ResolveBoundVars {
|
||||
/// Maps from every use of a named (not anonymous) lifetime to a
|
||||
/// `Region` describing how that region is bound
|
||||
pub defs: FxIndexMap<OwnerId, FxIndexMap<ItemLocalId, ResolvedArg>>,
|
||||
pub defs: SortedMap<ItemLocalId, ResolvedArg>,
|
||||
|
||||
pub late_bound_vars: FxIndexMap<OwnerId, FxIndexMap<ItemLocalId, Vec<ty::BoundVariableKind>>>,
|
||||
pub late_bound_vars: SortedMap<ItemLocalId, Vec<ty::BoundVariableKind>>,
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use rustc_ast::expand::StrippedCfgItem;
|
|||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
|
@ -1742,8 +1743,7 @@ rustc_queries! {
|
|||
arena_cache
|
||||
desc { |tcx| "resolving lifetimes for `{}`", tcx.def_path_str(owner_id) }
|
||||
}
|
||||
query named_variable_map(owner_id: hir::OwnerId) ->
|
||||
Option<&'tcx FxIndexMap<ItemLocalId, ResolvedArg>> {
|
||||
query named_variable_map(owner_id: hir::OwnerId) -> &'tcx SortedMap<ItemLocalId, ResolvedArg> {
|
||||
desc { |tcx| "looking up a named region inside `{}`", tcx.def_path_str(owner_id) }
|
||||
}
|
||||
query is_late_bound_map(owner_id: hir::OwnerId) -> Option<&'tcx FxIndexSet<ItemLocalId>> {
|
||||
|
@ -1759,7 +1759,7 @@ rustc_queries! {
|
|||
separate_provide_extern
|
||||
}
|
||||
query late_bound_vars_map(owner_id: hir::OwnerId)
|
||||
-> Option<&'tcx FxIndexMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
|
||||
-> &'tcx SortedMap<ItemLocalId, Vec<ty::BoundVariableKind>> {
|
||||
desc { |tcx| "looking up late bound vars inside `{}`", tcx.def_path_str(owner_id) }
|
||||
}
|
||||
|
||||
|
|
|
@ -2996,7 +2996,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
pub fn named_bound_var(self, id: HirId) -> Option<resolve_bound_vars::ResolvedArg> {
|
||||
debug!(?id, "named_region");
|
||||
self.named_variable_map(id.owner).and_then(|map| map.get(&id.local_id).cloned())
|
||||
self.named_variable_map(id.owner).get(&id.local_id).cloned()
|
||||
}
|
||||
|
||||
pub fn is_late_bound(self, id: HirId) -> bool {
|
||||
|
@ -3005,12 +3005,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
|
||||
self.mk_bound_variable_kinds(
|
||||
&self
|
||||
.late_bound_vars_map(id.owner)
|
||||
.and_then(|map| map.get(&id.local_id).cloned())
|
||||
.unwrap_or_else(|| {
|
||||
bug!("No bound vars found for {}", self.hir().node_to_string(id))
|
||||
}),
|
||||
&self.late_bound_vars_map(id.owner).get(&id.local_id).cloned().unwrap_or_else(|| {
|
||||
bug!("No bound vars found for {}", self.hir().node_to_string(id))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue