mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-11 07:34:18 +00:00
try to cache region_scope_tree as a query
This commit is contained in:
parent
286b717808
commit
2f250783b1
2 changed files with 3 additions and 15 deletions
|
@ -55,11 +55,7 @@ pub(super) fn check<'tcx>(
|
|||
// ensure that the indexed variable was declared before the loop, see #601
|
||||
if let Some(indexed_extent) = indexed_extent {
|
||||
let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id);
|
||||
let parent_body_id = cx
|
||||
.tcx
|
||||
.hir()
|
||||
.body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(parent_def_id));
|
||||
let region_scope_tree = &cx.tcx.typeck_body(parent_body_id).region_scope_tree;
|
||||
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
|
||||
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap();
|
||||
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
|
||||
return;
|
||||
|
@ -282,14 +278,9 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
|||
match res {
|
||||
Res::Local(hir_id) => {
|
||||
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
|
||||
let parent_body_id = self.cx
|
||||
.tcx
|
||||
.hir()
|
||||
.body_owned_by(self.cx.tcx.hir().local_def_id_to_hir_id(parent_def_id));
|
||||
let extent = self.cx
|
||||
.tcx
|
||||
.typeck_body(parent_body_id)
|
||||
.region_scope_tree
|
||||
.region_scope_tree(parent_def_id)
|
||||
.var_scope(hir_id.local_id)
|
||||
.unwrap();
|
||||
if index_used_directly {
|
||||
|
|
|
@ -162,10 +162,7 @@ fn is_shadow(
|
|||
first: ItemLocalId,
|
||||
second: ItemLocalId,
|
||||
) -> bool {
|
||||
let scope_tree = &cx
|
||||
.tcx
|
||||
.typeck_body(cx.tcx.hir().body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(owner)))
|
||||
.region_scope_tree;
|
||||
let scope_tree = cx.tcx.region_scope_tree(owner);
|
||||
let first_scope = scope_tree.var_scope(first).unwrap();
|
||||
let second_scope = scope_tree.var_scope(second).unwrap();
|
||||
scope_tree.is_subscope_of(second_scope, first_scope)
|
||||
|
|
Loading…
Reference in a new issue