in starlark/src/analysis/names.rs [146:177]
fn unused_variable(codemap: &CodeMap, scope: &Scope, top: bool, res: &mut Vec<LintT<NameWarning>>) {
let mut warnings = HashMap::new();
for (x, (typ, span)) in &scope.bound {
let exported = top && *typ == Assigner::Assign && !x.starts_with('_');
let ignored = !top && x.starts_with('_');
// We don't want to warn about exported things or ignored things
if !exported && !ignored {
warnings.insert(x, (*typ, *span));
}
}
for x in &scope.inner {
match x {
Bind::Set(..) => {}
Bind::Get(x) => {
warnings.remove(&x.node);
}
Bind::Scope(scope) => {
unused_variable(codemap, scope, false, res);
for x in scope.free.keys() {
warnings.remove(x);
}
}
Bind::Flow => {}
}
}
for (name, (typ, span)) in warnings {
res.push(NameWarning::unused(typ, codemap, span, name.clone()))
}
}