Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ncMN authored and infrandomness committed May 30, 2022
1 parent 39231b4 commit db3d19c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 18 additions & 3 deletions clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,26 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
}
}

type Result<T> = std::result::Result<T, LifetimeError>;

#[derive(Debug, Clone)]
struct LifetimeError;

impl std::fmt::Display for LifetimeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Invalid lifetime")
}
}

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).unwrap();
let second_scope = scope_tree.var_scope(second).unwrap();
scope_tree.is_subscope_of(second_scope, first_scope)
if let Some(first_scope) = scope_tree.var_scope(first) {
if let Some(second_scope) = scope_tree.var_scope(second) {
return scope_tree.is_subscope_of(second_scope, first_scope);
}
}

false
}

fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span) {
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,11 @@ pub async fn foo2(_a: i32, _b: i64) {
let _b = _a;
}

fn ice_8748() {
let _ = [0; {
let x = 1;
if let Some(x) = Some(1) { x } else { 1 }
}];
}

fn main() {}

0 comments on commit db3d19c

Please sign in to comment.