@@ -1131,56 +1131,50 @@ fn type_is_native(cx: &ctxt, ty: t) -> bool {
1131
1131
alt struct( cx, ty) { ty_native ( _) { ret true ; } _ { ret false; } }
1132
1132
}
1133
1133
1134
- fn type_has_dynamic_size ( cx : & ctxt , ty : t ) -> bool {
1135
- alt struct( cx, ty) {
1136
- ty_nil. { ret false ; }
1137
- ty_bot. { ret false ; }
1138
- ty_bool. { ret false ; }
1139
- ty_int. { ret false ; }
1140
- ty_float. { ret false ; }
1141
- ty_uint. { ret false ; }
1142
- ty_machine ( _) { ret false ; }
1143
- ty_char. { ret false ; }
1144
- ty_str. { ret false ; }
1145
- ty_istr. { ret false ; }
1146
- ty_tag ( _, subtys) {
1147
- let i = 0 u;
1148
- while i < vec:: len :: < t > ( subtys) {
1149
- if type_has_dynamic_size ( cx, subtys[ i] ) { ret true ; }
1150
- i += 1 u;
1134
+ fn type_structurally_contains ( cx : & ctxt , ty : t ,
1135
+ test : fn ( & sty ) -> bool ) -> bool {
1136
+ let sty = struct ( cx, ty) ;
1137
+ if test ( sty) { ret true ; }
1138
+ alt sty {
1139
+ ty_tag( did, tps) {
1140
+ for variant in tag_variants ( cx, did) {
1141
+ for aty in variant. args {
1142
+ let sty = substitute_type_params ( cx, tps, aty) ;
1143
+ if type_structurally_contains ( cx, sty, test) { ret true ; }
1144
+ }
1151
1145
}
1152
1146
ret false;
1153
1147
}
1154
- ty_box ( _) { ret false; }
1155
- ty_vec ( mt) { ret type_has_dynamic_size ( cx, mt. ty ) ; }
1156
- ty_ptr ( _) { ret false; }
1148
+ ty_vec ( mt) { ret type_structurally_contains ( cx, mt. ty , test) ; }
1157
1149
ty_rec ( fields) {
1158
- let i = 0 u;
1159
- while i < vec:: len :: < field > ( fields) {
1160
- if type_has_dynamic_size ( cx, fields[ i] . mt . ty ) { ret true ; }
1161
- i += 1 u;
1150
+ for field in fields {
1151
+ if type_structurally_contains ( cx, field. mt . ty , test) { ret true ; }
1162
1152
}
1163
1153
ret false;
1164
1154
}
1165
1155
ty_tup ( ts) {
1166
- for tt in ts { if type_has_dynamic_size ( cx, tt) { ret true ; } }
1156
+ for tt in ts {
1157
+ if type_structurally_contains ( cx, tt, test) { ret true ; }
1158
+ }
1167
1159
ret false;
1168
1160
}
1169
- ty_fn ( _, _, _, _, _) { ret false; }
1170
- ty_native_fn ( _, _, _) { ret false; }
1171
- ty_obj ( _) { ret false; }
1172
1161
ty_res ( _, sub, tps) {
1173
- for tp : t in tps { if type_has_dynamic_size ( cx, tp ) { ret true ; } }
1174
- ret type_has_dynamic_size ( cx, sub ) ;
1162
+ let sty = substitute_type_params ( cx, tps , sub ) ;
1163
+ ret type_structurally_contains ( cx, sty , test ) ;
1175
1164
}
1176
- ty_var ( _) { fail "ty_var in type_has_dynamic_size()" ; }
1177
- ty_param ( _, _) { ret true; }
1178
- ty_type. { ret false ; }
1179
- ty_native ( _) { ret false ; }
1180
- ty_uniq ( _) { ret false ; }
1165
+ _ { ret false; }
1181
1166
}
1182
1167
}
1183
1168
1169
+ fn type_has_dynamic_size ( cx : & ctxt , ty : t ) -> bool {
1170
+ ret type_structurally_contains ( cx, ty, fn ( sty: & sty) -> bool {
1171
+ ret alt sty {
1172
+ ty_param( _, _) { true }
1173
+ _ { false }
1174
+ } ;
1175
+ } ) ;
1176
+ }
1177
+
1184
1178
fn type_is_integral ( cx : & ctxt , ty : t ) -> bool {
1185
1179
alt struct( cx, ty) {
1186
1180
ty_int. { ret true ; }
0 commit comments