@@ -19,13 +19,6 @@ pub use self::TypeOrigin::*;
19
19
pub use self :: ValuePairs :: * ;
20
20
pub use self :: fixup_err:: * ;
21
21
pub use middle:: ty:: IntVarValue ;
22
- pub use self :: resolve:: resolve_and_force_all_but_regions;
23
- pub use self :: resolve:: { force_all, not_regions} ;
24
- pub use self :: resolve:: { force_ivar} ;
25
- pub use self :: resolve:: { force_tvar, force_rvar} ;
26
- pub use self :: resolve:: { resolve_ivar, resolve_all} ;
27
- pub use self :: resolve:: { resolve_nested_tvar} ;
28
- pub use self :: resolve:: { resolve_rvar} ;
29
22
pub use self :: skolemize:: TypeSkolemizer ;
30
23
31
24
use middle:: subst;
@@ -47,7 +40,6 @@ use util::ppaux::{trait_ref_to_string, Repr};
47
40
use self :: coercion:: Coerce ;
48
41
use self :: combine:: { Combine , CombineFields } ;
49
42
use self :: region_inference:: { RegionVarBindings , RegionSnapshot } ;
50
- use self :: resolve:: { resolver} ;
51
43
use self :: equate:: Equate ;
52
44
use self :: sub:: Sub ;
53
45
use self :: lub:: Lub ;
@@ -453,22 +445,6 @@ pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
453
445
} )
454
446
}
455
447
456
- // See comment on the type `resolve_state` below
457
- pub fn resolve_type < ' a , ' tcx > ( cx : & InferCtxt < ' a , ' tcx > ,
458
- span : Option < Span > ,
459
- a : Ty < ' tcx > ,
460
- modes : uint )
461
- -> fres < Ty < ' tcx > > {
462
- let mut resolver = resolver ( cx, modes, span) ;
463
- cx. commit_unconditionally ( || resolver. resolve_type_chk ( a) )
464
- }
465
-
466
- pub fn resolve_region ( cx : & InferCtxt , r : ty:: Region , modes : uint )
467
- -> fres < ty:: Region > {
468
- let mut resolver = resolver ( cx, modes, None ) ;
469
- resolver. resolve_region_chk ( r)
470
- }
471
-
472
448
trait then < ' tcx > {
473
449
fn then < T , F > ( & self , f : F ) -> Result < T , ty:: type_err < ' tcx > > where
474
450
T : Clone ,
@@ -835,20 +811,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
835
811
trait_ref_to_string ( self . tcx , & t)
836
812
}
837
813
838
- pub fn contains_unbound_type_variables ( & self , typ : Ty < ' tcx > ) -> Ty < ' tcx > {
839
- match resolve_type ( self ,
840
- None ,
841
- typ, resolve_nested_tvar | resolve_ivar) {
842
- Ok ( new_type) => new_type,
843
- Err ( _) => typ
844
- }
845
- }
846
-
847
814
pub fn shallow_resolve ( & self , typ : Ty < ' tcx > ) -> Ty < ' tcx > {
848
815
match typ. sty {
849
816
ty:: ty_infer( ty:: TyVar ( v) ) => {
817
+ // Not entirely obvious: if `typ` is a type variable,
818
+ // it can be resolved to an int/float variable, which
819
+ // can then be recursively resolved, hence the
820
+ // recursion. Note though that we prevent type
821
+ // variables from unifying to other type variables
822
+ // directly (though they may be embedded
823
+ // structurally), and we prevent cycles in any case,
824
+ // so this recursion should always be of very limited
825
+ // depth.
850
826
self . type_variables . borrow ( )
851
827
. probe ( v)
828
+ . map ( |t| self . shallow_resolve ( t) )
852
829
. unwrap_or ( typ)
853
830
}
854
831
@@ -869,10 +846,33 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
869
846
}
870
847
871
848
pub fn resolve_type_vars_if_possible < T : TypeFoldable < ' tcx > > ( & self , value : & T ) -> T {
872
- let mut r = resolve:: DeepTypeResolver :: new ( self ) ;
849
+ /*!
850
+ * Where possible, replaces type/int/float variables in
851
+ * `value` with their final value. Note that region variables
852
+ * are unaffected. If a type variable has not been unified, it
853
+ * is left as is. This is an idempotent operation that does
854
+ * not affect inference state in any way and so you can do it
855
+ * at will.
856
+ */
857
+
858
+ let mut r = resolve:: OpportunisticTypeResolver :: new ( self ) ;
873
859
value. fold_with ( & mut r)
874
860
}
875
861
862
+ pub fn fully_resolve < T : TypeFoldable < ' tcx > > ( & self , value : & T ) -> fres < T > {
863
+ /*!
864
+ * Attempts to resolve all type/region variables in
865
+ * `value`. Region inference must have been run already (e.g.,
866
+ * by calling `resolve_regions_and_report_errors`). If some
867
+ * variable was never unified, an `Err` results.
868
+ *
869
+ * This method is idempotent, but it not typically not invoked
870
+ * except during the writeback phase.
871
+ */
872
+
873
+ resolve:: fully_resolve ( self , value)
874
+ }
875
+
876
876
// [Note-Type-error-reporting]
877
877
// An invariant is that anytime the expected or actual type is ty_err (the special
878
878
// error type, meaning that an error occurred when typechecking this expression),
0 commit comments