@@ -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 ,
@@ -4145,8 +4172,8 @@ pub fn ty_fn_abi(fty: Ty) -> abi::Abi {
4145
4172
}
4146
4173
4147
4174
// Type accessors for substructures of types
4148
- pub fn ty_fn_args < ' tcx > ( fty : Ty < ' tcx > ) -> & ' tcx [ Ty < ' tcx > ] {
4149
- ty_fn_sig ( fty) . 0 . inputs . as_slice ( )
4175
+ pub fn ty_fn_args < ' tcx > ( fty : Ty < ' tcx > ) -> ty :: Binder < Vec < Ty < ' tcx > > > {
4176
+ ty_fn_sig ( fty) . inputs ( )
4150
4177
}
4151
4178
4152
4179
pub fn ty_closure_store ( fty : Ty ) -> TraitStore {
@@ -4162,9 +4189,9 @@ pub fn ty_closure_store(fty: Ty) -> TraitStore {
4162
4189
}
4163
4190
}
4164
4191
4165
- pub fn ty_fn_ret < ' tcx > ( fty : Ty < ' tcx > ) -> FnOutput < ' tcx > {
4192
+ pub fn ty_fn_ret < ' tcx > ( fty : Ty < ' tcx > ) -> Binder < FnOutput < ' tcx > > {
4166
4193
match fty. sty {
4167
- ty_bare_fn( _, ref f) => f. sig . 0 . output ,
4194
+ ty_bare_fn( _, ref f) => f. sig . output ( ) ,
4168
4195
ref s => {
4169
4196
panic ! ( "ty_fn_ret() called on non-fn type: {}" , s)
4170
4197
}
@@ -4319,9 +4346,12 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
4319
4346
let method_call = MethodCall :: autoderef ( expr_id, i) ;
4320
4347
match method_type ( method_call) {
4321
4348
Some ( method_ty) => {
4322
- if let ty:: FnConverging ( result_type) = ty_fn_ret ( method_ty) {
4323
- adjusted_ty = result_type;
4324
- }
4349
+ // overloaded deref operators have all late-bound
4350
+ // regions fully instantiated and coverge
4351
+ let fn_ret =
4352
+ ty:: assert_no_late_bound_regions ( cx,
4353
+ & ty_fn_ret ( method_ty) ) ;
4354
+ adjusted_ty = fn_ret. unwrap ( ) ;
4325
4355
}
4326
4356
None => { }
4327
4357
}
@@ -5143,7 +5173,9 @@ impl<'tcx> VariantInfo<'tcx> {
5143
5173
match ast_variant. node . kind {
5144
5174
ast:: TupleVariantKind ( ref args) => {
5145
5175
let arg_tys = if args. len ( ) > 0 {
5146
- ty_fn_args ( ctor_ty) . iter ( ) . map ( |a| * a) . collect ( )
5176
+ // the regions in the argument types come from the
5177
+ // enum def'n, and hence will all be early bound
5178
+ ty:: assert_no_late_bound_regions ( cx, & ty_fn_args ( ctor_ty) )
5147
5179
} else {
5148
5180
Vec :: new ( )
5149
5181
} ;
@@ -5159,7 +5191,6 @@ impl<'tcx> VariantInfo<'tcx> {
5159
5191
} ;
5160
5192
} ,
5161
5193
ast:: StructVariantKind ( ref struct_def) => {
5162
-
5163
5194
let fields: & [ StructField ] = struct_def. fields [ ] ;
5164
5195
5165
5196
assert ! ( fields. len( ) > 0 ) ;
@@ -5791,40 +5822,6 @@ pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool
5791
5822
return tbl[ tycat ( cx, ty) as uint ] [ opcat ( op) as uint ] ;
5792
5823
}
5793
5824
5794
- /// Returns an equivalent type with all the typedefs and self regions removed.
5795
- pub fn normalize_ty < ' tcx > ( cx : & ctxt < ' tcx > , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
5796
- let u = TypeNormalizer ( cx) . fold_ty ( ty) ;
5797
- return u;
5798
-
5799
- struct TypeNormalizer < ' a , ' tcx : ' a > ( & ' a ctxt < ' tcx > ) ;
5800
-
5801
- impl < ' a , ' tcx > TypeFolder < ' tcx > for TypeNormalizer < ' a , ' tcx > {
5802
- fn tcx ( & self ) -> & ctxt < ' tcx > { let TypeNormalizer ( c) = * self ; c }
5803
-
5804
- fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
5805
- match self . tcx ( ) . normalized_cache . borrow ( ) . get ( & ty) . cloned ( ) {
5806
- None => { }
5807
- Some ( u) => return u
5808
- }
5809
-
5810
- let t_norm = ty_fold:: super_fold_ty ( self , ty) ;
5811
- self . tcx ( ) . normalized_cache . borrow_mut ( ) . insert ( ty, t_norm) ;
5812
- return t_norm;
5813
- }
5814
-
5815
- fn fold_region ( & mut self , _: ty:: Region ) -> ty:: Region {
5816
- ty:: ReStatic
5817
- }
5818
-
5819
- fn fold_substs ( & mut self ,
5820
- substs : & subst:: Substs < ' tcx > )
5821
- -> subst:: Substs < ' tcx > {
5822
- subst:: Substs { regions : subst:: ErasedRegions ,
5823
- types : substs. types . fold_with ( self ) }
5824
- }
5825
- }
5826
- }
5827
-
5828
5825
// Returns the repeat count for a repeating vector expression.
5829
5826
pub fn eval_repeat_count ( tcx : & ctxt , count_expr : & ast:: Expr ) -> uint {
5830
5827
match const_eval:: eval_const_expr_partial ( tcx, count_expr) {
@@ -6204,7 +6201,7 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
6204
6201
mt. mutbl . hash ( state) ;
6205
6202
} ;
6206
6203
let fn_sig = |& : state: & mut sip:: SipState , sig : & Binder < FnSig < ' tcx > > | {
6207
- let sig = anonymize_late_bound_regions ( tcx, sig) ;
6204
+ let sig = anonymize_late_bound_regions ( tcx, sig) . 0 ;
6208
6205
for a in sig. inputs . iter ( ) { helper ( tcx, * a, svh, state) ; }
6209
6206
if let ty:: FnConverging ( output) = sig. output {
6210
6207
helper ( tcx, output, svh, state) ;
@@ -6265,7 +6262,7 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) -
6265
6262
did ( state, data. principal_def_id ( ) ) ;
6266
6263
hash ! ( data. bounds) ;
6267
6264
6268
- let principal = anonymize_late_bound_regions ( tcx, & data. principal ) ;
6265
+ let principal = anonymize_late_bound_regions ( tcx, & data. principal ) . 0 ;
6269
6266
for subty in principal. substs . types . iter ( ) {
6270
6267
helper ( tcx, * subty, svh, state) ;
6271
6268
}
@@ -6696,6 +6693,16 @@ pub fn binds_late_bound_regions<'tcx, T>(
6696
6693
count_late_bound_regions ( tcx, value) > 0
6697
6694
}
6698
6695
6696
+ pub fn assert_no_late_bound_regions < ' tcx , T > (
6697
+ tcx : & ty:: ctxt < ' tcx > ,
6698
+ value : & Binder < T > )
6699
+ -> T
6700
+ where T : TypeFoldable < ' tcx > + Repr < ' tcx > + Clone
6701
+ {
6702
+ assert ! ( !binds_late_bound_regions( tcx, value) ) ;
6703
+ value. 0 . clone ( )
6704
+ }
6705
+
6699
6706
/// Replace any late-bound regions bound in `value` with `'static`. Useful in trans but also
6700
6707
/// method lookup and a few other places where precise region relationships are not required.
6701
6708
pub fn erase_late_bound_regions < ' tcx , T > (
@@ -6718,14 +6725,14 @@ pub fn erase_late_bound_regions<'tcx, T>(
6718
6725
pub fn anonymize_late_bound_regions < ' tcx , T > (
6719
6726
tcx : & ctxt < ' tcx > ,
6720
6727
sig : & Binder < T > )
6721
- -> T
6728
+ -> Binder < T >
6722
6729
where T : TypeFoldable < ' tcx > + Repr < ' tcx > ,
6723
6730
{
6724
6731
let mut counter = 0 ;
6725
- replace_late_bound_regions ( tcx, sig, |_, db| {
6732
+ ty :: Binder ( replace_late_bound_regions ( tcx, sig, |_, db| {
6726
6733
counter += 1 ;
6727
6734
ReLateBound ( db, BrAnon ( counter) )
6728
- } ) . 0
6735
+ } ) . 0 )
6729
6736
}
6730
6737
6731
6738
/// Replaces the late-bound-regions in `value` that are bound by `value`.
0 commit comments