@@ -1054,6 +1054,10 @@ pub enum FnOutput<'tcx> {
1054
1054
}
1055
1055
1056
1056
impl < ' tcx > FnOutput < ' tcx > {
1057
+ pub fn diverges ( & self ) -> bool {
1058
+ * self == FnDiverging
1059
+ }
1060
+
1057
1061
pub fn unwrap ( self ) -> Ty < ' tcx > {
1058
1062
match self {
1059
1063
ty:: FnConverging ( t) => t,
@@ -1062,6 +1066,14 @@ impl<'tcx> FnOutput<'tcx> {
1062
1066
}
1063
1067
}
1064
1068
1069
+ pub type PolyFnOutput < ' tcx > = Binder < FnOutput < ' tcx > > ;
1070
+
1071
+ impl < ' tcx > PolyFnOutput < ' tcx > {
1072
+ pub fn diverges ( & self ) -> bool {
1073
+ self . 0 . diverges ( )
1074
+ }
1075
+ }
1076
+
1065
1077
/// Signature of a function type, which I have arbitrarily
1066
1078
/// decided to use to refer to the input/output types.
1067
1079
///
@@ -1077,6 +1089,21 @@ pub struct FnSig<'tcx> {
1077
1089
1078
1090
pub type PolyFnSig < ' tcx > = Binder < FnSig < ' tcx > > ;
1079
1091
1092
+ impl < ' tcx > PolyFnSig < ' tcx > {
1093
+ pub fn inputs ( & self ) -> ty:: Binder < Vec < Ty < ' tcx > > > {
1094
+ ty:: Binder ( self . 0 . inputs . clone ( ) )
1095
+ }
1096
+ pub fn input ( & self , index : uint ) -> ty:: Binder < Ty < ' tcx > > {
1097
+ ty:: Binder ( self . 0 . inputs [ index] )
1098
+ }
1099
+ pub fn output ( & self ) -> ty:: Binder < FnOutput < ' tcx > > {
1100
+ ty:: Binder ( self . 0 . output . clone ( ) )
1101
+ }
1102
+ pub fn variadic ( & self ) -> bool {
1103
+ self . 0 . variadic
1104
+ }
1105
+ }
1106
+
1080
1107
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Show ) ]
1081
1108
pub struct ParamTy {
1082
1109
pub space : subst:: ParamSpace ,
@@ -4146,8 +4173,8 @@ pub fn ty_fn_abi(fty: Ty) -> abi::Abi {
4146
4173
}
4147
4174
4148
4175
// Type accessors for substructures of types
4149
- pub fn ty_fn_args < ' tcx > ( fty : Ty < ' tcx > ) -> & ' tcx [ Ty < ' tcx > ] {
4150
- ty_fn_sig ( fty) . 0 . inputs . as_slice ( )
4176
+ pub fn ty_fn_args < ' tcx > ( fty : Ty < ' tcx > ) -> ty :: Binder < Vec < Ty < ' tcx > > > {
4177
+ ty_fn_sig ( fty) . inputs ( )
4151
4178
}
4152
4179
4153
4180
pub fn ty_closure_store ( fty : Ty ) -> TraitStore {
@@ -4163,9 +4190,9 @@ pub fn ty_closure_store(fty: Ty) -> TraitStore {
4163
4190
}
4164
4191
}
4165
4192
4166
- pub fn ty_fn_ret < ' tcx > ( fty : Ty < ' tcx > ) -> FnOutput < ' tcx > {
4193
+ pub fn ty_fn_ret < ' tcx > ( fty : Ty < ' tcx > ) -> Binder < FnOutput < ' tcx > > {
4167
4194
match fty. sty {
4168
- ty_bare_fn( _, ref f) => f. sig . 0 . output ,
4195
+ ty_bare_fn( _, ref f) => f. sig . output ( ) ,
4169
4196
ref s => {
4170
4197
panic ! ( "ty_fn_ret() called on non-fn type: {:?}" , s)
4171
4198
}
@@ -4320,9 +4347,12 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
4320
4347
let method_call = MethodCall :: autoderef ( expr_id, i) ;
4321
4348
match method_type ( method_call) {
4322
4349
Some ( method_ty) => {
4323
- if let ty:: FnConverging ( result_type) = ty_fn_ret ( method_ty) {
4324
- adjusted_ty = result_type;
4325
- }
4350
+ // overloaded deref operators have all late-bound
4351
+ // regions fully instantiated and coverge
4352
+ let fn_ret =
4353
+ ty:: assert_no_late_bound_regions ( cx,
4354
+ & ty_fn_ret ( method_ty) ) ;
4355
+ adjusted_ty = fn_ret. unwrap ( ) ;
4326
4356
}
4327
4357
None => { }
4328
4358
}
@@ -5144,7 +5174,9 @@ impl<'tcx> VariantInfo<'tcx> {
5144
5174
match ast_variant. node . kind {
5145
5175
ast:: TupleVariantKind ( ref args) => {
5146
5176
let arg_tys = if args. len ( ) > 0 {
5147
- ty_fn_args ( ctor_ty) . iter ( ) . map ( |a| * a) . collect ( )
5177
+ // the regions in the argument types come from the
5178
+ // enum def'n, and hence will all be early bound
5179
+ ty:: assert_no_late_bound_regions ( cx, & ty_fn_args ( ctor_ty) )
5148
5180
} else {
5149
5181
Vec :: new ( )
5150
5182
} ;
@@ -5160,7 +5192,6 @@ impl<'tcx> VariantInfo<'tcx> {
5160
5192
} ;
5161
5193
} ,
5162
5194
ast:: StructVariantKind ( ref struct_def) => {
5163
-
5164
5195
let fields: & [ StructField ] = struct_def. fields . index ( & FullRange ) ;
5165
5196
5166
5197
assert ! ( fields. len( ) > 0 ) ;
@@ -5792,40 +5823,6 @@ pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool
5792
5823
return tbl[ tycat ( cx, ty) as uint ] [ opcat ( op) as uint ] ;
5793
5824
}
5794
5825
5795
- /// Returns an equivalent type with all the typedefs and self regions removed.
5796
- pub fn normalize_ty < ' tcx > ( cx : & ctxt < ' tcx > , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
5797
- let u = TypeNormalizer ( cx) . fold_ty ( ty) ;
5798
- return u;
5799
-
5800
- struct TypeNormalizer < ' a , ' tcx : ' a > ( & ' a ctxt < ' tcx > ) ;
5801
-
5802
- impl < ' a , ' tcx > TypeFolder < ' tcx > for TypeNormalizer < ' a , ' tcx > {
5803
- fn tcx ( & self ) -> & ctxt < ' tcx > { let TypeNormalizer ( c) = * self ; c }
5804
-
5805
- fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
5806
- match self . tcx ( ) . normalized_cache . borrow ( ) . get ( & ty) . cloned ( ) {
5807
- None => { }
5808
- Some ( u) => return u
5809
- }
5810
-
5811
- let t_norm = ty_fold:: super_fold_ty ( self , ty) ;
5812
- self . tcx ( ) . normalized_cache . borrow_mut ( ) . insert ( ty, t_norm) ;
5813
- return t_norm;
5814
- }
5815
-
5816
- fn fold_region ( & mut self , _: ty:: Region ) -> ty:: Region {
5817
- ty:: ReStatic
5818
- }
5819
-
5820
- fn fold_substs ( & mut self ,
5821
- substs : & subst:: Substs < ' tcx > )
5822
- -> subst:: Substs < ' tcx > {
5823
- subst:: Substs { regions : subst:: ErasedRegions ,
5824
- types : substs. types . fold_with ( self ) }
5825
- }
5826
- }
5827
- }
5828
-
5829
5826
// Returns the repeat count for a repeating vector expression.
5830
5827
pub fn eval_repeat_count ( tcx : & ctxt , count_expr : & ast:: Expr ) -> uint {
5831
5828
match const_eval:: eval_const_expr_partial ( tcx, count_expr) {
@@ -6205,7 +6202,7 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
6205
6202
mt. mutbl . hash ( state) ;
6206
6203
} ;
6207
6204
let fn_sig = |& : state: & mut sip:: SipState , sig : & Binder < FnSig < ' tcx > > | {
6208
- let sig = anonymize_late_bound_regions ( tcx, sig) ;
6205
+ let sig = anonymize_late_bound_regions ( tcx, sig) . 0 ;
6209
6206
for a in sig. inputs . iter ( ) { helper ( tcx, * a, svh, state) ; }
6210
6207
if let ty:: FnConverging ( output) = sig. output {
6211
6208
helper ( tcx, output, svh, state) ;
@@ -6266,7 +6263,7 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
6266
6263
did ( state, data. principal_def_id ( ) ) ;
6267
6264
hash ! ( data. bounds) ;
6268
6265
6269
- let principal = anonymize_late_bound_regions ( tcx, & data. principal ) ;
6266
+ let principal = anonymize_late_bound_regions ( tcx, & data. principal ) . 0 ;
6270
6267
for subty in principal. substs . types . iter ( ) {
6271
6268
helper ( tcx, * subty, svh, state) ;
6272
6269
}
@@ -6697,6 +6694,16 @@ pub fn binds_late_bound_regions<'tcx, T>(
6697
6694
count_late_bound_regions ( tcx, value) > 0
6698
6695
}
6699
6696
6697
+ pub fn assert_no_late_bound_regions < ' tcx , T > (
6698
+ tcx : & ty:: ctxt < ' tcx > ,
6699
+ value : & Binder < T > )
6700
+ -> T
6701
+ where T : TypeFoldable < ' tcx > + Repr < ' tcx > + Clone
6702
+ {
6703
+ assert ! ( !binds_late_bound_regions( tcx, value) ) ;
6704
+ value. 0 . clone ( )
6705
+ }
6706
+
6700
6707
/// Replace any late-bound regions bound in `value` with `'static`. Useful in trans but also
6701
6708
/// method lookup and a few other places where precise region relationships are not required.
6702
6709
pub fn erase_late_bound_regions < ' tcx , T > (
@@ -6719,14 +6726,14 @@ pub fn erase_late_bound_regions<'tcx, T>(
6719
6726
pub fn anonymize_late_bound_regions < ' tcx , T > (
6720
6727
tcx : & ctxt < ' tcx > ,
6721
6728
sig : & Binder < T > )
6722
- -> T
6729
+ -> Binder < T >
6723
6730
where T : TypeFoldable < ' tcx > + Repr < ' tcx > ,
6724
6731
{
6725
6732
let mut counter = 0 ;
6726
- replace_late_bound_regions ( tcx, sig, |_, db| {
6733
+ ty :: Binder ( replace_late_bound_regions ( tcx, sig, |_, db| {
6727
6734
counter += 1 ;
6728
6735
ReLateBound ( db, BrAnon ( counter) )
6729
- } ) . 0
6736
+ } ) . 0 )
6730
6737
}
6731
6738
6732
6739
/// Replaces the late-bound-regions in `value` that are bound by `value`.
0 commit comments