Skip to content

Commit 72605cd

Browse files
committed
Remove some unused type folders.
I'm surprised the compiler doesn't warn about these. It appears having an `impl` on a struct is enough to avoid a warning about it never being constructed.
1 parent bbc4009 commit 72605cd

File tree

4 files changed

+4
-145
lines changed

4 files changed

+4
-145
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

+1-26
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use rustc_middle::hir::nested_filter;
88
use rustc_middle::ty::print::with_forced_trimmed_paths;
99
use rustc_middle::ty::subst::InternalSubsts;
1010
use rustc_middle::ty::util::IntTypeExt;
11-
use rustc_middle::ty::{
12-
self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable,
13-
TypeVisitableExt,
14-
};
11+
use rustc_middle::ty::{self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
1512
use rustc_span::symbol::Ident;
1613
use rustc_span::{Span, DUMMY_SP};
1714

@@ -874,28 +871,6 @@ fn infer_placeholder_type<'a>(
874871
item_ident: Ident,
875872
kind: &'static str,
876873
) -> Ty<'a> {
877-
// Attempts to make the type nameable by turning FnDefs into FnPtrs.
878-
struct MakeNameable<'tcx> {
879-
tcx: TyCtxt<'tcx>,
880-
}
881-
882-
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for MakeNameable<'tcx> {
883-
fn interner(&self) -> TyCtxt<'tcx> {
884-
self.tcx
885-
}
886-
887-
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
888-
let ty = match *ty.kind() {
889-
ty::FnDef(def_id, substs) => {
890-
self.tcx.mk_fn_ptr(self.tcx.fn_sig(def_id).subst(self.tcx, substs))
891-
}
892-
_ => ty,
893-
};
894-
895-
ty.super_fold_with(self)
896-
}
897-
}
898-
899874
let ty = tcx.diagnostic_only_typeck(def_id).node_type(body_id.hir_id);
900875

901876
// If this came from a free `const` or `static mut?` item,

compiler/rustc_hir_typeck/src/op.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_middle::ty::adjustment::{
1212
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
1313
};
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
15-
use rustc_middle::ty::{
16-
self, IsSuggestable, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
17-
};
15+
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
1816
use rustc_session::errors::ExprParenthesesNeeded;
1917
use rustc_span::source_map::Spanned;
2018
use rustc_span::symbol::{sym, Ident};
@@ -965,21 +963,3 @@ fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: hir::BinOp) -> bool
965963
}
966964
}
967965
}
968-
969-
struct TypeParamEraser<'a, 'tcx>(&'a FnCtxt<'a, 'tcx>, Span);
970-
971-
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for TypeParamEraser<'_, 'tcx> {
972-
fn interner(&self) -> TyCtxt<'tcx> {
973-
self.0.tcx
974-
}
975-
976-
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
977-
match ty.kind() {
978-
ty::Param(_) => self.0.next_ty_var(TypeVariableOrigin {
979-
kind: TypeVariableOriginKind::MiscVariable,
980-
span: self.1,
981-
}),
982-
_ => ty.super_fold_with(self),
983-
}
984-
}
985-
}

compiler/rustc_middle/src/ty/sty.rs

+2-77
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
77
use crate::ty::visit::ValidateBoundVars;
88
use crate::ty::InferTy::*;
99
use crate::ty::{
10-
self, AdtDef, Discr, FallibleTypeFolder, Term, Ty, TyCtxt, TypeFlags, TypeFoldable,
11-
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
10+
self, AdtDef, Discr, Term, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable,
11+
TypeVisitableExt, TypeVisitor,
1212
};
1313
use crate::ty::{List, ParamEnv};
1414
use hir::def::DefKind;
@@ -1156,81 +1156,6 @@ where
11561156
}
11571157
}
11581158

1159-
struct SkipBindersAt<'tcx> {
1160-
tcx: TyCtxt<'tcx>,
1161-
index: ty::DebruijnIndex,
1162-
}
1163-
1164-
impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for SkipBindersAt<'tcx> {
1165-
type Error = ();
1166-
1167-
fn interner(&self) -> TyCtxt<'tcx> {
1168-
self.tcx
1169-
}
1170-
1171-
fn try_fold_binder<T>(&mut self, t: Binder<'tcx, T>) -> Result<Binder<'tcx, T>, Self::Error>
1172-
where
1173-
T: ty::TypeFoldable<TyCtxt<'tcx>>,
1174-
{
1175-
self.index.shift_in(1);
1176-
let value = t.try_map_bound(|t| t.try_fold_with(self));
1177-
self.index.shift_out(1);
1178-
value
1179-
}
1180-
1181-
fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
1182-
if !ty.has_escaping_bound_vars() {
1183-
Ok(ty)
1184-
} else if let ty::Bound(index, bv) = *ty.kind() {
1185-
if index == self.index {
1186-
Err(())
1187-
} else {
1188-
Ok(self.interner().mk_bound(index.shifted_out(1), bv))
1189-
}
1190-
} else {
1191-
ty.try_super_fold_with(self)
1192-
}
1193-
}
1194-
1195-
fn try_fold_region(&mut self, r: ty::Region<'tcx>) -> Result<ty::Region<'tcx>, Self::Error> {
1196-
if !r.has_escaping_bound_vars() {
1197-
Ok(r)
1198-
} else if let ty::ReLateBound(index, bv) = r.kind() {
1199-
if index == self.index {
1200-
Err(())
1201-
} else {
1202-
Ok(self.interner().mk_re_late_bound(index.shifted_out(1), bv))
1203-
}
1204-
} else {
1205-
r.try_super_fold_with(self)
1206-
}
1207-
}
1208-
1209-
fn try_fold_const(&mut self, ct: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self::Error> {
1210-
if !ct.has_escaping_bound_vars() {
1211-
Ok(ct)
1212-
} else if let ty::ConstKind::Bound(index, bv) = ct.kind() {
1213-
if index == self.index {
1214-
Err(())
1215-
} else {
1216-
Ok(self.interner().mk_const(
1217-
ty::ConstKind::Bound(index.shifted_out(1), bv),
1218-
ct.ty().try_fold_with(self)?,
1219-
))
1220-
}
1221-
} else {
1222-
ct.try_super_fold_with(self)
1223-
}
1224-
}
1225-
1226-
fn try_fold_predicate(
1227-
&mut self,
1228-
p: ty::Predicate<'tcx>,
1229-
) -> Result<ty::Predicate<'tcx>, Self::Error> {
1230-
if !p.has_escaping_bound_vars() { Ok(p) } else { p.try_super_fold_with(self) }
1231-
}
1232-
}
1233-
12341159
/// Represents the projection of an associated type.
12351160
///
12361161
/// For a projection, this would be `<Ty as Trait<...>>::N`.

compiler/rustc_trait_selection/src/traits/auto_trait.rs

-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::infer::InferCtxt;
99
use crate::traits::project::ProjectAndUnifyResult;
1010
use rustc_infer::infer::DefineOpaqueTypes;
1111
use rustc_middle::mir::interpret::ErrorHandled;
12-
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
1312
use rustc_middle::ty::visit::TypeVisitableExt;
1413
use rustc_middle::ty::{ImplPolarity, Region, RegionVid};
1514

@@ -851,23 +850,3 @@ impl<'tcx> AutoTraitFinder<'tcx> {
851850
infcx.freshen(p)
852851
}
853852
}
854-
855-
/// Replaces all ReVars in a type with ty::Region's, using the provided map
856-
pub struct RegionReplacer<'a, 'tcx> {
857-
vid_to_region: &'a FxHashMap<ty::RegionVid, ty::Region<'tcx>>,
858-
tcx: TyCtxt<'tcx>,
859-
}
860-
861-
impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for RegionReplacer<'a, 'tcx> {
862-
fn interner(&self) -> TyCtxt<'tcx> {
863-
self.tcx
864-
}
865-
866-
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
867-
(match *r {
868-
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
869-
_ => None,
870-
})
871-
.unwrap_or_else(|| r.super_fold_with(self))
872-
}
873-
}

0 commit comments

Comments
 (0)