Skip to content

Commit

Permalink
View can use the faster hashing and equality checks on Ty instead of …
Browse files Browse the repository at this point in the history
…the inner type
  • Loading branch information
Marwes committed Jan 10, 2020
1 parent fba7f77 commit c243723
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/librustc/ty/view.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
fmt,
hash::{Hash, Hasher},
marker::PhantomData,
};
use std::{fmt, marker::PhantomData};

use syntax::ast;

Expand All @@ -17,35 +13,12 @@ pub use self::ViewKind::*;
/// `View<'tcx, T>` contains a value of `T` but stores the `Ty<'tcx>` ptr that contains the `T`
/// This allows for cheap access to the `Ty<'tcx>` without needing to ask the type interner or
/// losing the `T` type.
#[derive(TypeFoldable, Lift)]
#[derive(TypeFoldable, Eq, PartialEq, Hash, Lift)]
pub struct View<'tcx, T> {
ty: Ty<'tcx>,
_marker: PhantomData<T>,
}

impl<'tcx, T> PartialEq for View<'tcx, T>
where
T: PartialEq + TyDeref<'tcx>,
{
fn eq(&self, other: &Self) -> bool {
**self == **other
}
}

impl<'tcx, T> Eq for View<'tcx, T> where T: Eq + TyDeref<'tcx> {}

impl<'tcx, T> Hash for View<'tcx, T>
where
T: Hash + TyDeref<'tcx>,
{
fn hash<H>(&self, hasher: &mut H)
where
H: Hasher,
{
(**self).hash(hasher)
}
}

impl<T> Copy for View<'_, T> {}

impl<T> Clone for View<'_, T> {
Expand Down

0 comments on commit c243723

Please sign in to comment.