Skip to content

Commit 3d5dc41

Browse files
authored
Rollup merge of rust-lang#94849 - ouz-a:master4, r=oli-obk
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
2 parents 6f82524 + dc97080 commit 3d5dc41

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

clippy_lints/src/loops/needless_range_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(
5959
if let Some(indexed_extent) = indexed_extent {
6060
let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id);
6161
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
62-
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id);
62+
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap();
6363
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
6464
return;
6565
}
@@ -262,7 +262,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
262262
match res {
263263
Res::Local(hir_id) => {
264264
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
265-
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
265+
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id).unwrap();
266266
if index_used_directly {
267267
self.indexed_directly.insert(
268268
seqvar.segments[0].ident.name,

clippy_lints/src/shadow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
160160

161161
fn is_shadow(cx: &LateContext<'_>, owner: LocalDefId, first: ItemLocalId, second: ItemLocalId) -> bool {
162162
let scope_tree = cx.tcx.region_scope_tree(owner.to_def_id());
163-
let first_scope = scope_tree.var_scope(first);
164-
let second_scope = scope_tree.var_scope(second);
163+
let first_scope = scope_tree.var_scope(first).unwrap();
164+
let second_scope = scope_tree.var_scope(second).unwrap();
165165
scope_tree.is_subscope_of(second_scope, first_scope)
166166
}
167167

0 commit comments

Comments
 (0)