Skip to content

Commit f9808ea

Browse files
committed
Create a visitor for TypeFoldables and use it to implement RegionEscape and HasTypeFlags (fixes #20298)
1 parent 5daa753 commit f9808ea

File tree

19 files changed

+534
-690
lines changed

19 files changed

+534
-690
lines changed

src/librustc/middle/implicator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
404404
}
405405

406406
fn fully_normalize<T>(&self, value: &T) -> Result<T,ErrorReported>
407-
where T : TypeFoldable<'tcx> + ty::HasTypeFlags
407+
where T : TypeFoldable<'tcx>
408408
{
409409
let value =
410410
traits::fully_normalize(self.infcx,

src/librustc/middle/infer/combine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
318318
}
319319
}
320320
_ => {
321-
ty::fold::super_fold_ty(self, t)
321+
t.fold_subitems_with(self)
322322
}
323323
}
324324
}

src/librustc/middle/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
169169
ty::TyTuple(..) |
170170
ty::TyProjection(..) |
171171
ty::TyParam(..) => {
172-
ty::fold::super_fold_ty(self, t)
172+
t.fold_subitems_with(self)
173173
}
174174
}
175175
}

src/librustc/middle/infer/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ pub struct CombinedSnapshot {
512512
}
513513

514514
pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T
515-
where T : TypeFoldable<'tcx> + HasTypeFlags
515+
where T : TypeFoldable<'tcx>
516516
{
517517
debug!("normalize_associated_type(t={:?})", value);
518518

@@ -546,7 +546,7 @@ pub fn drain_fulfillment_cx_or_panic<'a,'tcx,T>(span: Span,
546546
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
547547
result: &T)
548548
-> T
549-
where T : TypeFoldable<'tcx> + HasTypeFlags
549+
where T : TypeFoldable<'tcx>
550550
{
551551
match drain_fulfillment_cx(infcx, fulfill_cx, result) {
552552
Ok(v) => v,
@@ -570,7 +570,7 @@ pub fn drain_fulfillment_cx<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
570570
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
571571
result: &T)
572572
-> Result<T,Vec<traits::FulfillmentError<'tcx>>>
573-
where T : TypeFoldable<'tcx> + HasTypeFlags
573+
where T : TypeFoldable<'tcx>
574574
{
575575
debug!("drain_fulfillment_cx(result={:?})",
576576
result);
@@ -929,7 +929,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
929929
snapshot: &CombinedSnapshot,
930930
value: &T)
931931
-> T
932-
where T : TypeFoldable<'tcx> + HasTypeFlags
932+
where T : TypeFoldable<'tcx>
933933
{
934934
/*! See `higher_ranked::plug_leaks` */
935935

@@ -1201,7 +1201,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12011201
}
12021202

12031203
pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
1204-
where T: TypeFoldable<'tcx> + HasTypeFlags
1204+
where T: TypeFoldable<'tcx>
12051205
{
12061206
/*!
12071207
* Where possible, replaces type/int/float variables in

src/librustc/middle/infer/resolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for OpportunisticTypeResolver<'a, 'tcx
4040
t // micro-optimize -- if there is nothing in this type that this fold affects...
4141
} else {
4242
let t0 = self.infcx.shallow_resolve(t);
43-
ty::fold::super_fold_ty(self, t0)
43+
t0.fold_subitems_with(self)
4444
}
4545
}
4646
}
@@ -68,7 +68,7 @@ impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for OpportunisticTypeAndRegionResolver
6868
t // micro-optimize -- if there is nothing in this type that this fold affects...
6969
} else {
7070
let t0 = self.infcx.shallow_resolve(t);
71-
ty::fold::super_fold_ty(self, t0)
71+
t0.fold_subitems_with(self)
7272
}
7373
}
7474

@@ -133,7 +133,7 @@ impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
133133
t));
134134
}
135135
_ => {
136-
ty::fold::super_fold_ty(self, t)
136+
t.fold_subitems_with(self)
137137
}
138138
}
139139
}

src/librustc/middle/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
674674
self.ty_for_param(p, t)
675675
}
676676
_ => {
677-
ty::fold::super_fold_ty(self, t)
677+
t.fold_subitems_with(self)
678678
}
679679
};
680680

src/librustc/middle/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
185185
pub fn report_overflow_error<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
186186
obligation: &Obligation<'tcx, T>)
187187
-> !
188-
where T: fmt::Display + TypeFoldable<'tcx> + HasTypeFlags
188+
where T: fmt::Display + TypeFoldable<'tcx>
189189
{
190190
let predicate =
191191
infcx.resolve_type_vars_if_possible(&obligation.predicate);

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ pub fn fully_normalize<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
470470
cause: ObligationCause<'tcx>,
471471
value: &T)
472472
-> Result<T, Vec<FulfillmentError<'tcx>>>
473-
where T : TypeFoldable<'tcx> + HasTypeFlags
473+
where T : TypeFoldable<'tcx>
474474
{
475475
debug!("normalize_param_env(value={:?})", value);
476476

src/librustc/middle/traits/project.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub fn normalize<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tcx>,
202202
cause: ObligationCause<'tcx>,
203203
value: &T)
204204
-> Normalized<'tcx, T>
205-
where T : TypeFoldable<'tcx> + HasTypeFlags
205+
where T : TypeFoldable<'tcx>
206206
{
207207
normalize_with_depth(selcx, cause, 0, value)
208208
}
@@ -213,7 +213,7 @@ pub fn normalize_with_depth<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tc
213213
depth: usize,
214214
value: &T)
215215
-> Normalized<'tcx, T>
216-
where T : TypeFoldable<'tcx> + HasTypeFlags
216+
where T : TypeFoldable<'tcx>
217217
{
218218
let mut normalizer = AssociatedTypeNormalizer::new(selcx, cause, depth);
219219
let result = normalizer.fold(value);
@@ -245,7 +245,7 @@ impl<'a,'b,'tcx> AssociatedTypeNormalizer<'a,'b,'tcx> {
245245
}
246246
}
247247

248-
fn fold<T:TypeFoldable<'tcx> + HasTypeFlags>(&mut self, value: &T) -> T {
248+
fn fold<T:TypeFoldable<'tcx>>(&mut self, value: &T) -> T {
249249
let value = self.selcx.infcx().resolve_type_vars_if_possible(value);
250250

251251
if !value.has_projection_types() {
@@ -273,7 +273,7 @@ impl<'a,'b,'tcx> TypeFolder<'tcx> for AssociatedTypeNormalizer<'a,'b,'tcx> {
273273
// normalize it when we instantiate those bound regions (which
274274
// should occur eventually).
275275

276-
let ty = ty::fold::super_fold_ty(self, ty);
276+
let ty = ty.fold_subitems_with(self);
277277
match ty.sty {
278278
ty::TyProjection(ref data) if !data.has_escaping_regions() => { // (*)
279279

src/librustc/middle/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
965965
match *candidate {
966966
Ok(Some(_)) | Err(_) => true,
967967
Ok(None) => {
968-
cache_fresh_trait_pred.0.input_types().has_infer_types()
968+
cache_fresh_trait_pred.0.trait_ref.substs.types.has_infer_types()
969969
}
970970
}
971971
}

0 commit comments

Comments
 (0)