Skip to content

Commit 090f21e

Browse files
committed
fix some suspicious TypeFolder patterns
1 parent 4d14c66 commit 090f21e

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

src/librustc/mir/mod.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -1906,12 +1906,18 @@ pub enum Place<'tcx> {
19061906

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

1915+
BraceStructTypeFoldableImpl! {
1916+
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
1917+
def_id, ty
1918+
}
1919+
}
1920+
19151921
impl_stable_hash_for!(struct Static<'tcx> {
19161922
def_id,
19171923
ty
@@ -3285,23 +3291,12 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
32853291
}
32863292
}
32873293

3288-
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
3289-
// TODO: this doesn't look correct!
3290-
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
3291-
-> Result<Self, F::Error>
3292-
{
3293-
match self {
3294-
&Place::Projection(ref p) => Ok(Place::Projection(p.fold_with(folder)?)),
3295-
_ => Ok(self.clone()),
3296-
}
3297-
}
3298-
3299-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> Result<(), V::Error> {
3300-
if let &Place::Projection(ref p) = self {
3301-
p.visit_with(visitor)
3302-
} else {
3303-
Ok(())
3304-
}
3294+
EnumTypeFoldableImpl! {
3295+
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
3296+
(Place::Local)(local),
3297+
(Place::Static)(statik),
3298+
(Place::Promoted)(promoted),
3299+
(Place::Projection)(projection),
33053300
}
33063301
}
33073302

@@ -3426,8 +3421,6 @@ where
34263421
}
34273422
}
34283423

3429-
CloneTypeFoldableImpls! { Field, }
3430-
34313424
BraceStructTypeFoldableImpl! {
34323425
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
34333426
span, ty, user_ty, literal

src/librustc/traits/structural_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,8 @@ impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx
771771
}
772772

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

src/librustc/ty/structural_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CloneTypeFoldableAndLiftImpls! {
4141
::rustc_target::spec::abi::Abi,
4242
crate::mir::Local,
4343
crate::mir::Promoted,
44+
crate::mir::Field,
4445
crate::traits::Reveal,
4546
crate::ty::adjustment::AutoBorrowMutability,
4647
crate::ty::AdtKind,

0 commit comments

Comments
 (0)