Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a visitor for TypeFoldables and use it to fix cleanup issue #20298 #30317

Merged
merged 3 commits into from
Jan 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/middle/implicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use middle::def_id::DefId;
use middle::infer::{InferCtxt, GenericKind};
use middle::subst::Substs;
use middle::traits;
use middle::ty::{self, RegionEscape, ToPredicate, Ty};
use middle::ty::{self, ToPredicate, Ty};
use middle::ty::fold::{TypeFoldable, TypeFolder};

use syntax::ast;
Expand Down Expand Up @@ -404,7 +404,7 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
}

fn fully_normalize<T>(&self, value: &T) -> Result<T,ErrorReported>
where T : TypeFoldable<'tcx> + ty::HasTypeFlags
where T : TypeFoldable<'tcx>
{
let value =
traits::fully_normalize(self.infcx,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'cx, 'tcx> ty::fold::TypeFolder<'tcx> for Generalizer<'cx, 'tcx> {
}
}
_ => {
ty::fold::super_fold_ty(self, t)
t.super_fold_with(self)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use middle::def_id::DefId;
use middle::infer::{self, TypeOrigin};
use middle::region;
use middle::subst;
use middle::ty::{self, Ty, HasTypeFlags};
use middle::ty::{self, Ty, TypeFoldable};
use middle::ty::{Region, ReFree};
use middle::ty::error::TypeError;

Expand Down Expand Up @@ -250,7 +250,7 @@ pub trait ErrorReporting<'tcx> {

fn values_str(&self, values: &ValuePairs<'tcx>) -> Option<String>;

fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + HasTypeFlags>(
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + TypeFoldable<'tcx>>(
&self,
exp_found: &ty::error::ExpectedFound<T>)
-> Option<String>;
Expand Down Expand Up @@ -575,7 +575,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
}
}

fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + HasTypeFlags>(
fn expected_found_str<T: fmt::Display + Resolvable<'tcx> + TypeFoldable<'tcx>>(
&self,
exp_found: &ty::error::ExpectedFound<T>)
-> Option<String>
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
//! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
//! inferencer knows "so far".

use middle::ty::{self, Ty, HasTypeFlags};
use middle::ty::fold::TypeFoldable;
use middle::ty::{self, Ty, TypeFoldable};
use middle::ty::fold::TypeFolder;
use std::collections::hash_map::{self, Entry};

Expand Down Expand Up @@ -169,7 +168,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
ty::TyTuple(..) |
ty::TyProjection(..) |
ty::TyParam(..) => {
ty::fold::super_fold_ty(self, t)
t.super_fold_with(self)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
use super::{CombinedSnapshot, InferCtxt, HigherRankedType, SkolemizationMap};
use super::combine::CombineFields;

use middle::ty::{self, Binder};
use middle::ty::{self, Binder, TypeFoldable};
use middle::ty::error::TypeError;
use middle::ty::fold::TypeFoldable;
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
use syntax::codemap::Span;
use util::nodemap::{FnvHashMap, FnvHashSet};
Expand Down Expand Up @@ -557,7 +556,7 @@ pub fn plug_leaks<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
snapshot: &CombinedSnapshot,
value: &T)
-> T
where T : TypeFoldable<'tcx> + ty::HasTypeFlags
where T : TypeFoldable<'tcx>
{
debug_assert!(leak_check(infcx, &skol_map, snapshot).is_ok());

Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use middle::subst::Subst;
use middle::traits;
use middle::ty::adjustment;
use middle::ty::{TyVid, IntVid, FloatVid};
use middle::ty::{self, Ty, HasTypeFlags};
use middle::ty::{self, Ty};
use middle::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
use middle::ty::fold::{TypeFolder, TypeFoldable};
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
Expand Down Expand Up @@ -512,7 +512,7 @@ pub struct CombinedSnapshot {
}

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

Expand Down Expand Up @@ -546,7 +546,7 @@ pub fn drain_fulfillment_cx_or_panic<'a,'tcx,T>(span: Span,
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
result: &T)
-> T
where T : TypeFoldable<'tcx> + HasTypeFlags
where T : TypeFoldable<'tcx>
{
match drain_fulfillment_cx(infcx, fulfill_cx, result) {
Ok(v) => v,
Expand All @@ -570,7 +570,7 @@ pub fn drain_fulfillment_cx<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
result: &T)
-> Result<T,Vec<traits::FulfillmentError<'tcx>>>
where T : TypeFoldable<'tcx> + HasTypeFlags
where T : TypeFoldable<'tcx>
{
debug!("drain_fulfillment_cx(result={:?})",
result);
Expand Down Expand Up @@ -929,7 +929,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
snapshot: &CombinedSnapshot,
value: &T)
-> T
where T : TypeFoldable<'tcx> + HasTypeFlags
where T : TypeFoldable<'tcx>
{
/*! See `higher_ranked::plug_leaks` */

Expand Down Expand Up @@ -1201,7 +1201,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}

pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
where T: TypeFoldable<'tcx> + HasTypeFlags
where T: TypeFoldable<'tcx>
{
/*!
* Where possible, replaces type/int/float variables in
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
// except according to those terms.

use super::{InferCtxt, FixupError, FixupResult};
use middle::ty::{self, Ty, HasTypeFlags};
use middle::ty::fold::{TypeFoldable};
use middle::ty::{self, Ty, TypeFoldable};

///////////////////////////////////////////////////////////////////////////
// OPPORTUNISTIC TYPE RESOLVER
Expand Down Expand Up @@ -40,7 +39,7 @@ impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for OpportunisticTypeResolver<'a, 'tcx
t // micro-optimize -- if there is nothing in this type that this fold affects...
} else {
let t0 = self.infcx.shallow_resolve(t);
ty::fold::super_fold_ty(self, t0)
t0.super_fold_with(self)
}
}
}
Expand Down Expand Up @@ -68,7 +67,7 @@ impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for OpportunisticTypeAndRegionResolver
t // micro-optimize -- if there is nothing in this type that this fold affects...
} else {
let t0 = self.infcx.shallow_resolve(t);
ty::fold::super_fold_ty(self, t0)
t0.super_fold_with(self)
}
}

Expand Down Expand Up @@ -133,7 +132,7 @@ impl<'a, 'tcx> ty::fold::TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
t));
}
_ => {
ty::fold::super_fold_ty(self, t)
t.super_fold_with(self)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use middle::def::DefFn;
use middle::def_id::DefId;
use middle::subst::{Subst, Substs, EnumeratedItems};
use middle::ty::{TransmuteRestriction, ctxt, TyBareFn};
use middle::ty::{self, Ty, HasTypeFlags};
use middle::ty::{self, Ty, TypeFoldable};

use std::fmt;

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::ParamSpace::*;
pub use self::RegionSubsts::*;

use middle::cstore;
use middle::ty::{self, Ty, HasTypeFlags, RegionEscape};
use middle::ty::{self, Ty};
use middle::ty::fold::{TypeFoldable, TypeFolder};

use serialize::{Encodable, Encoder, Decodable, Decoder};
Expand Down Expand Up @@ -674,7 +674,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
self.ty_for_param(p, t)
}
_ => {
ty::fold::super_fold_ty(self, t)
t.super_fold_with(self)
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ use super::{
use fmt_macros::{Parser, Piece, Position};
use middle::def_id::DefId;
use middle::infer::InferCtxt;
use middle::ty::{self, ToPredicate, HasTypeFlags, ToPolyTraitRef, TraitRef, Ty};
use middle::ty::{self, ToPredicate, ToPolyTraitRef, TraitRef, Ty, TypeFoldable};
use middle::ty::fast_reject;
use middle::ty::fold::TypeFoldable;
use util::nodemap::{FnvHashMap, FnvHashSet};

use std::cmp;
Expand Down Expand Up @@ -185,7 +184,7 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
pub fn report_overflow_error<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
obligation: &Obligation<'tcx, T>)
-> !
where T: fmt::Display + TypeFoldable<'tcx> + HasTypeFlags
where T: fmt::Display + TypeFoldable<'tcx>
{
let predicate =
infcx.resolve_type_vars_if_possible(&obligation.predicate);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use middle::infer::InferCtxt;
use middle::ty::{self, RegionEscape, Ty, HasTypeFlags};
use middle::ty::{self, Ty, TypeFoldable};

use syntax::ast;
use util::common::ErrorReported;
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ use dep_graph::DepNode;
use middle::def_id::DefId;
use middle::free_region::FreeRegionMap;
use middle::subst;
use middle::ty::{self, HasTypeFlags, Ty};
use middle::ty::{self, Ty, TypeFoldable};
use middle::ty::fast_reject;
use middle::ty::fold::TypeFoldable;
use middle::infer::{self, fixup_err_to_string, InferCtxt};

use std::rc::Rc;
Expand Down Expand Up @@ -470,7 +469,7 @@ pub fn fully_normalize<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
cause: ObligationCause<'tcx>,
value: &T)
-> Result<T, Vec<FulfillmentError<'tcx>>>
where T : TypeFoldable<'tcx> + HasTypeFlags
where T : TypeFoldable<'tcx>
{
debug!("normalize_param_env(value={:?})", value);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::elaborate_predicates;
use middle::def_id::DefId;
use middle::subst::{self, SelfSpace, TypeSpace};
use middle::traits;
use middle::ty::{self, HasTypeFlags, ToPolyTraitRef, Ty};
use middle::ty::{self, ToPolyTraitRef, Ty, TypeFoldable};
use std::rc::Rc;
use syntax::ast;

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::util;

use middle::infer::{self, TypeOrigin};
use middle::subst::Subst;
use middle::ty::{self, ToPredicate, RegionEscape, HasTypeFlags, ToPolyTraitRef, Ty};
use middle::ty::{self, ToPredicate, ToPolyTraitRef, Ty};
use middle::ty::fold::{TypeFoldable, TypeFolder};
use syntax::parse::token;
use util::common::FN_OUTPUT_NAME;
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn normalize<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tcx>,
cause: ObligationCause<'tcx>,
value: &T)
-> Normalized<'tcx, T>
where T : TypeFoldable<'tcx> + HasTypeFlags
where T : TypeFoldable<'tcx>
{
normalize_with_depth(selcx, cause, 0, value)
}
Expand All @@ -213,7 +213,7 @@ pub fn normalize_with_depth<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tc
depth: usize,
value: &T)
-> Normalized<'tcx, T>
where T : TypeFoldable<'tcx> + HasTypeFlags
where T : TypeFoldable<'tcx>
{
let mut normalizer = AssociatedTypeNormalizer::new(selcx, cause, depth);
let result = normalizer.fold(value);
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<'a,'b,'tcx> AssociatedTypeNormalizer<'a,'b,'tcx> {
}
}

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

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

let ty = ty::fold::super_fold_ty(self, ty);
let ty = ty.super_fold_with(self);
match ty.sty {
ty::TyProjection(ref data) if !data.has_escaping_regions() => { // (*)

Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ use middle::def_id::DefId;
use middle::infer;
use middle::infer::{InferCtxt, TypeFreshener, TypeOrigin};
use middle::subst::{Subst, Substs, TypeSpace};
use middle::ty::{self, ToPredicate, RegionEscape, ToPolyTraitRef, Ty, HasTypeFlags};
use middle::ty::{self, ToPredicate, ToPolyTraitRef, Ty, TypeFoldable};
use middle::ty::fast_reject;
use middle::ty::fold::TypeFoldable;
use middle::ty::relate::TypeRelation;

use std::cell::RefCell;
Expand Down Expand Up @@ -965,7 +964,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
match *candidate {
Ok(Some(_)) | Err(_) => true,
Ok(None) => {
cache_fresh_trait_pred.0.input_types().has_infer_types()
cache_fresh_trait_pred.0.trait_ref.substs.types.has_infer_types()
}
}
}
Expand Down
Loading