Skip to content

Commit 2f25078

Browse files
try to cache region_scope_tree as a query
1 parent 286b717 commit 2f25078

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ pub(super) fn check<'tcx>(
5555
// ensure that the indexed variable was declared before the loop, see #601
5656
if let Some(indexed_extent) = indexed_extent {
5757
let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id);
58-
let parent_body_id = cx
59-
.tcx
60-
.hir()
61-
.body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(parent_def_id));
62-
let region_scope_tree = &cx.tcx.typeck_body(parent_body_id).region_scope_tree;
58+
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
6359
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap();
6460
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
6561
return;
@@ -282,14 +278,9 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
282278
match res {
283279
Res::Local(hir_id) => {
284280
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
285-
let parent_body_id = self.cx
286-
.tcx
287-
.hir()
288-
.body_owned_by(self.cx.tcx.hir().local_def_id_to_hir_id(parent_def_id));
289281
let extent = self.cx
290282
.tcx
291-
.typeck_body(parent_body_id)
292-
.region_scope_tree
283+
.region_scope_tree(parent_def_id)
293284
.var_scope(hir_id.local_id)
294285
.unwrap();
295286
if index_used_directly {

clippy_lints/src/shadow.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ fn is_shadow(
162162
first: ItemLocalId,
163163
second: ItemLocalId,
164164
) -> bool {
165-
let scope_tree = &cx
166-
.tcx
167-
.typeck_body(cx.tcx.hir().body_owned_by(cx.tcx.hir().local_def_id_to_hir_id(owner)))
168-
.region_scope_tree;
165+
let scope_tree = cx.tcx.region_scope_tree(owner);
169166
let first_scope = scope_tree.var_scope(first).unwrap();
170167
let second_scope = scope_tree.var_scope(second).unwrap();
171168
scope_tree.is_subscope_of(second_scope, first_scope)

0 commit comments

Comments
 (0)