Skip to content

Commit 3d95cd8

Browse files
committed
fix some suspicious TypeFolder patterns
1 parent bf0e4cb commit 3d95cd8

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/librustc/mir/mod.rs

+31-24
Original file line numberDiff line numberDiff line change
@@ -1916,12 +1916,18 @@ pub enum PlaceBase<'tcx> {
19161916

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

1925+
BraceStructTypeFoldableImpl! {
1926+
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
1927+
def_id, ty
1928+
}
1929+
}
1930+
19251931
impl_stable_hash_for!(struct Static<'tcx> {
19261932
def_id,
19271933
ty
@@ -2046,24 +2052,32 @@ impl<'tcx> Place<'tcx> {
20462052
}
20472053
}
20482054

2049-
impl<'tcx> Debug for Place<'tcx> {
2055+
impl<'tcx> Debug for PlaceBase<'tcx> {
20502056
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
2051-
use self::Place::*;
2052-
20532057
match *self {
2054-
Base(PlaceBase::Local(id)) => write!(fmt, "{:?}", id),
2055-
Base(PlaceBase::Static(box self::Static { def_id, ty })) => write!(
2058+
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
2059+
PlaceBase::Static(box self::Static { def_id, ty }) => write!(
20562060
fmt,
20572061
"({}: {:?})",
20582062
ty::tls::with(|tcx| tcx.item_path_str(def_id)),
20592063
ty
20602064
),
2061-
Base(PlaceBase::Promoted(ref promoted)) => write!(
2065+
PlaceBase::Promoted(ref promoted) => write!(
20622066
fmt,
20632067
"({:?}: {:?})",
20642068
promoted.0,
20652069
promoted.1
20662070
),
2071+
}
2072+
}
2073+
}
2074+
2075+
impl<'tcx> Debug for Place<'tcx> {
2076+
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
2077+
use self::Place::*;
2078+
2079+
match *self {
2080+
Base(ref base) => Debug::fmt(base, fmt),
20672081
Projection(ref data) => match data.elem {
20682082
ProjectionElem::Downcast(ref adt_def, index) => {
20692083
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].ident)
@@ -3302,23 +3316,18 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
33023316
}
33033317
}
33043318

3305-
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
3306-
// TODO: this doesn't look correct!
3307-
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
3308-
-> Result<Self, F::Error>
3309-
{
3310-
match self {
3311-
&Place::Projection(ref p) => Ok(Place::Projection(p.fold_with(folder)?)),
3312-
_ => Ok(self.clone()),
3313-
}
3319+
EnumTypeFoldableImpl! {
3320+
impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
3321+
(Place::Base)(base),
3322+
(Place::Projection)(projection),
33143323
}
3324+
}
33153325

3316-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> Result<(), V::Error> {
3317-
if let &Place::Projection(ref p) = self {
3318-
p.visit_with(visitor)
3319-
} else {
3320-
Ok(())
3321-
}
3326+
EnumTypeFoldableImpl! {
3327+
impl<'tcx> TypeFoldable<'tcx> for PlaceBase<'tcx> {
3328+
(PlaceBase::Local)(local),
3329+
(PlaceBase::Static)(statik),
3330+
(PlaceBase::Promoted)(promoted),
33223331
}
33233332
}
33243333

@@ -3443,8 +3452,6 @@ where
34433452
}
34443453
}
34453454

3446-
CloneTypeFoldableImpls! { Field, }
3447-
34483455
BraceStructTypeFoldableImpl! {
34493456
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
34503457
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)