Add a new Binding::is_unused method (#12729)

This commit is contained in:
Alex Waygood 2024-08-07 11:17:56 +01:00 committed by GitHub
parent b14fee9320
commit d380b37a09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 19 additions and 9 deletions

View file

@ -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`].

View file

@ -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,
}