Remove RefEquality (#6393)

## Summary

See discussion in
https://github.com/astral-sh/ruff/pull/6351#discussion_r1284996979. We
can remove `RefEquality` entirely and instead use a text offset for
statement keys, since no two statements can start at the same text
offset.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-08-07 12:04:50 -04:00 committed by GitHub
parent 9328606843
commit c895252aae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 88 deletions

View file

@ -1,5 +1,3 @@
use std::ops::Deref;
use crate::{Expr, Stmt};
#[derive(Clone)]
@ -7,78 +5,3 @@ pub enum Node<'a> {
Stmt(&'a Stmt),
Expr(&'a Expr),
}
#[derive(Debug)]
pub struct RefEquality<'a, T>(pub &'a T);
impl<'a, T> RefEquality<'a, T> {
// More specific implementation that keeps the `'a` lifetime.
// It's otherwise the same as [`AsRef::as_ref`]
#[allow(clippy::should_implement_trait)]
pub fn as_ref(&self) -> &'a T {
self.0
}
}
impl<'a, T> AsRef<T> for RefEquality<'a, T> {
fn as_ref(&self) -> &T {
self.0
}
}
impl<'a, T> Clone for RefEquality<'a, T> {
fn clone(&self) -> Self {
*self
}
}
impl<'a, T> Copy for RefEquality<'a, T> {}
impl<'a, T> std::hash::Hash for RefEquality<'a, T> {
fn hash<H>(&self, state: &mut H)
where
H: std::hash::Hasher,
{
(self.0 as *const T).hash(state);
}
}
impl<'a, 'b, T> PartialEq<RefEquality<'b, T>> for RefEquality<'a, T> {
fn eq(&self, other: &RefEquality<'b, T>) -> bool {
std::ptr::eq(self.0, other.0)
}
}
impl<'a, T> Eq for RefEquality<'a, T> {}
impl<'a, T> Deref for RefEquality<'a, T> {
type Target = T;
fn deref(&self) -> &T {
self.0
}
}
impl<'a> From<&RefEquality<'a, Stmt>> for &'a Stmt {
fn from(r: &RefEquality<'a, Stmt>) -> Self {
r.0
}
}
impl<'a> From<&RefEquality<'a, Expr>> for &'a Expr {
fn from(r: &RefEquality<'a, Expr>) -> Self {
r.0
}
}
impl<'a> From<RefEquality<'a, Stmt>> for &'a Stmt {
fn from(r: RefEquality<'a, Stmt>) -> Self {
r.0
}
}
impl<'a> From<RefEquality<'a, Expr>> for &'a Expr {
fn from(r: RefEquality<'a, Expr>) -> Self {
r.0
}
}