Move methods from Map
to TyCtxt
, part 2.
Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
This commit is contained in:
parent
ce36a966c7
commit
fd7b4bf4e1
108 changed files with 314 additions and 346 deletions
|
@ -484,7 +484,7 @@ fn best_definition_site_of_opaque<'tcx>(
|
|||
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: false, .. } => {
|
||||
let scope = tcx.hir().get_defining_scope(tcx.local_def_id_to_hir_id(opaque_def_id));
|
||||
let found = if scope == hir::CRATE_HIR_ID {
|
||||
tcx.hir().walk_toplevel_module(&mut locator)
|
||||
tcx.hir_walk_toplevel_module(&mut locator)
|
||||
} else {
|
||||
match tcx.hir_node(scope) {
|
||||
Node::Item(it) => locator.visit_item(it),
|
||||
|
|
|
@ -501,7 +501,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
check_method_is_structurally_compatible(tcx, impl_m, trait_m, impl_trait_ref, true)?;
|
||||
|
||||
let impl_m_hir_id = tcx.local_def_id_to_hir_id(impl_m_def_id);
|
||||
let return_span = tcx.hir().fn_decl_by_hir_id(impl_m_hir_id).unwrap().output.span();
|
||||
let return_span = tcx.hir_fn_decl_by_hir_id(impl_m_hir_id).unwrap().output.span();
|
||||
let cause = ObligationCause::new(
|
||||
return_span,
|
||||
impl_m_def_id,
|
||||
|
@ -1033,8 +1033,7 @@ 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_names(body)
|
||||
.zip(sig.decl.inputs.iter())
|
||||
.map(|(param, ty)| param.span.to(ty.span))
|
||||
.next()
|
||||
|
|
|
@ -844,7 +844,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
|
|||
|
||||
fn visit_body(&mut self, body: &hir::Body<'tcx>) {
|
||||
let body_id = body.id();
|
||||
let owner_id = self.tcx.hir().body_owner_def_id(body_id);
|
||||
let owner_id = self.tcx.hir_body_owner_def_id(body_id);
|
||||
|
||||
debug!(
|
||||
"visit_body(id={:?}, span={:?}, body.id={:?}, cx.parent={:?})",
|
||||
|
@ -855,7 +855,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
|
|||
);
|
||||
|
||||
self.enter_body(body.value.hir_id, |this| {
|
||||
if this.tcx.hir().body_owner_kind(owner_id).is_fn_or_closure() {
|
||||
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
|
||||
// The arguments and `self` are parented to the fn.
|
||||
this.cx.var_parent = this.cx.parent.take();
|
||||
for param in body.params {
|
||||
|
@ -924,7 +924,7 @@ pub(crate) fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
|
|||
return tcx.region_scope_tree(typeck_root_def_id);
|
||||
}
|
||||
|
||||
let scope_tree = if let Some(body) = tcx.hir().maybe_body_owned_by(def_id.expect_local()) {
|
||||
let scope_tree = if let Some(body) = tcx.hir_maybe_body_owned_by(def_id.expect_local()) {
|
||||
let mut visitor = ScopeResolutionVisitor {
|
||||
tcx,
|
||||
scope_tree: ScopeTree::default(),
|
||||
|
|
|
@ -1710,7 +1710,7 @@ fn check_sized_if_body<'tcx>(
|
|||
maybe_span: Option<Span>,
|
||||
) {
|
||||
let tcx = wfcx.tcx();
|
||||
if let Some(body) = tcx.hir().maybe_body_owned_by(def_id) {
|
||||
if let Some(body) = tcx.hir_maybe_body_owned_by(def_id) {
|
||||
let span = maybe_span.unwrap_or(body.value.span);
|
||||
|
||||
wfcx.register_bound(
|
||||
|
|
|
@ -13,11 +13,11 @@ pub(crate) fn provide(providers: &mut Providers) {
|
|||
fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
|
||||
let mut used_trait_imports = UnordSet::<LocalDefId>::default();
|
||||
|
||||
// FIXME: Use `tcx.hir().par_body_owners()` when we implement creating `DefId`s
|
||||
// FIXME: Use `tcx.hir_par_body_owners()` when we implement creating `DefId`s
|
||||
// for anon constants during their parents' typeck.
|
||||
// Doing so at current will produce queries cycle errors because it may typeck
|
||||
// on anon constants directly.
|
||||
for item_def_id in tcx.hir().body_owners() {
|
||||
for item_def_id in tcx.hir_body_owners() {
|
||||
let imports = tcx.used_trait_imports(item_def_id);
|
||||
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
|
||||
used_trait_imports.extend_unord(imports.items().copied());
|
||||
|
|
|
@ -113,7 +113,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let items = self.tcx.associated_item_def_ids(impl_def_id);
|
||||
if !self.tcx.hir().rustc_coherence_is_core() {
|
||||
if !self.tcx.hir_rustc_coherence_is_core() {
|
||||
if self.tcx.features().rustc_attrs() {
|
||||
for &impl_item in items {
|
||||
if !self.tcx.has_attr(impl_item, sym::rustc_allow_incoherent_impl) {
|
||||
|
|
|
@ -435,7 +435,7 @@ fn const_evaluatable_predicates_of<'tcx>(
|
|||
self_ty.instantiate_identity().visit_with(&mut collector);
|
||||
}
|
||||
|
||||
if let Some(_) = tcx.hir().fn_sig_by_hir_id(hir_id) {
|
||||
if let Some(_) = tcx.hir_fn_sig_by_hir_id(hir_id) {
|
||||
debug!("visit fn sig");
|
||||
let fn_sig = tcx.fn_sig(def_id);
|
||||
let fn_sig = fn_sig.instantiate_identity();
|
||||
|
@ -825,7 +825,7 @@ pub(super) fn type_param_predicates<'tcx>(
|
|||
// `where T: Foo`.
|
||||
|
||||
let param_id = tcx.local_def_id_to_hir_id(def_id);
|
||||
let param_owner = tcx.hir().ty_param_owner(def_id);
|
||||
let param_owner = tcx.hir_ty_param_owner(def_id);
|
||||
|
||||
// Don't look for bounds where the type parameter isn't in scope.
|
||||
let parent = if item_def_id == param_owner {
|
||||
|
|
|
@ -1340,7 +1340,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||
};
|
||||
def = ResolvedArg::Error(guar);
|
||||
} else if let Some(body_id) = outermost_body {
|
||||
let fn_id = self.tcx.hir().body_owner(body_id);
|
||||
let fn_id = self.tcx.hir_body_owner(body_id);
|
||||
match self.tcx.hir_node(fn_id) {
|
||||
Node::Item(hir::Item { owner_id, kind: hir::ItemKind::Fn { .. }, .. })
|
||||
| Node::TraitItem(hir::TraitItem {
|
||||
|
@ -2265,7 +2265,7 @@ fn is_late_bound_map(
|
|||
tcx: TyCtxt<'_>,
|
||||
owner_id: hir::OwnerId,
|
||||
) -> Option<&FxIndexSet<hir::ItemLocalId>> {
|
||||
let sig = tcx.hir().fn_sig_by_hir_id(owner_id.into())?;
|
||||
let sig = tcx.hir_fn_sig_by_hir_id(owner_id.into())?;
|
||||
let generics = tcx.hir_get_generics(owner_id.def_id)?;
|
||||
|
||||
let mut late_bound = FxIndexSet::default();
|
||||
|
|
|
@ -89,7 +89,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
|
|||
debug!(?scope);
|
||||
|
||||
if scope == hir::CRATE_HIR_ID {
|
||||
tcx.hir().walk_toplevel_module(&mut locator);
|
||||
tcx.hir_walk_toplevel_module(&mut locator);
|
||||
} else {
|
||||
trace!("scope={:#?}", tcx.hir_node(scope));
|
||||
match tcx.hir_node(scope) {
|
||||
|
|
|
@ -70,7 +70,7 @@ fn generic_arg_mismatch_err(
|
|||
}
|
||||
Res::Def(DefKind::TyParam, src_def_id) => {
|
||||
if let Some(param_local_id) = param.def_id.as_local() {
|
||||
let param_name = tcx.hir().ty_param_name(param_local_id);
|
||||
let param_name = tcx.hir_ty_param_name(param_local_id);
|
||||
let param_type = tcx.type_of(param.def_id).instantiate_identity();
|
||||
if param_type.is_suggestable(tcx, false) {
|
||||
err.span_suggestion(
|
||||
|
|
|
@ -217,7 +217,7 @@ impl AssocItemQSelf {
|
|||
fn to_string(&self, tcx: TyCtxt<'_>) -> String {
|
||||
match *self {
|
||||
Self::Trait(def_id) => tcx.def_path_str(def_id),
|
||||
Self::TyParam(def_id, _) => tcx.hir().ty_param_name(def_id).to_string(),
|
||||
Self::TyParam(def_id, _) => tcx.hir_ty_param_name(def_id).to_string(),
|
||||
Self::SelfTyAlias => kw::SelfUpper.to_string(),
|
||||
}
|
||||
}
|
||||
|
@ -342,8 +342,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
}
|
||||
|
||||
rbv::ResolvedArg::EarlyBound(def_id) => {
|
||||
let name = tcx.hir().ty_param_name(def_id);
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id);
|
||||
let name = tcx.hir_ty_param_name(def_id);
|
||||
let item_def_id = tcx.hir_ty_param_owner(def_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
||||
ty::Region::new_early_param(tcx, ty::EarlyParamRegion { index, name })
|
||||
|
@ -2070,10 +2070,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
Ty::new_bound(tcx, debruijn, br)
|
||||
}
|
||||
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id);
|
||||
let item_def_id = tcx.hir_ty_param_owner(def_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
||||
Ty::new_param(tcx, index, tcx.hir().ty_param_name(def_id))
|
||||
Ty::new_param(tcx, index, tcx.hir_ty_param_name(def_id))
|
||||
}
|
||||
Some(rbv::ResolvedArg::Error(guar)) => Ty::new_error(tcx, guar),
|
||||
arg => bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"),
|
||||
|
|
|
@ -22,8 +22,6 @@ fn diagnostic_hir_wf_check<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
(predicate, loc): (ty::Predicate<'tcx>, WellFormedLoc),
|
||||
) -> Option<ObligationCause<'tcx>> {
|
||||
let hir = tcx.hir();
|
||||
|
||||
let def_id = match loc {
|
||||
WellFormedLoc::Ty(def_id) => def_id,
|
||||
WellFormedLoc::Param { function, param_idx: _ } => function,
|
||||
|
@ -187,7 +185,7 @@ fn diagnostic_hir_wf_check<'tcx>(
|
|||
ref node => bug!("Unexpected node {:?}", node),
|
||||
},
|
||||
WellFormedLoc::Param { function: _, param_idx } => {
|
||||
let fn_decl = hir.fn_decl_by_hir_id(hir_id).unwrap();
|
||||
let fn_decl = tcx.hir_fn_decl_by_hir_id(hir_id).unwrap();
|
||||
// Get return type
|
||||
if param_idx as usize == fn_decl.inputs.len() {
|
||||
match fn_decl.output {
|
||||
|
|
|
@ -183,7 +183,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
// what we are intending to discard, to help future type-based refactoring.
|
||||
type R = Result<(), ErrorGuaranteed>;
|
||||
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
tcx.par_hir_for_each_module(|module| {
|
||||
let _: R = tcx.ensure_ok().check_mod_type_wf(module);
|
||||
});
|
||||
|
||||
|
@ -208,7 +208,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
|
||||
// Make sure we evaluate all static and (non-associated) const items, even if unused.
|
||||
// If any of these fail to evaluate, we do not want this crate to pass compilation.
|
||||
tcx.hir().par_body_owners(|item_def_id| {
|
||||
tcx.par_hir_body_owners(|item_def_id| {
|
||||
let def_kind = tcx.def_kind(item_def_id);
|
||||
match def_kind {
|
||||
DefKind::Static { .. } => tcx.ensure_ok().eval_static_initializer(item_def_id),
|
||||
|
@ -226,7 +226,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
// for anon constants during their parents' typeck.
|
||||
// Typeck all body owners in parallel will produce queries
|
||||
// cycle errors because it may typeck on anon constants directly.
|
||||
tcx.hir().par_body_owners(|item_def_id| {
|
||||
tcx.par_hir_body_owners(|item_def_id| {
|
||||
let def_kind = tcx.def_kind(item_def_id);
|
||||
if !matches!(def_kind, DefKind::AnonConst) {
|
||||
tcx.ensure_ok().typeck(item_def_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue