Move some Map methods onto TyCtxt.
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
This commit is contained in:
parent
fc532c5b32
commit
8cf9eea5b3
102 changed files with 146 additions and 150 deletions
|
|
@ -192,7 +192,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) {
|
|||
},
|
||||
ExprKind::Closure(&Closure { body, .. }) => (
|
||||
Pat::Str(""),
|
||||
expr_search_pat_inner(tcx, tcx.hir().body(body).value, outer_span).1,
|
||||
expr_search_pat_inner(tcx, tcx.hir_body(body).value, outer_span).1,
|
||||
),
|
||||
ExprKind::Block(
|
||||
Block {
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
|
|||
Some(val)
|
||||
}
|
||||
},
|
||||
PatExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir().body(*body).value),
|
||||
PatExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir_body(*body).value),
|
||||
PatExprKind::Path(qpath) => self.qpath(qpath, pat_expr.hir_id),
|
||||
}
|
||||
}
|
||||
|
|
@ -483,7 +483,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
|
|||
/// Simple constant folding: Insert an expression, get a constant or none.
|
||||
fn expr(&self, e: &Expr<'_>) -> Option<Constant<'tcx>> {
|
||||
match e.kind {
|
||||
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir().body(body).value),
|
||||
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.tcx.hir_body(body).value),
|
||||
ExprKind::DropTemps(e) => self.expr(e),
|
||||
ExprKind::Path(ref qpath) => self.qpath(qpath, e.hir_id),
|
||||
ExprKind::Block(block, _) => self.block(block),
|
||||
|
|
@ -550,7 +550,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
|
|||
/// leaves the local crate.
|
||||
pub fn eval_is_empty(&self, e: &Expr<'_>) -> Option<bool> {
|
||||
match e.kind {
|
||||
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(self.tcx.hir().body(body).value),
|
||||
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.eval_is_empty(self.tcx.hir_body(body).value),
|
||||
ExprKind::DropTemps(e) => self.eval_is_empty(e),
|
||||
ExprKind::Path(ref qpath) => {
|
||||
if !self
|
||||
|
|
@ -645,7 +645,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> {
|
|||
Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => {
|
||||
// Check if this constant is based on `cfg!(..)`,
|
||||
// which is NOT constant for our purposes.
|
||||
if let Some(node) = self.tcx.hir().get_if_local(def_id)
|
||||
if let Some(node) = self.tcx.hir_get_if_local(def_id)
|
||||
&& let Node::Item(Item {
|
||||
kind: ItemKind::Const(.., body_id),
|
||||
..
|
||||
|
|
|
|||
|
|
@ -273,8 +273,8 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||
self.inner.cx.tcx.typeck_body(right),
|
||||
));
|
||||
let res = self.eq_expr(
|
||||
self.inner.cx.tcx.hir().body(left).value,
|
||||
self.inner.cx.tcx.hir().body(right).value,
|
||||
self.inner.cx.tcx.hir_body(left).value,
|
||||
self.inner.cx.tcx.hir_body(right).value,
|
||||
);
|
||||
self.inner.maybe_typeck_results = old_maybe_typeck_results;
|
||||
res
|
||||
|
|
@ -906,7 +906,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||
}) => {
|
||||
std::mem::discriminant(&capture_clause).hash(&mut self.s);
|
||||
// closures inherit TypeckResults
|
||||
self.hash_expr(self.cx.tcx.hir().body(body).value);
|
||||
self.hash_expr(self.cx.tcx.hir_body(body).value);
|
||||
},
|
||||
ExprKind::ConstBlock(ref l_id) => {
|
||||
self.hash_body(l_id.body);
|
||||
|
|
@ -1316,7 +1316,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||
pub fn hash_body(&mut self, body_id: BodyId) {
|
||||
// swap out TypeckResults when hashing a body
|
||||
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body_id));
|
||||
self.hash_expr(self.cx.tcx.hir().body(body_id).value);
|
||||
self.hash_expr(self.cx.tcx.hir_body(body_id).value);
|
||||
self.maybe_typeck_results = old_maybe_typeck_results;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -652,8 +652,6 @@ fn non_local_item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol)
|
|||
}
|
||||
|
||||
fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symbol) -> Vec<Res> {
|
||||
let hir = tcx.hir();
|
||||
|
||||
let root_mod;
|
||||
let item_kind = match tcx.hir_node_by_def_id(local_id) {
|
||||
Node::Crate(r#mod) => {
|
||||
|
|
@ -677,7 +675,7 @@ fn local_item_children_by_name(tcx: TyCtxt<'_>, local_id: LocalDefId, name: Symb
|
|||
ItemKind::Mod(r#mod) => r#mod
|
||||
.item_ids
|
||||
.iter()
|
||||
.filter_map(|&item_id| res(hir.item(item_id).ident, item_id.owner_id))
|
||||
.filter_map(|&item_id| res(tcx.hir_item(item_id).ident, item_id.owner_id))
|
||||
.collect(),
|
||||
ItemKind::Impl(r#impl) => r#impl
|
||||
.items
|
||||
|
|
@ -944,7 +942,7 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
|||
ExprKind::Tup(items) | ExprKind::Array(items) => items.iter().all(|x| is_default_equivalent(cx, x)),
|
||||
ExprKind::Repeat(x, len) => {
|
||||
if let ConstArgKind::Anon(anon_const) = len.kind
|
||||
&& let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind
|
||||
&& let ExprKind::Lit(const_lit) = cx.tcx.hir_body(anon_const.body).value.kind
|
||||
&& let LitKind::Int(v, _) = const_lit.node
|
||||
&& v <= 32
|
||||
&& is_default_equivalent(cx, x)
|
||||
|
|
@ -974,7 +972,7 @@ fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: &
|
|||
ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec),
|
||||
ExprKind::Repeat(_, len) => {
|
||||
if let ConstArgKind::Anon(anon_const) = len.kind
|
||||
&& let ExprKind::Lit(const_lit) = cx.tcx.hir().body(anon_const.body).value.kind
|
||||
&& let ExprKind::Lit(const_lit) = cx.tcx.hir_body(anon_const.body).value.kind
|
||||
&& let LitKind::Int(v, _) = const_lit.node
|
||||
{
|
||||
return v == 0 && is_path_diagnostic_item(cx, ty, sym::Vec);
|
||||
|
|
@ -1424,7 +1422,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
|
|||
| Node::ImplItem(&ImplItem {
|
||||
kind: ImplItemKind::Fn(_, eid),
|
||||
..
|
||||
}) => match cx.tcx.hir().body(eid).value.kind {
|
||||
}) => match cx.tcx.hir_body(eid).value.kind {
|
||||
ExprKind::Block(block, _) => Some(block),
|
||||
_ => None,
|
||||
},
|
||||
|
|
@ -2067,7 +2065,7 @@ pub fn get_async_fn_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'t
|
|||
..
|
||||
},
|
||||
_,
|
||||
) = tcx.hir().body(body).value.kind
|
||||
) = tcx.hir_body(body).value.kind
|
||||
{
|
||||
return Some(expr);
|
||||
}
|
||||
|
|
@ -2175,7 +2173,7 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>)
|
|||
ExprKind::Closure(&Closure { body, fn_decl, .. })
|
||||
if fn_decl.inputs.iter().all(|ty| matches!(ty.kind, TyKind::Infer(()))) =>
|
||||
{
|
||||
is_body_identity_function(cx, cx.tcx.hir().body(body))
|
||||
is_body_identity_function(cx, cx.tcx.hir_body(body))
|
||||
},
|
||||
ExprKind::Path(QPath::Resolved(_, path))
|
||||
if path.segments.iter().all(|seg| seg.infer_args)
|
||||
|
|
@ -2197,7 +2195,7 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>)
|
|||
/// errors.
|
||||
pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir().body(body)),
|
||||
ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir_body(body)),
|
||||
_ => path_def_id(cx, expr).is_some_and(|id| cx.tcx.is_diagnostic_item(sym::convert_identity, id)),
|
||||
}
|
||||
}
|
||||
|
|
@ -2552,9 +2550,9 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Sym
|
|||
Entry::Occupied(entry) => f(entry.get()),
|
||||
Entry::Vacant(entry) => {
|
||||
let mut names = Vec::new();
|
||||
for id in tcx.hir().module_items(module) {
|
||||
for id in tcx.hir_module_free_items(module) {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Const)
|
||||
&& let item = tcx.hir().item(id)
|
||||
&& let item = tcx.hir_item(id)
|
||||
&& let ItemKind::Const(ty, _generics, _body) = item.kind
|
||||
{
|
||||
if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind {
|
||||
|
|
@ -2932,7 +2930,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU
|
|||
#[allow(unreachable_patterns)]
|
||||
Some(ControlFlow::Break(_)) => unreachable!("type of node is ControlFlow<!>"),
|
||||
None => ExprUseCtxt {
|
||||
node: Node::Crate(cx.tcx.hir().root_module()),
|
||||
node: Node::Crate(cx.tcx.hir_root_module()),
|
||||
child_id: HirId::INVALID,
|
||||
adjustments: &[],
|
||||
is_ty_unified: true,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub fn get_spans(
|
|||
idx: usize,
|
||||
replacements: &[(&'static str, &'static str)],
|
||||
) -> Option<Vec<(Span, Cow<'static, str>)>> {
|
||||
if let Some(body) = opt_body_id.map(|id| cx.tcx.hir().body(id)) {
|
||||
if let Some(body) = opt_body_id.map(|id| cx.tcx.hir_body(id)) {
|
||||
if let PatKind::Binding(_, binding_id, _, _) = strip_pat_refs(body.params[idx].pat).kind {
|
||||
extract_clone_suggestions(cx, binding_id, replacements, body)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -809,7 +809,7 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti
|
|||
fn_decl, def_id, body, ..
|
||||
}) = closure.kind
|
||||
{
|
||||
let closure_body = cx.tcx.hir().body(body);
|
||||
let closure_body = cx.tcx.hir_body(body);
|
||||
// is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
|
||||
// a type annotation is present if param `kind` is different from `TyKind::Infer`
|
||||
let closure_arg_is_type_annotated_double_ref = if let TyKind::Ref(_, MutTy { ty, .. }) = fn_decl.inputs[0].kind
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ where
|
|||
|
||||
/// Checks if the given resolved path is used in the given body.
|
||||
pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool {
|
||||
for_each_expr(cx, cx.tcx.hir().body(body).value, |e| {
|
||||
for_each_expr(cx, cx.tcx.hir_body(body).value, |e| {
|
||||
if let ExprKind::Path(p) = &e.kind {
|
||||
if cx.qpath_res(p, e.hir_id) == res {
|
||||
return ControlFlow::Break(());
|
||||
|
|
@ -456,7 +456,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
fn visit_nested_item(&mut self, id: ItemId) -> Self::Result {
|
||||
if let ItemKind::Impl(i) = &self.cx.tcx.hir().item(id).kind
|
||||
if let ItemKind::Impl(i) = &self.cx.tcx.hir_item(id).kind
|
||||
&& i.safety.is_unsafe()
|
||||
{
|
||||
ControlFlow::Break(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue