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
|
@ -386,8 +386,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
hir::intravisit::walk_pat(self, p);
|
||||
}
|
||||
}
|
||||
let tcx = self.infcx.tcx;
|
||||
let hir = self.infcx.tcx.hir();
|
||||
if let Some(body) = hir.maybe_body_owned_by(self.mir_def_id()) {
|
||||
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
|
||||
let expr = body.value;
|
||||
let place = &self.move_data.move_paths[mpi].place;
|
||||
let span = place.as_local().map(|local| self.body.local_decls[local].source_info.span);
|
||||
|
@ -396,7 +397,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
expr: None,
|
||||
pat: None,
|
||||
parent_pat: None,
|
||||
tcx: self.infcx.tcx,
|
||||
tcx,
|
||||
};
|
||||
finder.visit_expr(expr);
|
||||
if let Some(span) = span
|
||||
|
@ -782,9 +783,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
|
||||
// We use the statements were the binding was initialized, and inspect the HIR to look
|
||||
// for the branching codepaths that aren't covered, to point at them.
|
||||
let map = self.infcx.tcx.hir();
|
||||
let body = map.body_owned_by(self.mir_def_id());
|
||||
let mut visitor = ConditionVisitor { tcx: self.infcx.tcx, spans, name, errors: vec![] };
|
||||
let tcx = self.infcx.tcx;
|
||||
let body = tcx.hir_body_owned_by(self.mir_def_id());
|
||||
let mut visitor = ConditionVisitor { tcx, spans, name, errors: vec![] };
|
||||
visitor.visit_body(&body);
|
||||
let spans = visitor.spans;
|
||||
|
||||
|
@ -2443,7 +2444,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
) {
|
||||
let &UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
|
||||
let tcx = self.infcx.tcx;
|
||||
let hir = tcx.hir();
|
||||
|
||||
// Get the type of the local that we are trying to borrow
|
||||
let local = borrowed_place.local;
|
||||
|
@ -2522,7 +2522,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
|
||||
// Find the first argument with a matching type, get its name
|
||||
let Some((_, this_name)) =
|
||||
params.iter().zip(hir.body_param_names(closure.body)).find(|(param_ty, name)| {
|
||||
params.iter().zip(tcx.hir_body_param_names(closure.body)).find(|(param_ty, name)| {
|
||||
// FIXME: also support deref for stuff like `Rc` arguments
|
||||
param_ty.peel_refs() == local_ty && name != &Ident::empty()
|
||||
})
|
||||
|
@ -4178,7 +4178,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
|
||||
let is_closure = self.infcx.tcx.is_closure_like(did.to_def_id());
|
||||
let fn_hir_id = self.infcx.tcx.local_def_id_to_hir_id(did);
|
||||
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
|
||||
let fn_decl = self.infcx.tcx.hir_fn_decl_by_hir_id(fn_hir_id)?;
|
||||
|
||||
// We need to work out which arguments to highlight. We do this by looking
|
||||
// at the return type, where there are three cases:
|
||||
|
|
|
@ -777,12 +777,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
}
|
||||
let Some(pat_span) = pat_span else { return };
|
||||
|
||||
let hir = self.infcx.tcx.hir();
|
||||
let Some(body) = hir.maybe_body_owned_by(self.mir_def_id()) else { return };
|
||||
let tcx = self.infcx.tcx;
|
||||
let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) else { return };
|
||||
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
|
||||
let mut finder = BindingFinder {
|
||||
typeck_results,
|
||||
tcx: self.infcx.tcx,
|
||||
tcx,
|
||||
pat_span,
|
||||
binding_spans,
|
||||
found_pat: false,
|
||||
|
|
|
@ -648,10 +648,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let hir_map = self.infcx.tcx.hir();
|
||||
let def_id = self.body.source.def_id();
|
||||
let Some(local_def_id) = def_id.as_local() else { return };
|
||||
let Some(body) = hir_map.maybe_body_owned_by(local_def_id) else { return };
|
||||
let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id) else { return };
|
||||
|
||||
let mut v = SuggestIndexOperatorAlternativeVisitor {
|
||||
assign_span: span,
|
||||
|
@ -749,7 +748,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
// `fn foo(&x: &i32)` -> `fn foo(&(mut x): &i32)`
|
||||
let def_id = self.body.source.def_id();
|
||||
if let Some(local_def_id) = def_id.as_local()
|
||||
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
|
||||
&& let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id)
|
||||
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(&body).break_value()
|
||||
&& let node = self.infcx.tcx.hir_node(hir_id)
|
||||
&& let hir::Node::LetStmt(hir::LetStmt {
|
||||
|
@ -856,7 +855,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
use hir::ExprKind::{AddrOf, Block, Call, MethodCall};
|
||||
use hir::{BorrowKind, Expr};
|
||||
|
||||
let hir_map = self.infcx.tcx.hir();
|
||||
let tcx = self.infcx.tcx;
|
||||
struct Finder {
|
||||
span: Span,
|
||||
}
|
||||
|
@ -871,7 +870,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
if let Some(body) = hir_map.maybe_body_owned_by(self.mir_def_id())
|
||||
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id())
|
||||
&& let Block(block, _) = body.value.kind
|
||||
{
|
||||
// `span` corresponds to the expression being iterated, find the `for`-loop desugared
|
||||
|
@ -884,17 +883,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
MethodCall(path_segment, _, _, span) => {
|
||||
// We have `for _ in iter.read_only_iter()`, try to
|
||||
// suggest `for _ in iter.mutable_iter()` instead.
|
||||
let opt_suggestions = self
|
||||
.infcx
|
||||
.tcx
|
||||
let opt_suggestions = tcx
|
||||
.typeck(path_segment.hir_id.owner.def_id)
|
||||
.type_dependent_def_id(expr.hir_id)
|
||||
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
|
||||
.map(|def_id| self.infcx.tcx.associated_items(def_id))
|
||||
.and_then(|def_id| tcx.impl_of_method(def_id))
|
||||
.map(|def_id| tcx.associated_items(def_id))
|
||||
.map(|assoc_items| {
|
||||
assoc_items
|
||||
.in_definition_order()
|
||||
.map(|assoc_item_def| assoc_item_def.ident(self.infcx.tcx))
|
||||
.map(|assoc_item_def| assoc_item_def.ident(tcx))
|
||||
.filter(|&ident| {
|
||||
let original_method_ident = path_segment.ident;
|
||||
original_method_ident != ident
|
||||
|
@ -942,7 +939,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
let closure_span = tcx.def_span(self.mir_def_id());
|
||||
let fn_call_id = tcx.parent_hir_id(closure_id);
|
||||
let node = tcx.hir_node(fn_call_id);
|
||||
let def_id = hir.enclosing_body_owner(fn_call_id);
|
||||
let def_id = tcx.hir_enclosing_body_owner(fn_call_id);
|
||||
let mut look_at_return = true;
|
||||
|
||||
// If the HIR node is a function or method call gets the def ID
|
||||
|
@ -1275,7 +1272,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
}) => {
|
||||
let def_id = self.body.source.def_id();
|
||||
let hir_id = if let Some(local_def_id) = def_id.as_local()
|
||||
&& let Some(body) = self.infcx.tcx.hir().maybe_body_owned_by(local_def_id)
|
||||
&& let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(local_def_id)
|
||||
{
|
||||
BindingFinder { span: err_label_span }.visit_body(&body).break_value()
|
||||
} else {
|
||||
|
|
|
@ -1169,8 +1169,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diag<'_>) {
|
||||
let map = self.infcx.tcx.hir();
|
||||
let body = map.body_owned_by(self.mir_def_id());
|
||||
let body = self.infcx.tcx.hir_body_owned_by(self.mir_def_id());
|
||||
let expr = &body.value.peel_blocks();
|
||||
let mut closure_span = None::<rustc_span::Span>;
|
||||
match expr.kind {
|
||||
|
|
|
@ -424,7 +424,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
|||
&self,
|
||||
argument_index: usize,
|
||||
) -> Option<&hir::Ty<'tcx>> {
|
||||
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(self.mir_hir_id())?;
|
||||
let fn_decl = self.infcx.tcx.hir_fn_decl_by_hir_id(self.mir_hir_id())?;
|
||||
let argument_hir_ty: &hir::Ty<'_> = fn_decl.inputs.get(argument_index)?;
|
||||
match argument_hir_ty.kind {
|
||||
// This indicates a variable with no type annotation, like
|
||||
|
|
|
@ -188,7 +188,7 @@ fn do_mir_borrowck<'tcx>(
|
|||
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
|
||||
.into_results_cursor(body);
|
||||
|
||||
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(def).is_fn_or_closure();
|
||||
let locals_are_invalidated_at_exit = tcx.hir_body_owner_kind(def).is_fn_or_closure();
|
||||
let borrow_set = BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &move_data);
|
||||
|
||||
// Compute non-lexical lifetimes.
|
||||
|
|
|
@ -576,7 +576,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
let tcx = self.infcx.tcx;
|
||||
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id());
|
||||
|
||||
match tcx.hir().body_owner_kind(self.mir_def) {
|
||||
match tcx.hir_body_owner_kind(self.mir_def) {
|
||||
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
|
||||
let defining_ty = tcx.type_of(self.mir_def).instantiate_identity();
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
|
|||
|
||||
pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
|
||||
let omit_gdb_pretty_printer_section =
|
||||
attr::contains_name(cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section);
|
||||
attr::contains_name(cx.tcx.hir_krate_attrs(), sym::omit_gdb_pretty_printer_section);
|
||||
|
||||
// To ensure the section `__rustc_debug_gdb_scripts_section__` will not create
|
||||
// ODR violations at link time, this section will not be emitted for rlibs since
|
||||
|
|
|
@ -31,7 +31,7 @@ pub struct ConstCx<'mir, 'tcx> {
|
|||
impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Self {
|
||||
let typing_env = body.typing_env(tcx);
|
||||
let const_kind = tcx.hir().body_const_context(body.source.def_id().expect_local());
|
||||
let const_kind = tcx.hir_body_const_context(body.source.def_id().expect_local());
|
||||
ConstCx { body, tcx, typing_env, const_kind }
|
||||
}
|
||||
|
||||
|
|
|
@ -164,8 +164,7 @@ impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> {
|
|||
if let pprust_hir::AnnNode::Expr(expr) = node {
|
||||
let typeck_results = self.maybe_typeck_results.get().or_else(|| {
|
||||
self.tcx
|
||||
.hir()
|
||||
.maybe_body_owned_by(expr.hir_id.owner.def_id)
|
||||
.hir_maybe_body_owned_by(expr.hir_id.owner.def_id)
|
||||
.map(|body_id| self.tcx.typeck_body(body_id.id()))
|
||||
});
|
||||
|
||||
|
@ -317,7 +316,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
|||
rustc_hir_analysis::check_crate(tcx);
|
||||
tcx.dcx().abort_if_errors();
|
||||
debug!("pretty printing THIR tree");
|
||||
for did in tcx.hir().body_owners() {
|
||||
for did in tcx.hir_body_owners() {
|
||||
let _ = writeln!(out, "{:?}:\n{}\n", did, thir_tree(tcx, did));
|
||||
}
|
||||
out
|
||||
|
@ -328,7 +327,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
|||
rustc_hir_analysis::check_crate(tcx);
|
||||
tcx.dcx().abort_if_errors();
|
||||
debug!("pretty printing THIR flat");
|
||||
for did in tcx.hir().body_owners() {
|
||||
for did in tcx.hir_body_owners() {
|
||||
let _ = writeln!(out, "{:?}:\n{}\n", did, thir_flat(tcx, did));
|
||||
}
|
||||
out
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
//! - Example: Examine each expression to look for its type and do some check or other.
|
||||
//! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
|
||||
//! `nested_filter::OnlyBodies` (and implement `maybe_tcx`), and use
|
||||
//! `tcx.hir().visit_all_item_likes_in_crate(&mut visitor)`. Within your
|
||||
//! `tcx.hir_visit_all_item_likes_in_crate(&mut visitor)`. Within your
|
||||
//! `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke
|
||||
//! `intravisit::walk_expr()` to keep walking the subparts).
|
||||
//! - Pro: Visitor methods for any kind of HIR node, not just item-like things.
|
||||
|
@ -31,7 +31,7 @@
|
|||
//! impl into scope while visiting the impl-items, and then back out again.
|
||||
//! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
|
||||
//! `nested_filter::All` (and implement `maybe_tcx`). Walk your crate with
|
||||
//! `tcx.hir().walk_toplevel_module(visitor)` invoked on `tcx.hir().krate()`.
|
||||
//! `tcx.hir_walk_toplevel_module(visitor)`.
|
||||
//! - Pro: Visitor methods for any kind of HIR node, not just item-like things.
|
||||
//! - Pro: Preserves nesting information
|
||||
//! - Con: Does not integrate well into dependency tracking.
|
||||
|
@ -193,7 +193,7 @@ use nested_filter::NestedFilter;
|
|||
/// (this is why the module is called `intravisit`, to distinguish it
|
||||
/// from the AST's `visit` module, which acts differently). If you
|
||||
/// simply want to visit all items in the crate in some order, you
|
||||
/// should call `tcx.hir().visit_all_item_likes_in_crate`. Otherwise, see the comment
|
||||
/// should call `tcx.hir_visit_all_item_likes_in_crate`. Otherwise, see the comment
|
||||
/// on `visit_nested_item` for details on how to visit nested items.
|
||||
///
|
||||
/// If you want to ensure that your code handles every variant
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -213,10 +213,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
arm_ty: Ty<'tcx>,
|
||||
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
|
||||
) {
|
||||
let hir = self.tcx.hir();
|
||||
|
||||
// First, check that we're actually in the tail of a function.
|
||||
let Some(body) = hir.maybe_body_owned_by(self.body_id) else {
|
||||
let Some(body) = self.tcx.hir_maybe_body_owned_by(self.body_id) else {
|
||||
return;
|
||||
};
|
||||
let hir::ExprKind::Block(block, _) = body.value.kind else {
|
||||
|
|
|
@ -860,7 +860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
let host = match self.tcx.hir().body_const_context(self.body_id) {
|
||||
let host = match self.tcx.hir_body_const_context(self.body_id) {
|
||||
Some(hir::ConstContext::Const { .. } | hir::ConstContext::Static(_)) => {
|
||||
ty::BoundConstness::Const
|
||||
}
|
||||
|
|
|
@ -35,12 +35,8 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||
params_can_be_unsized: bool,
|
||||
) -> Option<CoroutineTypes<'tcx>> {
|
||||
let fn_id = fcx.tcx.local_def_id_to_hir_id(fn_def_id);
|
||||
|
||||
let tcx = fcx.tcx;
|
||||
let hir = tcx.hir();
|
||||
|
||||
let declared_ret_ty = fn_sig.output();
|
||||
|
||||
let ret_ty =
|
||||
fcx.register_infer_ok_obligations(fcx.infcx.replace_opaque_types_with_inference_vars(
|
||||
declared_ret_ty,
|
||||
|
@ -69,7 +65,7 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||
});
|
||||
|
||||
// Add formal parameters.
|
||||
let inputs_hir = hir.fn_decl_by_hir_id(fn_id).map(|decl| &decl.inputs);
|
||||
let inputs_hir = tcx.hir_fn_decl_by_hir_id(fn_id).map(|decl| &decl.inputs);
|
||||
let inputs_fn = fn_sig.inputs().iter().copied();
|
||||
for (idx, (param_ty, param)) in inputs_fn.chain(maybe_va_list).zip(body.params).enumerate() {
|
||||
// We checked the root's signature during wfcheck, but not the child.
|
||||
|
|
|
@ -1943,7 +1943,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||
if due_to_block
|
||||
&& let Some(expr) = expression
|
||||
&& let Some(parent_fn_decl) =
|
||||
fcx.tcx.hir().fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
|
||||
fcx.tcx.hir_fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
|
||||
{
|
||||
fcx.suggest_missing_break_or_return_expr(
|
||||
&mut err,
|
||||
|
|
|
@ -293,8 +293,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
expr: &hir::Expr<'_>,
|
||||
source: TypeMismatchSource<'tcx>,
|
||||
) -> bool {
|
||||
let hir = self.tcx.hir();
|
||||
|
||||
let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind else {
|
||||
return false;
|
||||
};
|
||||
|
@ -334,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
let mut expr_finder = FindExprs { hir_id: local_hir_id, uses: init.into_iter().collect() };
|
||||
let body = hir.body_owned_by(self.body_id);
|
||||
let body = self.tcx.hir_body_owned_by(self.body_id);
|
||||
expr_finder.visit_expr(body.value);
|
||||
|
||||
// Replaces all of the variables in the given type with a fresh inference variable.
|
||||
|
|
|
@ -1150,13 +1150,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// We are inside a function body, so reporting "return statement
|
||||
// outside of function body" needs an explanation.
|
||||
|
||||
let encl_body_owner_id = self.tcx.hir().enclosing_body_owner(expr.hir_id);
|
||||
let encl_body_owner_id = self.tcx.hir_enclosing_body_owner(expr.hir_id);
|
||||
|
||||
// If this didn't hold, we would not have to report an error in
|
||||
// the first place.
|
||||
assert_ne!(encl_item_id.def_id, encl_body_owner_id);
|
||||
|
||||
let encl_body = self.tcx.hir().body_owned_by(encl_body_owner_id);
|
||||
let encl_body = self.tcx.hir_body_owned_by(encl_body_owner_id);
|
||||
|
||||
err.encl_body_span = Some(encl_body.value.span);
|
||||
err.encl_fn_span = Some(*encl_fn_span);
|
||||
|
@ -3229,7 +3229,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
None => return,
|
||||
};
|
||||
let param_span = self.tcx.hir().span(param_hir_id);
|
||||
let param_name = self.tcx.hir().ty_param_name(param_def_id.expect_local());
|
||||
let param_name = self.tcx.hir_ty_param_name(param_def_id.expect_local());
|
||||
|
||||
err.span_label(param_span, format!("type parameter '{param_name}' declared here"));
|
||||
}
|
||||
|
|
|
@ -1001,11 +1001,12 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
|
|||
let closure_def_id = closure_expr.def_id;
|
||||
// For purposes of this function, coroutine and closures are equivalent.
|
||||
let body_owner_is_closure = matches!(
|
||||
tcx.hir().body_owner_kind(self.cx.body_owner_def_id()),
|
||||
tcx.hir_body_owner_kind(self.cx.body_owner_def_id()),
|
||||
hir::BodyOwnerKind::Closure
|
||||
);
|
||||
|
||||
// If we have a nested closure, we want to include the fake reads present in the nested closure.
|
||||
// If we have a nested closure, we want to include the fake reads present in the nested
|
||||
// closure.
|
||||
if let Some(fake_reads) = self.cx.typeck_results().closure_fake_reads.get(&closure_def_id) {
|
||||
for (fake_read, cause, hir_id) in fake_reads.iter() {
|
||||
match fake_read.base {
|
||||
|
|
|
@ -573,7 +573,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
|||
coercions: &VecGraph<ty::TyVid, true>,
|
||||
) -> errors::SuggestAnnotations {
|
||||
let body =
|
||||
self.tcx.hir().maybe_body_owned_by(self.body_id).expect("body id must have an owner");
|
||||
self.tcx.hir_maybe_body_owned_by(self.body_id).expect("body id must have an owner");
|
||||
// For each diverging var, look through the HIR for a place to give it
|
||||
// a type annotation. We do this per var because we only really need one
|
||||
// suggestion to influence a var to be `()`.
|
||||
|
@ -764,7 +764,7 @@ fn compute_unsafe_infer_vars<'a, 'tcx>(
|
|||
fcx: &'a FnCtxt<'a, 'tcx>,
|
||||
body_id: LocalDefId,
|
||||
) -> UnordMap<ty::TyVid, (HirId, Span, UnsafeUseReason)> {
|
||||
let body = fcx.tcx.hir().maybe_body_owned_by(body_id).expect("body id must have an owner");
|
||||
let body = fcx.tcx.hir_maybe_body_owned_by(body_id).expect("body id must have an owner");
|
||||
let mut res = UnordMap::default();
|
||||
|
||||
struct UnsafeInferVarsVisitor<'a, 'tcx> {
|
||||
|
|
|
@ -100,7 +100,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let mut deferred_asm_checks = self.deferred_asm_checks.borrow_mut();
|
||||
debug!("FnCtxt::check_asm: {} deferred checks", deferred_asm_checks.len());
|
||||
for (asm, hir_id) in deferred_asm_checks.drain(..) {
|
||||
let enclosing_id = self.tcx.hir().enclosing_body_owner(hir_id);
|
||||
let enclosing_id = self.tcx.hir_enclosing_body_owner(hir_id);
|
||||
let get_operand_ty = |expr| {
|
||||
let ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
|
||||
let ty = self.resolve_vars_if_possible(ty);
|
||||
|
|
|
@ -290,7 +290,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
|
|||
_: Ident,
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
let tcx = self.tcx;
|
||||
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()];
|
||||
// HACK(eddyb) should get the original `Span`.
|
||||
|
|
|
@ -1811,7 +1811,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
"`{expected_ty}` does not implement `Clone`, so `{found_ty}` was cloned instead"
|
||||
),
|
||||
);
|
||||
let owner = self.tcx.hir().enclosing_body_owner(expr.hir_id);
|
||||
let owner = self.tcx.hir_enclosing_body_owner(expr.hir_id);
|
||||
if let ty::Param(param) = expected_ty.kind()
|
||||
&& let Some(generics) = self.tcx.hir_get_generics(owner)
|
||||
{
|
||||
|
@ -2094,9 +2094,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
expr: &hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
) -> bool {
|
||||
let hir = self.tcx.hir();
|
||||
let tcx = self.tcx;
|
||||
let hir = tcx.hir();
|
||||
let enclosing_scope =
|
||||
hir.get_enclosing_scope(expr.hir_id).map(|hir_id| self.tcx.hir_node(hir_id));
|
||||
hir.get_enclosing_scope(expr.hir_id).map(|hir_id| tcx.hir_node(hir_id));
|
||||
|
||||
// Get tail expr of the enclosing block or body
|
||||
let tail_expr = if let Some(Node::Block(hir::Block { expr, .. })) = enclosing_scope
|
||||
|
@ -2104,8 +2105,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
{
|
||||
*expr
|
||||
} else {
|
||||
let body_def_id = hir.enclosing_body_owner(expr.hir_id);
|
||||
let body = hir.body_owned_by(body_def_id);
|
||||
let body_def_id = tcx.hir_enclosing_body_owner(expr.hir_id);
|
||||
let body = tcx.hir_body_owned_by(body_def_id);
|
||||
|
||||
// Get tail expr of the body
|
||||
match body.value.kind {
|
||||
|
@ -2147,7 +2148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
("consider returning a value here", format!("`{expected}` value"))
|
||||
};
|
||||
|
||||
let src_map = self.tcx.sess.source_map();
|
||||
let src_map = tcx.sess.source_map();
|
||||
let suggestion = if src_map.is_multiline(expr.span) {
|
||||
let indentation = src_map.indentation_before(span).unwrap_or_else(String::new);
|
||||
format!("\n{indentation}/* {suggestion} */")
|
||||
|
|
|
@ -531,7 +531,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
&& let hir::def::Res::Local(recv_id) = path.res
|
||||
&& let Some(segment) = path.segments.first()
|
||||
{
|
||||
let body = self.tcx.hir().body_owned_by(self.body_id);
|
||||
let body = self.tcx.hir_body_owned_by(self.body_id);
|
||||
|
||||
if let Node::Expr(call_expr) = self.tcx.parent_hir_node(rcvr.hir_id) {
|
||||
let mut let_visitor = LetVisitor {
|
||||
|
@ -2599,7 +2599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
seg1.ident.span,
|
||||
StashKey::CallAssocMethod,
|
||||
|err| {
|
||||
let body = self.tcx.hir().body_owned_by(self.body_id);
|
||||
let body = self.tcx.hir_body_owned_by(self.body_id);
|
||||
struct LetVisitor {
|
||||
ident_name: Symbol,
|
||||
}
|
||||
|
@ -3336,7 +3336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let accessible_sugg = sugg(accessible_candidates, true);
|
||||
let inaccessible_sugg = sugg(inaccessible_candidates, false);
|
||||
|
||||
let (module, _, _) = self.tcx.hir().get_module(scope);
|
||||
let (module, _, _) = self.tcx.hir_get_module(scope);
|
||||
let span = module.spans.inject_use_span;
|
||||
handle_candidates(accessible_sugg, inaccessible_sugg, span);
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let args = self.resolve_vars_if_possible(args);
|
||||
let closure_def_id = closure_def_id.expect_local();
|
||||
|
||||
assert_eq!(self.tcx.hir().body_owner_def_id(body.id()), closure_def_id);
|
||||
assert_eq!(self.tcx.hir_body_owner_def_id(body.id()), closure_def_id);
|
||||
let mut delegate = InferBorrowKind {
|
||||
closure_def_id,
|
||||
capture_information: Default::default(),
|
||||
|
|
|
@ -38,7 +38,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
&self,
|
||||
body: &'tcx hir::Body<'tcx>,
|
||||
) -> &'tcx ty::TypeckResults<'tcx> {
|
||||
let item_def_id = self.tcx.hir().body_owner_def_id(body.id());
|
||||
let item_def_id = self.tcx.hir_body_owner_def_id(body.id());
|
||||
|
||||
// This attribute causes us to dump some writeback information
|
||||
// in the form of errors, which is used for unit tests.
|
||||
|
@ -49,7 +49,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
wbcx.visit_node_id(param.pat.span, param.hir_id);
|
||||
}
|
||||
// Type only exists for constants and statics, not functions.
|
||||
match self.tcx.hir().body_owner_kind(item_def_id) {
|
||||
match self.tcx.hir_body_owner_kind(item_def_id) {
|
||||
hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) => {
|
||||
let item_hir_id = self.tcx.local_def_id_to_hir_id(item_def_id);
|
||||
wbcx.visit_node_id(body.value.span, item_hir_id);
|
||||
|
@ -790,7 +790,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
|
|||
self.fcx
|
||||
.err_ctxt()
|
||||
.emit_inference_failure_err(
|
||||
self.fcx.tcx.hir().body_owner_def_id(self.body.id()),
|
||||
self.fcx.tcx.hir_body_owner_def_id(self.body.id()),
|
||||
self.span.to_span(self.fcx.tcx),
|
||||
p.into(),
|
||||
TypeAnnotationNeeded::E0282,
|
||||
|
@ -814,7 +814,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
|
|||
// expect that types that show up in the typeck are fully
|
||||
// normalized.
|
||||
let mut value = if self.should_normalize {
|
||||
let body_id = tcx.hir().body_owner_def_id(self.body.id());
|
||||
let body_id = tcx.hir_body_owner_def_id(self.body.id());
|
||||
let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
|
||||
let at = self.fcx.at(&cause, self.fcx.param_env);
|
||||
let universes = vec![None; outer_exclusive_binder(value).as_usize()];
|
||||
|
|
|
@ -76,7 +76,7 @@ pub(crate) fn assert_dep_graph(tcx: TyCtxt<'_>) {
|
|||
let mut visitor =
|
||||
IfThisChanged { tcx, if_this_changed: vec![], then_this_would_need: vec![] };
|
||||
visitor.process_attrs(CRATE_DEF_ID);
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut visitor);
|
||||
tcx.hir_visit_all_item_likes_in_crate(&mut visitor);
|
||||
(visitor.if_this_changed, visitor.then_this_would_need)
|
||||
};
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ pub(crate) fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
|
|||
}
|
||||
|
||||
let mut all_attrs = FindAllAttrs { tcx, found_attrs: vec![] };
|
||||
tcx.hir().walk_attributes(&mut all_attrs);
|
||||
tcx.hir_walk_attributes(&mut all_attrs);
|
||||
|
||||
// Note that we cannot use the existing "unused attribute"-infrastructure
|
||||
// here, since that is running before codegen. This is also the reason why
|
||||
|
|
|
@ -20,21 +20,21 @@ use crate::errors::LimitInvalid;
|
|||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
providers.limits = |tcx, ()| Limits {
|
||||
recursion_limit: get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess),
|
||||
recursion_limit: get_recursion_limit(tcx.hir_krate_attrs(), tcx.sess),
|
||||
move_size_limit: get_limit(
|
||||
tcx.hir().krate_attrs(),
|
||||
tcx.hir_krate_attrs(),
|
||||
tcx.sess,
|
||||
sym::move_size_limit,
|
||||
Limit::new(tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0)),
|
||||
),
|
||||
type_length_limit: get_limit(
|
||||
tcx.hir().krate_attrs(),
|
||||
tcx.hir_krate_attrs(),
|
||||
tcx.sess,
|
||||
sym::type_length_limit,
|
||||
Limit::new(2usize.pow(24)),
|
||||
),
|
||||
pattern_complexity_limit: get_limit(
|
||||
tcx.hir().krate_attrs(),
|
||||
tcx.hir_krate_attrs(),
|
||||
tcx.sess,
|
||||
sym::pattern_complexity_limit,
|
||||
Limit::unlimited(),
|
||||
|
|
|
@ -846,7 +846,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
CStore::from_tcx(tcx).report_unused_deps(tcx);
|
||||
},
|
||||
{
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
tcx.par_hir_for_each_module(|module| {
|
||||
tcx.ensure_ok().check_mod_loops(module);
|
||||
tcx.ensure_ok().check_mod_attrs(module);
|
||||
tcx.ensure_ok().check_mod_naked_functions(module);
|
||||
|
@ -871,7 +871,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
|
||||
rustc_hir_analysis::check_crate(tcx);
|
||||
sess.time("MIR_coroutine_by_move_body", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
tcx.par_hir_body_owners(|def_id| {
|
||||
if tcx.needs_coroutine_by_move_body_def_id(def_id.to_def_id()) {
|
||||
tcx.ensure_done().coroutine_by_move_body_def_id(def_id);
|
||||
}
|
||||
|
@ -885,7 +885,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
tcx.untracked().definitions.freeze();
|
||||
|
||||
sess.time("MIR_borrow_checking", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
tcx.par_hir_body_owners(|def_id| {
|
||||
// Run unsafety check because it's responsible for stealing and
|
||||
// deallocating THIR.
|
||||
tcx.ensure_ok().check_unsafety(def_id);
|
||||
|
@ -893,21 +893,21 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
});
|
||||
});
|
||||
sess.time("MIR_effect_checking", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
tcx.par_hir_body_owners(|def_id| {
|
||||
tcx.ensure_ok().has_ffi_unwind_calls(def_id);
|
||||
|
||||
// If we need to codegen, ensure that we emit all errors from
|
||||
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering
|
||||
// them later during codegen.
|
||||
if tcx.sess.opts.output_types.should_codegen()
|
||||
|| tcx.hir().body_const_context(def_id).is_some()
|
||||
|| tcx.hir_body_const_context(def_id).is_some()
|
||||
{
|
||||
tcx.ensure_ok().mir_drops_elaborated_and_const_checked(def_id);
|
||||
}
|
||||
});
|
||||
});
|
||||
sess.time("coroutine_obligations", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
tcx.par_hir_body_owners(|def_id| {
|
||||
if tcx.is_coroutine(def_id.to_def_id()) {
|
||||
tcx.ensure_ok().mir_coroutine_witnesses(def_id);
|
||||
tcx.ensure_ok().check_coroutine_obligations(
|
||||
|
@ -931,7 +931,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
|
|||
// that requires the optimized/ctfe MIR, coroutine bodies, or evaluating consts.
|
||||
if tcx.sess.opts.unstable_opts.validate_mir {
|
||||
sess.time("ensuring_final_MIR_is_computable", || {
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
tcx.par_hir_body_owners(|def_id| {
|
||||
tcx.instance_mir(ty::InstanceKind::Item(def_id.into()));
|
||||
});
|
||||
});
|
||||
|
@ -967,7 +967,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
|
|||
tcx.ensure_ok().check_private_in_public(());
|
||||
},
|
||||
{
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
tcx.par_hir_for_each_module(|module| {
|
||||
tcx.ensure_ok().check_mod_deathness(module)
|
||||
});
|
||||
},
|
||||
|
@ -983,7 +983,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
|
|||
},
|
||||
{
|
||||
sess.time("privacy_checking_modules", || {
|
||||
tcx.hir().par_for_each_module(|module| {
|
||||
tcx.par_hir_for_each_module(|module| {
|
||||
tcx.ensure_ok().check_mod_privacy(module);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -166,7 +166,7 @@ fn suggest_question_mark<'tcx>(
|
|||
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env());
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
|
||||
let body_def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
||||
let body_def_id = cx.tcx.hir_body_owner_def_id(body_id);
|
||||
let cause =
|
||||
ObligationCause::new(span, body_def_id, rustc_infer::traits::ObligationCauseCode::Misc);
|
||||
|
||||
|
|
|
@ -379,7 +379,7 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
|
|||
) {
|
||||
let mut cx = LateContextAndPass { context, pass };
|
||||
|
||||
let (module, _span, hir_id) = tcx.hir().get_module(module_def_id);
|
||||
let (module, _span, hir_id) = tcx.hir_get_module(module_def_id);
|
||||
|
||||
cx.with_lint_attrs(hir_id, |cx| {
|
||||
// There is no module lint that will have the crate itself as an item, so check it here.
|
||||
|
@ -445,7 +445,7 @@ fn late_lint_crate_inner<'tcx, T: LateLintPass<'tcx>>(
|
|||
// Since the root module isn't visited as an item (because it isn't an
|
||||
// item), warn for it here.
|
||||
lint_callback!(cx, check_crate,);
|
||||
tcx.hir().walk_toplevel_module(cx);
|
||||
tcx.hir_walk_toplevel_module(cx);
|
||||
lint_callback!(cx, check_crate_post,);
|
||||
})
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
|||
|| {
|
||||
tcx.sess.time("module_lints", || {
|
||||
// Run per-module lints
|
||||
tcx.hir().par_for_each_module(|module| tcx.ensure_ok().lint_mod(module));
|
||||
tcx.par_hir_for_each_module(|module| tcx.ensure_ok().lint_mod(module));
|
||||
});
|
||||
},
|
||||
);
|
||||
|
|
|
@ -144,7 +144,7 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
|
|||
|
||||
let mut visitor = LintLevelMaximum { tcx, dont_need_to_run };
|
||||
visitor.process_opts();
|
||||
tcx.hir().walk_attributes(&mut visitor);
|
||||
tcx.hir_walk_attributes(&mut visitor);
|
||||
|
||||
visitor.dont_need_to_run
|
||||
}
|
||||
|
|
|
@ -696,7 +696,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
let target_modifiers = stat!("target-modifiers", || self.encode_target_modifiers());
|
||||
|
||||
let root = stat!("final", || {
|
||||
let attrs = tcx.hir().krate_attrs();
|
||||
let attrs = tcx.hir_krate_attrs();
|
||||
self.lazy(CrateRoot {
|
||||
header: CrateHeader {
|
||||
name: tcx.crate_name(LOCAL_CRATE),
|
||||
|
@ -1763,7 +1763,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
if should_encode_const(tcx.def_kind(def_id)) {
|
||||
let qualifs = tcx.mir_const_qualif(def_id);
|
||||
record!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs);
|
||||
let body = tcx.hir().maybe_body_owned_by(def_id);
|
||||
let body = tcx.hir_maybe_body_owned_by(def_id);
|
||||
if let Some(body) = body {
|
||||
let const_data = rendered_const(self.tcx, &body, def_id);
|
||||
record!(self.tables.rendered_const[def_id.to_def_id()] <- const_data);
|
||||
|
|
|
@ -229,64 +229,62 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
pub fn hir_body(self, id: BodyId) -> &'tcx Body<'tcx> {
|
||||
self.hir_owner_nodes(id.hir_id.owner).bodies[&id.hir_id.local_id]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Map<'hir> {
|
||||
#[track_caller]
|
||||
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
|
||||
self.tcx.hir_node(hir_id).fn_decl()
|
||||
pub fn hir_fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'tcx FnDecl<'tcx>> {
|
||||
self.hir_node(hir_id).fn_decl()
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
|
||||
self.tcx.hir_node(hir_id).fn_sig()
|
||||
pub fn hir_fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'tcx FnSig<'tcx>> {
|
||||
self.hir_node(hir_id).fn_sig()
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
||||
for (_, node) in self.parent_iter(hir_id) {
|
||||
pub fn hir_enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
||||
for (_, node) in self.hir().parent_iter(hir_id) {
|
||||
if let Some((def_id, _)) = node.associated_body() {
|
||||
return def_id;
|
||||
}
|
||||
}
|
||||
|
||||
bug!("no `enclosing_body_owner` for hir_id `{}`", hir_id);
|
||||
bug!("no `hir_enclosing_body_owner` for hir_id `{}`", hir_id);
|
||||
}
|
||||
|
||||
/// Returns the `HirId` that corresponds to the definition of
|
||||
/// which this is the body of, i.e., a `fn`, `const` or `static`
|
||||
/// item (possibly associated), a closure, or a `hir::AnonConst`.
|
||||
pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
|
||||
let parent = self.tcx.parent_hir_id(hir_id);
|
||||
assert_eq!(self.tcx.hir_node(parent).body_id().unwrap().hir_id, hir_id, "{hir_id:?}");
|
||||
pub fn hir_body_owner(self, BodyId { hir_id }: BodyId) -> HirId {
|
||||
let parent = self.parent_hir_id(hir_id);
|
||||
assert_eq!(self.hir_node(parent).body_id().unwrap().hir_id, hir_id, "{hir_id:?}");
|
||||
parent
|
||||
}
|
||||
|
||||
pub fn body_owner_def_id(self, BodyId { hir_id }: BodyId) -> LocalDefId {
|
||||
self.tcx.parent_hir_node(hir_id).associated_body().unwrap().0
|
||||
pub fn hir_body_owner_def_id(self, BodyId { hir_id }: BodyId) -> LocalDefId {
|
||||
self.parent_hir_node(hir_id).associated_body().unwrap().0
|
||||
}
|
||||
|
||||
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
|
||||
/// if the node is a body owner, otherwise returns `None`.
|
||||
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<&'hir Body<'hir>> {
|
||||
Some(self.tcx.hir_body(self.tcx.hir_node_by_def_id(id).body_id()?))
|
||||
pub fn hir_maybe_body_owned_by(self, id: LocalDefId) -> Option<&'tcx Body<'tcx>> {
|
||||
Some(self.hir_body(self.hir_node_by_def_id(id).body_id()?))
|
||||
}
|
||||
|
||||
/// Given a body owner's id, returns the `BodyId` associated with it.
|
||||
#[track_caller]
|
||||
pub fn body_owned_by(self, id: LocalDefId) -> &'hir Body<'hir> {
|
||||
self.maybe_body_owned_by(id).unwrap_or_else(|| {
|
||||
let hir_id = self.tcx.local_def_id_to_hir_id(id);
|
||||
pub fn hir_body_owned_by(self, id: LocalDefId) -> &'tcx Body<'tcx> {
|
||||
self.hir_maybe_body_owned_by(id).unwrap_or_else(|| {
|
||||
let hir_id = self.local_def_id_to_hir_id(id);
|
||||
span_bug!(
|
||||
self.span(hir_id),
|
||||
self.hir().span(hir_id),
|
||||
"body_owned_by: {} has no associated body",
|
||||
self.node_to_string(hir_id)
|
||||
self.hir().node_to_string(hir_id)
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
pub fn body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir {
|
||||
self.tcx.hir_body(id).params.iter().map(|arg| match arg.pat.kind {
|
||||
pub fn hir_body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'tcx {
|
||||
self.hir_body(id).params.iter().map(|arg| match arg.pat.kind {
|
||||
PatKind::Binding(_, _, ident, _) => ident,
|
||||
_ => Ident::empty(),
|
||||
})
|
||||
|
@ -295,9 +293,9 @@ impl<'hir> Map<'hir> {
|
|||
/// Returns the `BodyOwnerKind` of this `LocalDefId`.
|
||||
///
|
||||
/// Panics if `LocalDefId` does not have an associated body.
|
||||
pub fn body_owner_kind(self, def_id: impl Into<DefId>) -> BodyOwnerKind {
|
||||
pub fn hir_body_owner_kind(self, def_id: impl Into<DefId>) -> BodyOwnerKind {
|
||||
let def_id = def_id.into();
|
||||
match self.tcx.def_kind(def_id) {
|
||||
match self.def_kind(def_id) {
|
||||
DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
BodyOwnerKind::Const { inline: false }
|
||||
}
|
||||
|
@ -318,17 +316,17 @@ impl<'hir> Map<'hir> {
|
|||
/// This should only be used for determining the context of a body, a return
|
||||
/// value of `Some` does not always suggest that the owner of the body is `const`,
|
||||
/// just that it has to be checked as if it were.
|
||||
pub fn body_const_context(self, def_id: impl Into<DefId>) -> Option<ConstContext> {
|
||||
pub fn hir_body_const_context(self, def_id: impl Into<DefId>) -> Option<ConstContext> {
|
||||
let def_id = def_id.into();
|
||||
let ccx = match self.body_owner_kind(def_id) {
|
||||
let ccx = match self.hir_body_owner_kind(def_id) {
|
||||
BodyOwnerKind::Const { inline } => ConstContext::Const { inline },
|
||||
BodyOwnerKind::Static(mutability) => ConstContext::Static(mutability),
|
||||
|
||||
BodyOwnerKind::Fn if self.tcx.is_constructor(def_id) => return None,
|
||||
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.tcx.is_const_fn(def_id) => {
|
||||
BodyOwnerKind::Fn if self.is_constructor(def_id) => return None,
|
||||
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.is_const_fn(def_id) => {
|
||||
ConstContext::ConstFn
|
||||
}
|
||||
BodyOwnerKind::Fn if self.tcx.is_const_default_method(def_id) => ConstContext::ConstFn,
|
||||
BodyOwnerKind::Fn if self.is_const_default_method(def_id) => ConstContext::ConstFn,
|
||||
BodyOwnerKind::Fn | BodyOwnerKind::Closure => return None,
|
||||
};
|
||||
|
||||
|
@ -339,55 +337,55 @@ impl<'hir> Map<'hir> {
|
|||
/// crate. If you would prefer to iterate over the bodies
|
||||
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
|
||||
#[inline]
|
||||
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + 'hir {
|
||||
self.tcx.hir_crate_items(()).body_owners.iter().copied()
|
||||
pub fn hir_body_owners(self) -> impl Iterator<Item = LocalDefId> + 'tcx {
|
||||
self.hir_crate_items(()).body_owners.iter().copied()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn par_body_owners(self, f: impl Fn(LocalDefId) + DynSend + DynSync) {
|
||||
par_for_each_in(&self.tcx.hir_crate_items(()).body_owners[..], |&def_id| f(def_id));
|
||||
pub fn par_hir_body_owners(self, f: impl Fn(LocalDefId) + DynSend + DynSync) {
|
||||
par_for_each_in(&self.hir_crate_items(()).body_owners[..], |&def_id| f(def_id));
|
||||
}
|
||||
|
||||
pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId {
|
||||
let def_kind = self.tcx.def_kind(def_id);
|
||||
pub fn hir_ty_param_owner(self, def_id: LocalDefId) -> LocalDefId {
|
||||
let def_kind = self.def_kind(def_id);
|
||||
match def_kind {
|
||||
DefKind::Trait | DefKind::TraitAlias => def_id,
|
||||
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => {
|
||||
self.tcx.local_parent(def_id)
|
||||
self.local_parent(def_id)
|
||||
}
|
||||
_ => bug!("ty_param_owner: {:?} is a {:?} not a type parameter", def_id, def_kind),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty_param_name(self, def_id: LocalDefId) -> Symbol {
|
||||
let def_kind = self.tcx.def_kind(def_id);
|
||||
pub fn hir_ty_param_name(self, def_id: LocalDefId) -> Symbol {
|
||||
let def_kind = self.def_kind(def_id);
|
||||
match def_kind {
|
||||
DefKind::Trait | DefKind::TraitAlias => kw::SelfUpper,
|
||||
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => {
|
||||
self.tcx.item_name(def_id.to_def_id())
|
||||
self.item_name(def_id.to_def_id())
|
||||
}
|
||||
_ => bug!("ty_param_name: {:?} is a {:?} not a type parameter", def_id, def_kind),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trait_impls(self, trait_did: DefId) -> &'hir [LocalDefId] {
|
||||
self.tcx.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..])
|
||||
pub fn hir_trait_impls(self, trait_did: DefId) -> &'tcx [LocalDefId] {
|
||||
self.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..])
|
||||
}
|
||||
|
||||
/// Gets the attributes on the crate. This is preferable to
|
||||
/// invoking `krate.attrs` because it registers a tighter
|
||||
/// dep-graph access.
|
||||
pub fn krate_attrs(self) -> &'hir [Attribute] {
|
||||
self.attrs(CRATE_HIR_ID)
|
||||
pub fn hir_krate_attrs(self) -> &'tcx [Attribute] {
|
||||
self.hir().attrs(CRATE_HIR_ID)
|
||||
}
|
||||
|
||||
pub fn rustc_coherence_is_core(self) -> bool {
|
||||
self.krate_attrs().iter().any(|attr| attr.has_name(sym::rustc_coherence_is_core))
|
||||
pub fn hir_rustc_coherence_is_core(self) -> bool {
|
||||
self.hir_krate_attrs().iter().any(|attr| attr.has_name(sym::rustc_coherence_is_core))
|
||||
}
|
||||
|
||||
pub fn get_module(self, module: LocalModDefId) -> (&'hir Mod<'hir>, Span, HirId) {
|
||||
pub fn hir_get_module(self, module: LocalModDefId) -> (&'tcx Mod<'tcx>, Span, HirId) {
|
||||
let hir_id = HirId::make_owner(module.to_local_def_id());
|
||||
match self.tcx.hir_owner_node(hir_id.owner) {
|
||||
match self.hir_owner_node(hir_id.owner) {
|
||||
OwnerNode::Item(&Item { span, kind: ItemKind::Mod(m), .. }) => (m, span, hir_id),
|
||||
OwnerNode::Crate(item) => (item, item.spans.inner_span, hir_id),
|
||||
node => panic!("not a module: {node:?}"),
|
||||
|
@ -395,20 +393,20 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
|
||||
/// Walks the contents of the local crate. See also `visit_all_item_likes_in_crate`.
|
||||
pub fn walk_toplevel_module<V>(self, visitor: &mut V) -> V::Result
|
||||
pub fn hir_walk_toplevel_module<V>(self, visitor: &mut V) -> V::Result
|
||||
where
|
||||
V: Visitor<'hir>,
|
||||
V: Visitor<'tcx>,
|
||||
{
|
||||
let (top_mod, span, hir_id) = self.get_module(LocalModDefId::CRATE_DEF_ID);
|
||||
let (top_mod, span, hir_id) = self.hir_get_module(LocalModDefId::CRATE_DEF_ID);
|
||||
visitor.visit_mod(top_mod, span, hir_id)
|
||||
}
|
||||
|
||||
/// Walks the attributes in a crate.
|
||||
pub fn walk_attributes<V>(self, visitor: &mut V) -> V::Result
|
||||
pub fn hir_walk_attributes<V>(self, visitor: &mut V) -> V::Result
|
||||
where
|
||||
V: Visitor<'hir>,
|
||||
V: Visitor<'tcx>,
|
||||
{
|
||||
let krate = self.tcx.hir_crate(());
|
||||
let krate = self.hir_crate(());
|
||||
for info in krate.owners.iter() {
|
||||
if let MaybeOwner::Owner(info) = info {
|
||||
for attrs in info.attrs.map.values() {
|
||||
|
@ -422,89 +420,87 @@ impl<'hir> Map<'hir> {
|
|||
/// Visits all item-likes in the crate in some deterministic (but unspecified) order. If you
|
||||
/// need to process every item-like, and don't care about visiting nested items in a particular
|
||||
/// order then this method is the best choice. If you do care about this nesting, you should
|
||||
/// use the `tcx.hir().walk_toplevel_module`.
|
||||
/// use the `tcx.hir_walk_toplevel_module`.
|
||||
///
|
||||
/// Note that this function will access HIR for all the item-likes in the crate. If you only
|
||||
/// need to access some of them, it is usually better to manually loop on the iterators
|
||||
/// provided by `tcx.hir_crate_items(())`.
|
||||
///
|
||||
/// Please see the notes in `intravisit.rs` for more information.
|
||||
pub fn visit_all_item_likes_in_crate<V>(self, visitor: &mut V) -> V::Result
|
||||
pub fn hir_visit_all_item_likes_in_crate<V>(self, visitor: &mut V) -> V::Result
|
||||
where
|
||||
V: Visitor<'hir>,
|
||||
V: Visitor<'tcx>,
|
||||
{
|
||||
let krate = self.tcx.hir_crate_items(());
|
||||
walk_list!(visitor, visit_item, krate.free_items().map(|id| self.tcx.hir_item(id)));
|
||||
let krate = self.hir_crate_items(());
|
||||
walk_list!(visitor, visit_item, krate.free_items().map(|id| self.hir_item(id)));
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_trait_item,
|
||||
krate.trait_items().map(|id| self.tcx.hir_trait_item(id))
|
||||
);
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_impl_item,
|
||||
krate.impl_items().map(|id| self.tcx.hir_impl_item(id))
|
||||
krate.trait_items().map(|id| self.hir_trait_item(id))
|
||||
);
|
||||
walk_list!(visitor, visit_impl_item, krate.impl_items().map(|id| self.hir_impl_item(id)));
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_foreign_item,
|
||||
krate.foreign_items().map(|id| self.tcx.hir_foreign_item(id))
|
||||
krate.foreign_items().map(|id| self.hir_foreign_item(id))
|
||||
);
|
||||
V::Result::output()
|
||||
}
|
||||
|
||||
/// This method is the equivalent of `visit_all_item_likes_in_crate` but restricted to
|
||||
/// item-likes in a single module.
|
||||
pub fn visit_item_likes_in_module<V>(self, module: LocalModDefId, visitor: &mut V) -> V::Result
|
||||
pub fn hir_visit_item_likes_in_module<V>(
|
||||
self,
|
||||
module: LocalModDefId,
|
||||
visitor: &mut V,
|
||||
) -> V::Result
|
||||
where
|
||||
V: Visitor<'hir>,
|
||||
V: Visitor<'tcx>,
|
||||
{
|
||||
let module = self.tcx.hir_module_items(module);
|
||||
walk_list!(visitor, visit_item, module.free_items().map(|id| self.tcx.hir_item(id)));
|
||||
let module = self.hir_module_items(module);
|
||||
walk_list!(visitor, visit_item, module.free_items().map(|id| self.hir_item(id)));
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_trait_item,
|
||||
module.trait_items().map(|id| self.tcx.hir_trait_item(id))
|
||||
);
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_impl_item,
|
||||
module.impl_items().map(|id| self.tcx.hir_impl_item(id))
|
||||
module.trait_items().map(|id| self.hir_trait_item(id))
|
||||
);
|
||||
walk_list!(visitor, visit_impl_item, module.impl_items().map(|id| self.hir_impl_item(id)));
|
||||
walk_list!(
|
||||
visitor,
|
||||
visit_foreign_item,
|
||||
module.foreign_items().map(|id| self.tcx.hir_foreign_item(id))
|
||||
module.foreign_items().map(|id| self.hir_foreign_item(id))
|
||||
);
|
||||
V::Result::output()
|
||||
}
|
||||
|
||||
pub fn for_each_module(self, mut f: impl FnMut(LocalModDefId)) {
|
||||
let crate_items = self.tcx.hir_crate_items(());
|
||||
pub fn hir_for_each_module(self, mut f: impl FnMut(LocalModDefId)) {
|
||||
let crate_items = self.hir_crate_items(());
|
||||
for module in crate_items.submodules.iter() {
|
||||
f(LocalModDefId::new_unchecked(module.def_id))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn par_for_each_module(self, f: impl Fn(LocalModDefId) + DynSend + DynSync) {
|
||||
let crate_items = self.tcx.hir_crate_items(());
|
||||
pub fn par_hir_for_each_module(self, f: impl Fn(LocalModDefId) + DynSend + DynSync) {
|
||||
let crate_items = self.hir_crate_items(());
|
||||
par_for_each_in(&crate_items.submodules[..], |module| {
|
||||
f(LocalModDefId::new_unchecked(module.def_id))
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_par_for_each_module(
|
||||
pub fn try_par_hir_for_each_module(
|
||||
self,
|
||||
f: impl Fn(LocalModDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let crate_items = self.tcx.hir_crate_items(());
|
||||
let crate_items = self.hir_crate_items(());
|
||||
try_par_for_each_in(&crate_items.submodules[..], |module| {
|
||||
f(LocalModDefId::new_unchecked(module.def_id))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'hir> Map<'hir> {
|
||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||
/// until the crate root is reached. Prefer this over your own loop using `parent_id`.
|
||||
#[inline]
|
||||
|
@ -540,7 +536,7 @@ impl<'hir> Map<'hir> {
|
|||
/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
|
||||
/// Used exclusively for diagnostics, to avoid suggestion function calls.
|
||||
pub fn is_inside_const_context(self, hir_id: HirId) -> bool {
|
||||
self.body_const_context(self.enclosing_body_owner(hir_id)).is_some()
|
||||
self.tcx.hir_body_const_context(self.tcx.hir_enclosing_body_owner(hir_id)).is_some()
|
||||
}
|
||||
|
||||
/// Retrieves the `HirId` for `id`'s enclosing function *if* the `id` block or return is
|
||||
|
@ -566,7 +562,8 @@ impl<'hir> Map<'hir> {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn get_fn_id_for_return_block(self, id: HirId) -> Option<HirId> {
|
||||
let enclosing_body_owner = self.tcx.local_def_id_to_hir_id(self.enclosing_body_owner(id));
|
||||
let enclosing_body_owner =
|
||||
self.tcx.local_def_id_to_hir_id(self.tcx.hir_enclosing_body_owner(id));
|
||||
|
||||
// Return `None` if the `id` expression is not the returned value of the enclosing body
|
||||
let mut iter = [id].into_iter().chain(self.parent_id_iter(id)).peekable();
|
||||
|
@ -1249,7 +1246,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
|
|||
pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> ModuleItems {
|
||||
let mut collector = ItemCollector::new(tcx, false);
|
||||
|
||||
let (hir_mod, span, hir_id) = tcx.hir().get_module(module_id);
|
||||
let (hir_mod, span, hir_id) = tcx.hir_get_module(module_id);
|
||||
collector.visit_mod(hir_mod, span, hir_id);
|
||||
|
||||
let ItemCollector {
|
||||
|
@ -1282,7 +1279,7 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
|
|||
// module item (the former starts at the crate root) but only
|
||||
// the former needs to collect it. ItemCollector does not do this for us.
|
||||
collector.submodules.push(CRATE_OWNER_ID);
|
||||
tcx.hir().walk_toplevel_module(&mut collector);
|
||||
tcx.hir_walk_toplevel_module(&mut collector);
|
||||
|
||||
let ItemCollector {
|
||||
submodules,
|
||||
|
|
|
@ -213,7 +213,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
providers.fn_arg_names = |tcx, def_id| {
|
||||
let hir = tcx.hir();
|
||||
if let Some(body_id) = tcx.hir_node_by_def_id(def_id).body_id() {
|
||||
tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
|
||||
tcx.arena.alloc_from_iter(tcx.hir_body_param_names(body_id))
|
||||
} else if let Node::TraitItem(&TraitItem {
|
||||
kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
|
||||
..
|
||||
|
|
|
@ -1588,7 +1588,7 @@ pub fn write_allocations<'tcx>(
|
|||
Some(GlobalAlloc::Static(did)) if !tcx.is_foreign_item(did) => {
|
||||
write!(w, " (static: {}", tcx.def_path_str(did))?;
|
||||
if body.phase <= MirPhase::Runtime(RuntimePhase::PostCleanup)
|
||||
&& tcx.hir().body_const_context(body.source.def_id()).is_some()
|
||||
&& tcx.hir_body_const_context(body.source.def_id()).is_some()
|
||||
{
|
||||
// Statics may be cyclic and evaluating them too early
|
||||
// in the MIR pipeline may cause cycle errors even though
|
||||
|
|
|
@ -163,7 +163,7 @@ rustc_queries! {
|
|||
|
||||
/// The items in a module.
|
||||
///
|
||||
/// This can be conveniently accessed by `tcx.hir().visit_item_likes_in_module`.
|
||||
/// This can be conveniently accessed by `tcx.hir_visit_item_likes_in_module`.
|
||||
/// Avoid calling this query directly.
|
||||
query hir_module_items(key: LocalModDefId) -> &'tcx rustc_middle::hir::ModuleItems {
|
||||
arena_cache
|
||||
|
@ -771,7 +771,7 @@ rustc_queries! {
|
|||
query type_param_predicates(
|
||||
key: (LocalDefId, LocalDefId, rustc_span::Ident)
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
|
||||
desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir_ty_param_name(key.1) }
|
||||
}
|
||||
|
||||
query trait_def(key: DefId) -> &'tcx ty::TraitDef {
|
||||
|
|
|
@ -2079,7 +2079,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
) -> Vec<&'tcx hir::Ty<'tcx>> {
|
||||
let hir_id = self.local_def_id_to_hir_id(scope_def_id);
|
||||
let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) =
|
||||
self.hir().fn_decl_by_hir_id(hir_id)
|
||||
self.hir_fn_decl_by_hir_id(hir_id)
|
||||
else {
|
||||
return vec![];
|
||||
};
|
||||
|
@ -2099,7 +2099,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let hir_id = self.local_def_id_to_hir_id(scope_def_id);
|
||||
let mut v = TraitObjectVisitor(vec![], self.hir());
|
||||
// when the return type is a type alias
|
||||
if let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir().fn_decl_by_hir_id(hir_id)
|
||||
if let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir_fn_decl_by_hir_id(hir_id)
|
||||
&& let hir::TyKind::Path(hir::QPath::Resolved(
|
||||
None,
|
||||
hir::Path { res: hir::def::Res::Def(DefKind::TyAlias, def_id), .. }, )) = hir_output.kind
|
||||
|
@ -3297,9 +3297,9 @@ pub fn provide(providers: &mut Providers) {
|
|||
providers.extern_mod_stmt_cnum =
|
||||
|tcx, id| tcx.resolutions(()).extern_crate_map.get(&id).cloned();
|
||||
providers.is_panic_runtime =
|
||||
|tcx, LocalCrate| contains_name(tcx.hir().krate_attrs(), sym::panic_runtime);
|
||||
|tcx, LocalCrate| contains_name(tcx.hir_krate_attrs(), sym::panic_runtime);
|
||||
providers.is_compiler_builtins =
|
||||
|tcx, LocalCrate| contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins);
|
||||
|tcx, LocalCrate| contains_name(tcx.hir_krate_attrs(), sym::compiler_builtins);
|
||||
providers.has_panic_handler = |tcx, LocalCrate| {
|
||||
// We want to check if the panic handler was defined in this crate
|
||||
tcx.lang_items().panic_impl().is_some_and(|did| did.is_local())
|
||||
|
|
|
@ -1470,7 +1470,7 @@ pub enum ImplTraitInTraitData {
|
|||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn typeck_body(self, body: hir::BodyId) -> &'tcx TypeckResults<'tcx> {
|
||||
self.typeck(self.hir().body_owner_def_id(body))
|
||||
self.typeck(self.hir_body_owner_def_id(body))
|
||||
}
|
||||
|
||||
pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {
|
||||
|
|
|
@ -235,7 +235,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
|
|||
}
|
||||
}
|
||||
|
||||
for &impl_def_id in tcx.hir().trait_impls(trait_id) {
|
||||
for &impl_def_id in tcx.hir_trait_impls(trait_id) {
|
||||
let impl_def_id = impl_def_id.to_def_id();
|
||||
|
||||
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
|
||||
|
|
|
@ -465,11 +465,10 @@ fn construct_fn<'tcx>(
|
|||
assert_eq!(expr.as_usize(), thir.exprs.len() - 1);
|
||||
|
||||
// Figure out what primary body this item has.
|
||||
let body = tcx.hir().body_owned_by(fn_def);
|
||||
let body = tcx.hir_body_owned_by(fn_def);
|
||||
let span_with_body = tcx.hir().span_with_body(fn_id);
|
||||
let return_ty_span = tcx
|
||||
.hir()
|
||||
.fn_decl_by_hir_id(fn_id)
|
||||
.hir_fn_decl_by_hir_id(fn_id)
|
||||
.unwrap_or_else(|| span_bug!(span, "can't build MIR for {:?}", fn_def))
|
||||
.output
|
||||
.span();
|
||||
|
@ -758,7 +757,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
check_overflow |= tcx.sess.overflow_checks();
|
||||
// Constants always need overflow checks.
|
||||
check_overflow |= matches!(
|
||||
tcx.hir().body_owner_kind(def),
|
||||
tcx.hir_body_owner_kind(def),
|
||||
hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_)
|
||||
);
|
||||
|
||||
|
|
|
@ -927,7 +927,7 @@ impl UnsafeOpKind {
|
|||
&& let hir::BlockCheckMode::UnsafeBlock(_) = block.rules
|
||||
{
|
||||
true
|
||||
} else if let Some(sig) = tcx.hir().fn_sig_by_hir_id(*id)
|
||||
} else if let Some(sig) = tcx.hir_fn_sig_by_hir_id(*id)
|
||||
&& matches!(sig.header.safety, hir::HeaderSafety::Normal(hir::Safety::Unsafe))
|
||||
{
|
||||
true
|
||||
|
@ -1145,7 +1145,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
|
|||
let thir = &thir.steal();
|
||||
|
||||
let hir_id = tcx.local_def_id_to_hir_id(def);
|
||||
let safety_context = tcx.hir().fn_sig_by_hir_id(hir_id).map_or(SafetyContext::Safe, |fn_sig| {
|
||||
let safety_context = tcx.hir_fn_sig_by_hir_id(hir_id).map_or(SafetyContext::Safe, |fn_sig| {
|
||||
match fn_sig.header.safety {
|
||||
// We typeck the body as safe, but otherwise treat it as unsafe everywhere else.
|
||||
// Call sites to other SafeTargetFeatures functions are checked explicitly and don't need
|
||||
|
|
|
@ -22,8 +22,7 @@ pub(crate) fn thir_body(
|
|||
tcx: TyCtxt<'_>,
|
||||
owner_def: LocalDefId,
|
||||
) -> Result<(&Steal<Thir<'_>>, ExprId), ErrorGuaranteed> {
|
||||
let hir = tcx.hir();
|
||||
let body = hir.body_owned_by(owner_def);
|
||||
let body = tcx.hir_body_owned_by(owner_def);
|
||||
let mut cx = ThirBuildCx::new(tcx, owner_def);
|
||||
if let Some(reported) = cx.typeck_results.tainted_by_errors {
|
||||
return Err(reported);
|
||||
|
@ -31,7 +30,7 @@ pub(crate) fn thir_body(
|
|||
let expr = cx.mirror_expr(body.value);
|
||||
|
||||
let owner_id = tcx.local_def_id_to_hir_id(owner_def);
|
||||
if let Some(fn_decl) = hir.fn_decl_by_hir_id(owner_id) {
|
||||
if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(owner_id) {
|
||||
let closure_env_param = cx.closure_env_param(owner_def, owner_id);
|
||||
let explicit_params = cx.explicit_params(owner_id, fn_decl, &body);
|
||||
cx.thir.params = closure_env_param.into_iter().chain(explicit_params).collect();
|
||||
|
@ -77,7 +76,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
|
|||
let hir = tcx.hir();
|
||||
let hir_id = tcx.local_def_id_to_hir_id(def);
|
||||
|
||||
let body_type = if hir.body_owner_kind(def).is_fn_or_closure() {
|
||||
let body_type = if tcx.hir_body_owner_kind(def).is_fn_or_closure() {
|
||||
// fetch the fully liberated fn signature (that is, all bound
|
||||
// types/lifetimes replaced)
|
||||
BodyTy::Fn(typeck_results.liberated_fn_sigs()[hir_id])
|
||||
|
|
|
@ -148,7 +148,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
if let ty::GenericArgKind::Type(ty) = arg.unpack()
|
||||
&& let ty::Param(param_ty) = ty.kind()
|
||||
{
|
||||
let def_id = self.tcx.hir().enclosing_body_owner(self.id);
|
||||
let def_id = self.tcx.hir_enclosing_body_owner(self.id);
|
||||
let generics = self.tcx.generics_of(def_id);
|
||||
let param = generics.type_param(*param_ty, self.tcx);
|
||||
let span = self.tcx.def_span(param.def_id);
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(super) struct CheckForceInline;
|
|||
impl<'tcx> MirLint<'tcx> for CheckForceInline {
|
||||
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
||||
let def_id = body.source.def_id();
|
||||
if !tcx.hir().body_owner_kind(def_id).is_fn_or_closure() || !def_id.is_local() {
|
||||
if !tcx.hir_body_owner_kind(def_id).is_fn_or_closure() || !def_id.is_local() {
|
||||
return;
|
||||
}
|
||||
let InlineAttr::Force { attr_span, .. } = tcx.codegen_fn_attrs(def_id).inline else {
|
||||
|
|
|
@ -113,7 +113,7 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
|
|||
return Some(PanicStrategy::Abort);
|
||||
}
|
||||
|
||||
for def_id in tcx.hir().body_owners() {
|
||||
for def_id in tcx.hir_body_owners() {
|
||||
if tcx.has_ffi_unwind_calls(def_id) {
|
||||
// Given that this crate is compiled in `-C panic=unwind`, the `AbortUnwindingCalls`
|
||||
// MIR pass will not be run on FFI-unwind call sites, therefore a foreign exception
|
||||
|
|
|
@ -463,7 +463,7 @@ fn inline<'tcx, T: Inliner<'tcx>>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> b
|
|||
let def_id = body.source.def_id();
|
||||
|
||||
// Only do inlining into fn bodies.
|
||||
if !tcx.hir().body_owner_kind(def_id).is_fn_or_closure() {
|
||||
if !tcx.hir_body_owner_kind(def_id).is_fn_or_closure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
|
|||
typing_env: body.typing_env(tcx),
|
||||
};
|
||||
let preserve_ub_checks =
|
||||
attr::contains_name(tcx.hir().krate_attrs(), sym::rustc_preserve_ub_checks);
|
||||
attr::contains_name(tcx.hir_krate_attrs(), sym::rustc_preserve_ub_checks);
|
||||
for block in body.basic_blocks.as_mut() {
|
||||
for statement in block.statements.iter_mut() {
|
||||
match statement.kind {
|
||||
|
|
|
@ -314,11 +314,11 @@ fn is_mir_available(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
|||
/// MIR associated with them.
|
||||
fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
|
||||
// All body-owners have MIR associated with them.
|
||||
let mut set: FxIndexSet<_> = tcx.hir().body_owners().collect();
|
||||
let mut set: FxIndexSet<_> = tcx.hir_body_owners().collect();
|
||||
|
||||
// Coroutine-closures (e.g. async closures) have an additional by-move MIR
|
||||
// body that isn't in the HIR.
|
||||
for body_owner in tcx.hir().body_owners() {
|
||||
for body_owner in tcx.hir_body_owners() {
|
||||
if let DefKind::Closure = tcx.def_kind(body_owner)
|
||||
&& tcx.needs_coroutine_by_move_body_def_id(body_owner.to_def_id())
|
||||
{
|
||||
|
@ -470,7 +470,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
|
|||
}
|
||||
|
||||
let body = tcx.mir_drops_elaborated_and_const_checked(def);
|
||||
let body = match tcx.hir().body_const_context(def) {
|
||||
let body = match tcx.hir_body_const_context(def) {
|
||||
// consts and statics do not have `optimized_mir`, so we can steal the body instead of
|
||||
// cloning it.
|
||||
Some(hir::ConstContext::Const { .. } | hir::ConstContext::Static(_)) => body.steal(),
|
||||
|
@ -729,7 +729,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
|
|||
return shim::build_adt_ctor(tcx, did.to_def_id());
|
||||
}
|
||||
|
||||
match tcx.hir().body_const_context(did) {
|
||||
match tcx.hir_body_const_context(did) {
|
||||
// Run the `mir_for_ctfe` query, which depends on `mir_drops_elaborated_and_const_checked`
|
||||
// which we are going to steal below. Thus we need to run `mir_for_ctfe` first, so it
|
||||
// computes and caches its result.
|
||||
|
|
|
@ -2461,7 +2461,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
if let Err(terr) = ocx.eq(&cause, param_env, expected_sig, sig) {
|
||||
let mut diag = tcx.dcx().create_err(errors::ProcMacroBadSig { span, kind });
|
||||
|
||||
let hir_sig = tcx.hir().fn_sig_by_hir_id(hir_id);
|
||||
let hir_sig = tcx.hir_fn_sig_by_hir_id(hir_id);
|
||||
if let Some(hir_sig) = hir_sig {
|
||||
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
|
||||
match terr {
|
||||
|
@ -2791,10 +2791,10 @@ fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>)
|
|||
|
||||
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
|
||||
let check_attr_visitor = &mut CheckAttrVisitor { tcx, abort: Cell::new(false) };
|
||||
tcx.hir().visit_item_likes_in_module(module_def_id, check_attr_visitor);
|
||||
tcx.hir_visit_item_likes_in_module(module_def_id, check_attr_visitor);
|
||||
if module_def_id.to_local_def_id().is_top_level_module() {
|
||||
check_attr_visitor.check_attributes(CRATE_HIR_ID, DUMMY_SP, Target::Mod, None);
|
||||
check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs());
|
||||
check_invalid_crate_level_attr(tcx, tcx.hir_krate_attrs());
|
||||
}
|
||||
if check_attr_visitor.abort.get() {
|
||||
tcx.dcx().abort_if_errors()
|
||||
|
|
|
@ -358,7 +358,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
if let Some(local_impl_of) = impl_of.as_local()
|
||||
&& let Some(local_def_id) = def_id.as_local()
|
||||
&& let Some(fn_sig) =
|
||||
self.tcx.hir().fn_sig_by_hir_id(self.tcx.local_def_id_to_hir_id(local_def_id))
|
||||
self.tcx.hir_fn_sig_by_hir_id(self.tcx.local_def_id_to_hir_id(local_def_id))
|
||||
&& matches!(fn_sig.decl.implicit_self, hir::ImplicitSelfKind::None)
|
||||
&& let TyKind::Path(hir::QPath::Resolved(_, path)) =
|
||||
self.tcx.hir().expect_item(local_impl_of).expect_impl().self_ty.kind
|
||||
|
@ -779,7 +779,7 @@ fn check_item<'tcx>(
|
|||
// check the function may construct Self
|
||||
let mut may_construct_self = false;
|
||||
if let Some(fn_sig) =
|
||||
tcx.hir().fn_sig_by_hir_id(tcx.local_def_id_to_hir_id(local_def_id))
|
||||
tcx.hir_fn_sig_by_hir_id(tcx.local_def_id_to_hir_id(local_def_id))
|
||||
{
|
||||
may_construct_self =
|
||||
matches!(fn_sig.decl.implicit_self, hir::ImplicitSelfKind::None);
|
||||
|
|
|
@ -9,11 +9,11 @@ use rustc_middle::ty::TyCtxt;
|
|||
pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||
let errors = Lock::new(Vec::new());
|
||||
|
||||
tcx.hir().par_for_each_module(|module_id| {
|
||||
tcx.par_hir_for_each_module(|module_id| {
|
||||
let mut v =
|
||||
HirIdValidator { tcx, owner: None, hir_ids_seen: Default::default(), errors: &errors };
|
||||
|
||||
tcx.hir().visit_item_likes_in_module(module_id, &mut v);
|
||||
tcx.hir_visit_item_likes_in_module(module_id, &mut v);
|
||||
});
|
||||
|
||||
let errors = errors.into_inner();
|
||||
|
|
|
@ -63,8 +63,8 @@ struct StatCollector<'k> {
|
|||
pub fn print_hir_stats(tcx: TyCtxt<'_>) {
|
||||
let mut collector =
|
||||
StatCollector { tcx: Some(tcx), nodes: FxHashMap::default(), seen: FxHashSet::default() };
|
||||
tcx.hir().walk_toplevel_module(&mut collector);
|
||||
tcx.hir().walk_attributes(&mut collector);
|
||||
tcx.hir_walk_toplevel_module(&mut collector);
|
||||
tcx.hir_walk_attributes(&mut collector);
|
||||
collector.print("HIR STATS", "hir-stats");
|
||||
}
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ fn lib_features(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> LibFeatures {
|
|||
}
|
||||
|
||||
let mut collector = LibFeatureCollector::new(tcx);
|
||||
tcx.hir().walk_attributes(&mut collector);
|
||||
tcx.hir_walk_attributes(&mut collector);
|
||||
collector.lib_features
|
||||
}
|
||||
|
||||
|
|
|
@ -152,8 +152,8 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
}
|
||||
|
||||
let mut maps = IrMaps::new(tcx);
|
||||
let body = tcx.hir().body_owned_by(def_id);
|
||||
let hir_id = tcx.hir().body_owner(body.id());
|
||||
let body = tcx.hir_body_owned_by(def_id);
|
||||
let hir_id = tcx.hir_body_owner(body.id());
|
||||
|
||||
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
|
||||
for &var_hir_id in upvars.keys() {
|
||||
|
@ -1522,8 +1522,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
|
|||
}
|
||||
|
||||
fn warn_about_unused_args(&self, body: &hir::Body<'_>, entry_ln: LiveNode) {
|
||||
if let Some(intrinsic) =
|
||||
self.ir.tcx.intrinsic(self.ir.tcx.hir().body_owner_def_id(body.id()))
|
||||
if let Some(intrinsic) = self.ir.tcx.intrinsic(self.ir.tcx.hir_body_owner_def_id(body.id()))
|
||||
{
|
||||
if intrinsic.must_be_overridden {
|
||||
return;
|
||||
|
|
|
@ -76,7 +76,7 @@ struct CheckLoopVisitor<'tcx> {
|
|||
fn check_mod_loops(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
|
||||
let mut check =
|
||||
CheckLoopVisitor { tcx, cx_stack: vec![Normal], block_breaks: Default::default() };
|
||||
tcx.hir().visit_item_likes_in_module(module_def_id, &mut check);
|
||||
tcx.hir_visit_item_likes_in_module(module_def_id, &mut check);
|
||||
check.report_outside_loop_error();
|
||||
}
|
||||
|
||||
|
|
|
@ -721,7 +721,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
|
|||
InheritDeprecation::Yes,
|
||||
InheritConstStability::No,
|
||||
InheritStability::No,
|
||||
|v| tcx.hir().walk_toplevel_module(v),
|
||||
|v| tcx.hir_walk_toplevel_module(v),
|
||||
);
|
||||
}
|
||||
index
|
||||
|
@ -730,7 +730,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
|
|||
/// Cross-references the feature names of unstable APIs with enabled
|
||||
/// features and possibly prints errors.
|
||||
fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
|
||||
tcx.hir().visit_item_likes_in_module(module_def_id, &mut Checker { tcx });
|
||||
tcx.hir_visit_item_likes_in_module(module_def_id, &mut Checker { tcx });
|
||||
}
|
||||
|
||||
pub(crate) fn provide(providers: &mut Providers) {
|
||||
|
@ -1059,8 +1059,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
let effective_visibilities = &tcx.effective_visibilities(());
|
||||
let mut missing = MissingStabilityAnnotations { tcx, effective_visibilities };
|
||||
missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID));
|
||||
tcx.hir().walk_toplevel_module(&mut missing);
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut missing);
|
||||
tcx.hir_walk_toplevel_module(&mut missing);
|
||||
tcx.hir_visit_all_item_likes_in_crate(&mut missing);
|
||||
}
|
||||
|
||||
let enabled_lang_features = tcx.features().enabled_lang_features();
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(crate) fn provide(providers: &mut Providers) {
|
|||
}
|
||||
|
||||
let local_def_id = def_id.expect_local();
|
||||
let body = tcx.hir().maybe_body_owned_by(local_def_id)?;
|
||||
let body = tcx.hir_maybe_body_owned_by(local_def_id)?;
|
||||
|
||||
let mut local_collector = LocalCollector::default();
|
||||
local_collector.visit_body(&body);
|
||||
|
|
|
@ -1771,7 +1771,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
|
||||
// Check privacy of names not checked in previous compilation stages.
|
||||
let mut visitor = NamePrivacyVisitor { tcx, maybe_typeck_results: None };
|
||||
tcx.hir().visit_item_likes_in_module(module_def_id, &mut visitor);
|
||||
tcx.hir_visit_item_likes_in_module(module_def_id, &mut visitor);
|
||||
|
||||
// Check privacy of explicitly written types and traits as well as
|
||||
// inferred types of expressions and patterns.
|
||||
|
@ -1782,7 +1782,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
|
|||
for def_id in module.definitions() {
|
||||
rustc_ty_utils::sig_types::walk_types(tcx, def_id, &mut visitor);
|
||||
|
||||
if let Some(body_id) = tcx.hir().maybe_body_owned_by(def_id) {
|
||||
if let Some(body_id) = tcx.hir_maybe_body_owned_by(def_id) {
|
||||
visitor.visit_nested_body(body_id.id());
|
||||
}
|
||||
}
|
||||
|
@ -1863,7 +1863,7 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
|
|||
}
|
||||
|
||||
loop {
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut visitor);
|
||||
tcx.hir_visit_all_item_likes_in_crate(&mut visitor);
|
||||
if visitor.changed {
|
||||
visitor.changed = false;
|
||||
} else {
|
||||
|
@ -1875,7 +1875,7 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
|
|||
let mut check_visitor =
|
||||
TestReachabilityVisitor { tcx, effective_visibilities: &visitor.effective_visibilities };
|
||||
check_visitor.effective_visibility_diagnostic(CRATE_DEF_ID);
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut check_visitor);
|
||||
tcx.hir_visit_all_item_likes_in_crate(&mut check_visitor);
|
||||
|
||||
tcx.arena.alloc(visitor.effective_visibilities)
|
||||
}
|
||||
|
|
|
@ -489,7 +489,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
};
|
||||
|
||||
let mut local_visitor = FindInferSourceVisitor::new(self, typeck_results, arg);
|
||||
if let Some(body) = self.tcx.hir().maybe_body_owned_by(
|
||||
if let Some(body) = self.tcx.hir_maybe_body_owned_by(
|
||||
self.tcx.typeck_root_def_id(body_def_id.to_def_id()).expect_local(),
|
||||
) {
|
||||
let expr = body.value;
|
||||
|
|
|
@ -147,7 +147,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
| ObligationCauseCode::BlockTailExpression(hir_id, ..) = cause.code()
|
||||
{
|
||||
let parent_id = tcx.hir().get_parent_item(*hir_id);
|
||||
if let Some(fn_decl) = tcx.hir().fn_decl_by_hir_id(parent_id.into()) {
|
||||
if let Some(fn_decl) = tcx.hir_fn_decl_by_hir_id(parent_id.into()) {
|
||||
let mut span: MultiSpan = fn_decl.output.span().into();
|
||||
let mut spans = Vec::new();
|
||||
let mut add_label = true;
|
||||
|
@ -490,7 +490,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
// obligation comes from the `impl`. Find that `impl` so that we can point
|
||||
// at it in the suggestion.
|
||||
let trait_did = trait_id.to_def_id();
|
||||
tcx.hir().trait_impls(trait_did).iter().find_map(|&impl_did| {
|
||||
tcx.hir_trait_impls(trait_did).iter().find_map(|&impl_did| {
|
||||
if let Node::Item(Item {
|
||||
kind: ItemKind::Impl(hir::Impl { self_ty, .. }), ..
|
||||
}) = tcx.hir_node_by_def_id(impl_did)
|
||||
|
|
|
@ -99,11 +99,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let mut visitor = TypeParamSpanVisitor { tcx: self.tcx(), types: vec![] };
|
||||
match assoc_item.kind {
|
||||
ty::AssocKind::Fn => {
|
||||
let hir = self.tcx().hir();
|
||||
if let Some(hir_id) =
|
||||
assoc_item.def_id.as_local().map(|id| self.tcx().local_def_id_to_hir_id(id))
|
||||
{
|
||||
if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) {
|
||||
if let Some(decl) = self.tcx().hir_fn_decl_by_hir_id(hir_id) {
|
||||
visitor.visit_fn_decl(decl);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,10 +64,10 @@ pub fn find_param_with_region<'tcx>(
|
|||
_ => {}
|
||||
}
|
||||
|
||||
let body = hir.maybe_body_owned_by(def_id)?;
|
||||
let body = tcx.hir_maybe_body_owned_by(def_id)?;
|
||||
|
||||
let owner_id = hir.body_owner(body.id());
|
||||
let fn_decl = hir.fn_decl_by_hir_id(owner_id)?;
|
||||
let owner_id = tcx.hir_body_owner(body.id());
|
||||
let fn_decl = tcx.hir_fn_decl_by_hir_id(owner_id)?;
|
||||
let poly_fn_sig = tcx.fn_sig(id).instantiate_identity();
|
||||
|
||||
let fn_sig = tcx.liberate_late_bound_regions(id, poly_fn_sig);
|
||||
|
|
|
@ -624,7 +624,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
self.tcx.hir().maybe_body_owned_by(cause.body_id).and_then(|body| {
|
||||
self.tcx.hir_maybe_body_owned_by(cause.body_id).and_then(|body| {
|
||||
IfVisitor { err_span: span, found_if: false }
|
||||
.visit_body(&body)
|
||||
.is_break()
|
||||
|
|
|
@ -316,7 +316,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
if let Some(ty::GenericArgKind::Type(_)) = arg.map(|arg| arg.unpack())
|
||||
&& let Some(body) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id)
|
||||
&& let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id)
|
||||
{
|
||||
let mut expr_finder = FindExprBySpan::new(span, self.tcx);
|
||||
expr_finder.visit_expr(&body.value);
|
||||
|
|
|
@ -367,7 +367,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
(span.shrink_to_lo(), format!("(")),
|
||||
(span.shrink_to_hi(), format!(" as {})", cand.self_ty())),
|
||||
]
|
||||
} else if let Some(body) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id) {
|
||||
} else if let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) {
|
||||
let mut expr_finder = FindExprBySpan::new(span, self.tcx);
|
||||
expr_finder.visit_expr(body.value);
|
||||
if let Some(expr) = expr_finder.result &&
|
||||
|
|
|
@ -876,7 +876,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
span.remove_mark();
|
||||
}
|
||||
let mut expr_finder = FindExprBySpan::new(span, self.tcx);
|
||||
let Some(body) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id) else {
|
||||
let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) else {
|
||||
return;
|
||||
};
|
||||
expr_finder.visit_expr(body.value);
|
||||
|
@ -1347,8 +1347,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
// Issue #104961, we need to add parentheses properly for compound expressions
|
||||
// for example, `x.starts_with("hi".to_string() + "you")`
|
||||
// should be `x.starts_with(&("hi".to_string() + "you"))`
|
||||
let Some(body) =
|
||||
self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id)
|
||||
let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
@ -1447,7 +1446,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
span.remove_mark();
|
||||
}
|
||||
let mut expr_finder = super::FindExprBySpan::new(span, self.tcx);
|
||||
let Some(body) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id) else {
|
||||
let Some(body) = self.tcx.hir_maybe_body_owned_by(obligation.cause.body_id) else {
|
||||
return false;
|
||||
};
|
||||
expr_finder.visit_expr(body.value);
|
||||
|
@ -1766,7 +1765,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
err.children.clear();
|
||||
|
||||
let span = obligation.cause.span;
|
||||
let body = self.tcx.hir().body_owned_by(obligation.cause.body_id);
|
||||
let body = self.tcx.hir_body_owned_by(obligation.cause.body_id);
|
||||
|
||||
let mut visitor = ReturnsVisitor::default();
|
||||
visitor.visit_body(&body);
|
||||
|
@ -2300,7 +2299,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
);
|
||||
|
||||
let coroutine_body =
|
||||
coroutine_did.as_local().and_then(|def_id| hir.maybe_body_owned_by(def_id));
|
||||
coroutine_did.as_local().and_then(|def_id| self.tcx.hir_maybe_body_owned_by(def_id));
|
||||
let mut visitor = AwaitsVisitor::default();
|
||||
if let Some(body) = coroutine_body {
|
||||
visitor.visit_body(&body);
|
||||
|
@ -4130,7 +4129,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
};
|
||||
suggest_restriction(
|
||||
tcx,
|
||||
hir.body_owner_def_id(body_id),
|
||||
tcx.hir_body_owner_def_id(body_id),
|
||||
generics,
|
||||
&format!("type parameter `{ty}`"),
|
||||
err,
|
||||
|
@ -4352,7 +4351,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
term: ty.into(),
|
||||
}),
|
||||
));
|
||||
let body_def_id = self.tcx.hir().enclosing_body_owner(body_id);
|
||||
let body_def_id = self.tcx.hir_enclosing_body_owner(body_id);
|
||||
// Add `<ExprTy as Iterator>::Item = _` obligation.
|
||||
ocx.register_obligation(Obligation::misc(
|
||||
self.tcx,
|
||||
|
|
|
@ -109,7 +109,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
|
|||
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
fn collect_taits_declared_in_body(&mut self) {
|
||||
let body = self.tcx.hir().body_owned_by(self.item).value;
|
||||
let body = self.tcx.hir_body_owned_by(self.item).value;
|
||||
struct TaitInBodyFinder<'a, 'tcx> {
|
||||
collector: &'a mut OpaqueTypeCollector<'tcx>,
|
||||
}
|
||||
|
|
|
@ -2121,7 +2121,7 @@ impl Discriminant {
|
|||
/// simplified
|
||||
pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> Option<String> {
|
||||
self.expr
|
||||
.map(|body| rendered_const(tcx, tcx.hir_body(body), tcx.hir().body_owner_def_id(body)))
|
||||
.map(|body| rendered_const(tcx, tcx.hir_body(body), tcx.hir_body_owner_def_id(body)))
|
||||
}
|
||||
pub(crate) fn value(&self, tcx: TyCtxt<'_>, with_underscores: bool) -> String {
|
||||
print_evaluated_const(tcx, self.value, with_underscores, false).unwrap()
|
||||
|
@ -2417,7 +2417,7 @@ impl ConstantKind {
|
|||
ConstantKind::Path { ref path } => path.to_string(),
|
||||
ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id),
|
||||
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
|
||||
rendered_const(tcx, tcx.hir_body(body), tcx.hir().body_owner_def_id(body))
|
||||
rendered_const(tcx, tcx.hir_body(body), tcx.hir_body_owner_def_id(body))
|
||||
}
|
||||
ConstantKind::Infer { .. } => "_".to_string(),
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
|
|||
match n.kind() {
|
||||
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args: _ }) => {
|
||||
let s = if let Some(def) = def.as_local() {
|
||||
rendered_const(cx.tcx, cx.tcx.hir().body_owned_by(def), def)
|
||||
rendered_const(cx.tcx, cx.tcx.hir_body_owned_by(def), def)
|
||||
} else {
|
||||
inline::print_inlined_const(cx.tcx, def)
|
||||
};
|
||||
|
|
|
@ -304,8 +304,7 @@ pub(crate) fn create_config(
|
|||
return tcx.typeck(typeck_root_def_id);
|
||||
}
|
||||
|
||||
let hir = tcx.hir();
|
||||
let body = hir.body_owned_by(def_id);
|
||||
let body = tcx.hir_body_owned_by(def_id);
|
||||
debug!("visiting body for {def_id:?}");
|
||||
EmitIgnoredResolutionErrors::new(tcx).visit_body(body);
|
||||
(rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id)
|
||||
|
@ -335,14 +334,14 @@ pub(crate) fn run_global_ctxt(
|
|||
|
||||
// NOTE: These are copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
|
||||
let _ = tcx.sess.time("wf_checking", || {
|
||||
tcx.hir().try_par_for_each_module(|module| tcx.ensure_ok().check_mod_type_wf(module))
|
||||
tcx.try_par_hir_for_each_module(|module| tcx.ensure_ok().check_mod_type_wf(module))
|
||||
});
|
||||
|
||||
tcx.dcx().abort_if_errors();
|
||||
|
||||
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
|
||||
tcx.sess.time("check_mod_attrs", || {
|
||||
tcx.hir().for_each_module(|module| tcx.ensure_ok().check_mod_attrs(module))
|
||||
tcx.hir_for_each_module(|module| tcx.ensure_ok().check_mod_attrs(module))
|
||||
});
|
||||
rustc_passes::stability::check_unused_or_stable_features(tcx);
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ impl<'tcx> HirCollector<'tcx> {
|
|||
pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> {
|
||||
let tcx = self.tcx;
|
||||
self.visit_testable("".to_string(), CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID), |this| {
|
||||
tcx.hir().walk_toplevel_module(this)
|
||||
tcx.hir_walk_toplevel_module(this)
|
||||
});
|
||||
self.collector.tests
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ pub(crate) fn collect_spans_and_sources(
|
|||
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
|
||||
|
||||
if generate_link_to_definition {
|
||||
tcx.hir().walk_toplevel_module(&mut visitor);
|
||||
tcx.hir_walk_toplevel_module(&mut visitor);
|
||||
}
|
||||
let sources = sources::collect_local_sources(tcx, src_root, krate);
|
||||
(sources, visitor.matches)
|
||||
|
@ -173,18 +173,18 @@ impl SpanMapVisitor<'_> {
|
|||
}
|
||||
|
||||
fn infer_id(&mut self, hir_id: HirId, expr_hir_id: Option<HirId>, span: Span) {
|
||||
let hir = self.tcx.hir();
|
||||
let body_id = hir.enclosing_body_owner(hir_id);
|
||||
let tcx = self.tcx;
|
||||
let body_id = tcx.hir_enclosing_body_owner(hir_id);
|
||||
// FIXME: this is showing error messages for parts of the code that are not
|
||||
// compiled (because of cfg)!
|
||||
//
|
||||
// See discussion in https://github.com/rust-lang/rust/issues/69426#issuecomment-1019412352
|
||||
let typeck_results = self.tcx.typeck_body(hir.body_owned_by(body_id).id());
|
||||
let typeck_results = tcx.typeck_body(tcx.hir_body_owned_by(body_id).id());
|
||||
// Interestingly enough, for method calls, we need the whole expression whereas for static
|
||||
// method/function calls, we need the call expression specifically.
|
||||
if let Some(def_id) = typeck_results.type_dependent_def_id(expr_hir_id.unwrap_or(hir_id)) {
|
||||
let link = if def_id.as_local().is_some() {
|
||||
LinkFromSrc::Local(rustc_span(def_id, self.tcx))
|
||||
LinkFromSrc::Local(rustc_span(def_id, tcx))
|
||||
} else {
|
||||
LinkFromSrc::External(def_id)
|
||||
};
|
||||
|
|
|
@ -846,7 +846,7 @@ fn convert_static(
|
|||
is_unsafe: safety.is_unsafe(),
|
||||
expr: stat
|
||||
.expr
|
||||
.map(|e| rendered_const(tcx, tcx.hir_body(e), tcx.hir().body_owner_def_id(e)))
|
||||
.map(|e| rendered_const(tcx, tcx.hir_body(e), tcx.hir_body_owner_def_id(e)))
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,8 +135,7 @@ where
|
|||
// If we visit an item that contains an expression outside a function body,
|
||||
// then we need to exit before calling typeck (which will panic). See
|
||||
// test/run-make/rustdoc-scrape-examples-invalid-expr for an example.
|
||||
let hir = tcx.hir();
|
||||
if hir.maybe_body_owned_by(ex.hir_id.owner.def_id).is_none() {
|
||||
if tcx.hir_maybe_body_owned_by(ex.hir_id.owner.def_id).is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -302,7 +301,7 @@ pub(crate) fn run(
|
|||
// Run call-finder on all items
|
||||
let mut calls = FxIndexMap::default();
|
||||
let mut finder = FindCalls { calls: &mut calls, cx, target_crates, bin_crate };
|
||||
tcx.hir().visit_all_item_likes_in_crate(&mut finder);
|
||||
tcx.hir_visit_all_item_likes_in_crate(&mut finder);
|
||||
|
||||
// The visitor might have found a type error, which we need to
|
||||
// promote to a fatal error
|
||||
|
|
|
@ -52,11 +52,10 @@ declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
|
|||
|
||||
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
let hir = cx.tcx.hir();
|
||||
// NOTE: this is different from `clippy_utils::is_inside_always_const_context`.
|
||||
// Inline const supports type inference.
|
||||
let is_parent_const = matches!(
|
||||
hir.body_const_context(hir.body_owner_def_id(body.id())),
|
||||
cx.tcx.hir_body_const_context(cx.tcx.hir_body_owner_def_id(body.id())),
|
||||
Some(ConstContext::Const { inline: false } | ConstContext::Static(_))
|
||||
);
|
||||
let mut visitor = NumericFallbackVisitor::new(cx, is_parent_const);
|
||||
|
|
|
@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
|
|||
if let ItemKind::Enum(def, _) = &item.kind {
|
||||
for var in def.variants {
|
||||
if let Some(anon_const) = &var.disr_expr {
|
||||
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
|
||||
let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body);
|
||||
let mut ty = cx.tcx.type_of(def_id.to_def_id()).instantiate_identity();
|
||||
let constant = cx
|
||||
.tcx
|
||||
|
|
|
@ -39,7 +39,7 @@ fn report(cx: &LateContext<'_>, param: &GenericParam<'_>, generics: &Generics<'_
|
|||
|
||||
pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body: &'tcx Body<'_>, hir_id: HirId) {
|
||||
if let FnKind::ItemFn(_, generics, _) = kind
|
||||
&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()
|
||||
&& cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public()
|
||||
&& !is_in_test(cx.tcx, hir_id)
|
||||
{
|
||||
for param in generics.params {
|
||||
|
@ -57,7 +57,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
|
|||
&& let hir::Impl { of_trait, .. } = *impl_
|
||||
&& of_trait.is_none()
|
||||
&& let body = cx.tcx.hir_body(body_id)
|
||||
&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()
|
||||
&& cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public()
|
||||
&& !is_in_test(cx.tcx, impl_item.hir_id())
|
||||
{
|
||||
for param in impl_item.generics.params {
|
||||
|
|
|
@ -22,7 +22,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored
|
|||
&& let Some(did) = trait_item_def_id_of_impl(items, item.owner_id)
|
||||
&& !is_from_ignored_trait(trait_ref, ignored_traits)
|
||||
{
|
||||
let mut param_idents_iter = cx.tcx.hir().body_param_names(body_id);
|
||||
let mut param_idents_iter = cx.tcx.hir_body_param_names(body_id);
|
||||
let mut default_param_idents_iter = cx.tcx.fn_arg_names(did).iter().copied();
|
||||
|
||||
let renames = RenamedFnArgs::new(&mut default_param_idents_iter, &mut param_idents_iter);
|
||||
|
|
|
@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
|
|||
&& exprs.iter_mut().partition_in_place(|i| path_to_local(i).is_some()) == 2
|
||||
&& !expr.span.in_external_macro(cx.sess().source_map())
|
||||
&& (
|
||||
is_not_const(cx.tcx, cx.tcx.hir().enclosing_body_owner(expr.hir_id).into())
|
||||
is_not_const(cx.tcx, cx.tcx.hir_enclosing_body_owner(expr.hir_id).into())
|
||||
|| self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY)
|
||||
)
|
||||
&& let [first, second, const_1, const_2] = exprs
|
||||
|
|
|
@ -58,8 +58,7 @@ pub(super) fn check<'tcx>(
|
|||
unwrap_or_span: unwrap_arg.span,
|
||||
};
|
||||
|
||||
let map = cx.tcx.hir();
|
||||
let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id));
|
||||
let body = cx.tcx.hir_body_owned_by(cx.tcx.hir_enclosing_body_owner(expr.hir_id));
|
||||
|
||||
// Visit the body, and return if we've found a reference
|
||||
if reference_visitor.visit_body(body).is_break() {
|
||||
|
|
|
@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> {
|
|||
if self
|
||||
.possible_borrowers
|
||||
.last()
|
||||
.is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir().body_owner_def_id(body.id()))
|
||||
.is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir_body_owner_def_id(body.id()))
|
||||
{
|
||||
self.possible_borrowers.pop();
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ fn referent_used_exactly_once<'tcx>(
|
|||
&& let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind
|
||||
&& !place.is_indirect_first_projection()
|
||||
{
|
||||
let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id);
|
||||
let body_owner_local_def_id = cx.tcx.hir_enclosing_body_owner(reference.hir_id);
|
||||
if possible_borrowers
|
||||
.last()
|
||||
.is_none_or(|&(local_def_id, _)| local_def_id != body_owner_local_def_id)
|
||||
|
|
|
@ -352,7 +352,7 @@ impl MutablyUsedVariablesCtxt<'_> {
|
|||
fn is_in_unsafe_block(&self, item: HirId) -> bool {
|
||||
let hir = self.tcx.hir();
|
||||
for (parent, node) in hir.parent_iter(item) {
|
||||
if let Some(fn_sig) = hir.fn_sig_by_hir_id(parent) {
|
||||
if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) {
|
||||
return fn_sig.header.is_unsafe();
|
||||
} else if let Node::Block(block) = node {
|
||||
if matches!(block.rules, BlockCheckMode::UnsafeBlock(_)) {
|
||||
|
|
|
@ -349,10 +349,10 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
|
|||
}
|
||||
|
||||
fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
|
||||
let body_owner = cx.tcx.hir().body_owner(body.id());
|
||||
let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id());
|
||||
let body_owner = cx.tcx.hir_body_owner(body.id());
|
||||
let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id());
|
||||
|
||||
let body_owner_kind = cx.tcx.hir().body_owner_kind(body_owner_def_id);
|
||||
let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id);
|
||||
if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind {
|
||||
let body_span = cx.tcx.hir().span_with_body(body_owner);
|
||||
if let Some(span) = self.const_span
|
||||
|
@ -365,7 +365,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
|
|||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
|
||||
let body_owner = cx.tcx.hir().body_owner(body.id());
|
||||
let body_owner = cx.tcx.hir_body_owner(body.id());
|
||||
let body_span = cx.tcx.hir().span(body_owner);
|
||||
if let Some(span) = self.const_span
|
||||
&& span.contains(body_span)
|
||||
|
|
|
@ -68,10 +68,10 @@ impl Context {
|
|||
}
|
||||
|
||||
pub fn enter_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
|
||||
let body_owner = cx.tcx.hir().body_owner(body.id());
|
||||
let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id());
|
||||
let body_owner = cx.tcx.hir_body_owner(body.id());
|
||||
let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id());
|
||||
|
||||
match cx.tcx.hir().body_owner_kind(body_owner_def_id) {
|
||||
match cx.tcx.hir_body_owner_kind(body_owner_def_id) {
|
||||
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => {
|
||||
let body_span = cx.tcx.hir().span_with_body(body_owner);
|
||||
|
||||
|
@ -87,7 +87,7 @@ impl Context {
|
|||
}
|
||||
|
||||
pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
|
||||
let body_owner = cx.tcx.hir().body_owner(body.id());
|
||||
let body_owner = cx.tcx.hir_body_owner(body.id());
|
||||
let body_span = cx.tcx.hir().span_with_body(body_owner);
|
||||
|
||||
if let Some(span) = self.const_span {
|
||||
|
|
|
@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
|
|||
/// assert_static(closure);
|
||||
/// ```
|
||||
fn is_by_value_closure_capture(cx: &LateContext<'_>, redefinition: HirId, root_variable: HirId) -> bool {
|
||||
let closure_def_id = cx.tcx.hir().enclosing_body_owner(redefinition);
|
||||
let closure_def_id = cx.tcx.hir_enclosing_body_owner(redefinition);
|
||||
|
||||
cx.tcx.is_closure_like(closure_def_id.to_def_id())
|
||||
&& cx.tcx.closure_captures(closure_def_id).iter().any(|c| {
|
||||
|
|
|
@ -149,17 +149,15 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
|
|||
}
|
||||
|
||||
fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
|
||||
let hir = cx.tcx.hir();
|
||||
let owner_id = hir.body_owner_def_id(body.id());
|
||||
if !matches!(hir.body_owner_kind(owner_id), BodyOwnerKind::Closure) {
|
||||
let owner_id = cx.tcx.hir_body_owner_def_id(body.id());
|
||||
if !matches!(cx.tcx.hir_body_owner_kind(owner_id), BodyOwnerKind::Closure) {
|
||||
self.bindings.push((FxHashMap::default(), owner_id));
|
||||
}
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
|
||||
let hir = cx.tcx.hir();
|
||||
if !matches!(
|
||||
hir.body_owner_kind(hir.body_owner_def_id(body.id())),
|
||||
cx.tcx.hir_body_owner_kind(cx.tcx.hir_body_owner_def_id(body.id())),
|
||||
BodyOwnerKind::Closure
|
||||
) {
|
||||
self.bindings.pop();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue