diff options
| author | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2022-05-25 13:52:32 +0800 |
|---|---|---|
| committer | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2022-05-25 13:52:32 +0800 |
| commit | 4c6074fbb03d2cb3d175a8f71606fc264e30e8d3 (patch) | |
| tree | e8dc0cf88568af4e34927c287f324520a0c2ca03 /src | |
| parent | b2eba058e6e1c698723e47074561a30b50b5fa7a (diff) | |
| download | rust-4c6074fbb03d2cb3d175a8f71606fc264e30e8d3.tar.gz rust-4c6074fbb03d2cb3d175a8f71606fc264e30e8d3.zip | |
try to cache region_scope_tree as a query
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs | 13 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/shadow.rs | 5 |
2 files changed, 3 insertions, 15 deletions
diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs index e2b82f9fd02..4f85364965b 100644 --- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs @@ -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 { diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs index db32b8d740b..2a80e6f918d 100644 --- a/src/tools/clippy/clippy_lints/src/shadow.rs +++ b/src/tools/clippy/clippy_lints/src/shadow.rs @@ -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) |
