@@ -76,6 +76,8 @@ pub trait AstConv<'gcx, 'tcx> {
76
76
/// used to help suppress derived errors typeck might otherwise
77
77
/// report.
78
78
fn set_tainted_by_errors ( & self ) ;
79
+
80
+ fn record_ty ( & self , hir_id : hir:: HirId , ty : Ty < ' tcx > , span : Span ) ;
79
81
}
80
82
81
83
struct ConvertedBinding < ' tcx > {
@@ -975,6 +977,14 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
975
977
}
976
978
}
977
979
Def :: Err => {
980
+ for segment in & path. segments {
981
+ for ty in & segment. parameters . types {
982
+ self . ast_ty_to_ty ( ty) ;
983
+ }
984
+ for binding in & segment. parameters . bindings {
985
+ self . ast_ty_to_ty ( & binding. ty ) ;
986
+ }
987
+ }
978
988
self . set_tainted_by_errors ( ) ;
979
989
return self . tcx ( ) . types . err ;
980
990
}
@@ -1115,6 +1125,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1115
1125
}
1116
1126
} ;
1117
1127
1128
+ self . record_ty ( ast_ty. hir_id , result_ty, ast_ty. span ) ;
1118
1129
result_ty
1119
1130
}
1120
1131
@@ -1124,8 +1135,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1124
1135
-> Ty < ' tcx >
1125
1136
{
1126
1137
match ty. node {
1127
- hir:: TyInfer if expected_ty. is_some ( ) => expected_ty. unwrap ( ) ,
1128
- hir:: TyInfer => self . ty_infer ( ty. span ) ,
1138
+ hir:: TyInfer if expected_ty. is_some ( ) => {
1139
+ self . record_ty ( ty. hir_id , expected_ty. unwrap ( ) , ty. span ) ;
1140
+ expected_ty. unwrap ( )
1141
+ }
1129
1142
_ => self . ast_ty_to_ty ( ty) ,
1130
1143
}
1131
1144
}
@@ -1214,19 +1227,22 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
1214
1227
1215
1228
let expected_ret_ty = expected_sig. as_ref ( ) . map ( |e| e. output ( ) ) ;
1216
1229
1217
- let is_infer = match decl. output {
1218
- hir:: Return ( ref output) if output. node == hir:: TyInfer => true ,
1219
- hir:: DefaultReturn ( ..) => true ,
1220
- _ => false
1221
- } ;
1222
-
1223
1230
let output_ty = match decl. output {
1224
- _ if is_infer && expected_ret_ty. is_some ( ) =>
1225
- expected_ret_ty. unwrap ( ) ,
1226
- _ if is_infer => self . ty_infer ( decl. output . span ( ) ) ,
1227
- hir:: Return ( ref output) =>
1228
- self . ast_ty_to_ty ( & output) ,
1229
- hir:: DefaultReturn ( ..) => bug ! ( ) ,
1231
+ hir:: Return ( ref output) => {
1232
+ if let ( & hir:: TyInfer , Some ( expected_ret_ty) ) = ( & output. node , expected_ret_ty) {
1233
+ self . record_ty ( output. hir_id , expected_ret_ty, output. span ) ;
1234
+ expected_ret_ty
1235
+ } else {
1236
+ self . ast_ty_to_ty ( & output)
1237
+ }
1238
+ }
1239
+ hir:: DefaultReturn ( span) => {
1240
+ if let Some ( expected_ret_ty) = expected_ret_ty {
1241
+ expected_ret_ty
1242
+ } else {
1243
+ self . ty_infer ( span)
1244
+ }
1245
+ }
1230
1246
} ;
1231
1247
1232
1248
debug ! ( "ty_of_closure: output_ty={:?}" , output_ty) ;
0 commit comments