Skip to content

Commit

Permalink
Rollup merge of rust-lang#94849 - ouz-a:master4, r=oli-obk
Browse files Browse the repository at this point in the history
Check var scope if it exist

Fixes rust-lang#92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error
  • Loading branch information
Dylan-DPC authored Apr 15, 2022
2 parents 6f82524 + dc97080 commit 3d5dc41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/loops/needless_range_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(
if let Some(indexed_extent) = indexed_extent {
let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id);
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);
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;
}
Expand Down Expand Up @@ -262,7 +262,7 @@ 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 extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id).unwrap();
if index_used_directly {
self.indexed_directly.insert(
seqvar.segments[0].ident.name,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {

fn is_shadow(cx: &LateContext<'_>, owner: LocalDefId, first: ItemLocalId, second: ItemLocalId) -> bool {
let scope_tree = cx.tcx.region_scope_tree(owner.to_def_id());
let first_scope = scope_tree.var_scope(first);
let second_scope = scope_tree.var_scope(second);
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)
}

Expand Down

0 comments on commit 3d5dc41

Please sign in to comment.