Skip to content

Commit

Permalink
fix some suspicious TypeFolder patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed Feb 16, 2019
1 parent 4d14c66 commit 090f21e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
33 changes: 13 additions & 20 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1906,12 +1906,18 @@ pub enum Place<'tcx> {

/// The `DefId` of a static, along with its normalized type (which is
/// stored to avoid requiring normalization when reading MIR).
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
pub struct Static<'tcx> {
pub def_id: DefId,
pub ty: Ty<'tcx>,
}

BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
def_id, ty
}
}

impl_stable_hash_for!(struct Static<'tcx> {
def_id,
ty
Expand Down Expand Up @@ -3285,23 +3291,12 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
}
}

impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
// TODO: this doesn't look correct!
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
-> Result<Self, F::Error>
{
match self {
&Place::Projection(ref p) => Ok(Place::Projection(p.fold_with(folder)?)),
_ => Ok(self.clone()),
}
}

fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> Result<(), V::Error> {
if let &Place::Projection(ref p) = self {
p.visit_with(visitor)
} else {
Ok(())
}
EnumTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
(Place::Local)(local),
(Place::Static)(statik),
(Place::Promoted)(promoted),
(Place::Projection)(projection),
}
}

Expand Down Expand Up @@ -3426,8 +3421,6 @@ where
}
}

CloneTypeFoldableImpls! { Field, }

BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
span, ty, user_ty, literal
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx
}

fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> Result<(), V::Error> {
// TODO: re-add param-env
self.predicate.visit_with(visitor)
self.predicate.visit_with(visitor)?;
self.param_env.visit_with(visitor)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CloneTypeFoldableAndLiftImpls! {
::rustc_target::spec::abi::Abi,
crate::mir::Local,
crate::mir::Promoted,
crate::mir::Field,
crate::traits::Reveal,
crate::ty::adjustment::AutoBorrowMutability,
crate::ty::AdtKind,
Expand Down

0 comments on commit 090f21e

Please sign in to comment.