mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 00:20:22 +00:00
Add a new Binding::is_unused
method (#12729)
This commit is contained in:
parent
b14fee9320
commit
d380b37a09
9 changed files with 19 additions and 9 deletions
|
@ -36,9 +36,18 @@ pub struct Binding<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Binding<'a> {
|
||||
/// Return `true` if this [`Binding`] is unused.
|
||||
///
|
||||
/// This method is the opposite of [`Binding::is_used`].
|
||||
pub fn is_unused(&self) -> bool {
|
||||
self.references.is_empty()
|
||||
}
|
||||
|
||||
/// Return `true` if this [`Binding`] is used.
|
||||
///
|
||||
/// This method is the opposite of [`Binding::is_unused`].
|
||||
pub fn is_used(&self) -> bool {
|
||||
!self.references.is_empty()
|
||||
!self.is_unused()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all references for the current [`Binding`].
|
||||
|
|
|
@ -1455,7 +1455,7 @@ impl<'a> SemanticModel<'a> {
|
|||
.get_all(id)
|
||||
.map(|binding_id| self.binding(binding_id))
|
||||
.filter(|binding| binding.start() >= expr.start())
|
||||
.all(|binding| !binding.is_used())
|
||||
.all(Binding::is_unused)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue