@@ -122,7 +122,8 @@ fn is_useful(tcx: ty::ctxt, m: matrix, v: [@pat]) -> useful {
122
122
123
123
alt pat_ctor_id ( tcx, v[ 0 ] ) {
124
124
none {
125
- if is_complete( tcx, m, left_ty) {
125
+ alt missing_ctor( tcx, m, left_ty) {
126
+ none {
126
127
alt ty:: get ( left_ty) . struct {
127
128
ty:: ty_bool {
128
129
alt is_useful_specialized( tcx, m, v, val( const_int ( 1i64 ) ) ,
@@ -149,9 +150,14 @@ fn is_useful(tcx: ty::ctxt, m: matrix, v: [@pat]) -> useful {
149
150
is_useful_specialized( tcx, m, v, single, arity, left_ty)
150
151
}
151
152
}
152
- } else {
153
- is_useful( tcx, vec:: filter_map( m, { |r| default ( tcx, r) } ) ,
154
- vec:: tail( v) )
153
+ }
154
+ some( ctor) {
155
+ alt is_useful( tcx, vec:: filter_map( m, { |r| default ( tcx, r) } ) ,
156
+ vec:: tail( v) ) {
157
+ useful_ { useful( left_ty, ctor) }
158
+ u { u }
159
+ }
160
+ }
155
161
}
156
162
}
157
163
some( v0_ctor) {
@@ -202,13 +208,13 @@ fn is_wild(tcx: ty::ctxt, p: @pat) -> bool {
202
208
}
203
209
}
204
210
205
- fn is_complete ( tcx: ty:: ctxt, m: matrix, left_ty: ty:: t) -> bool {
211
+ fn missing_ctor ( tcx: ty:: ctxt, m: matrix, left_ty: ty:: t) -> option < ctor > {
206
212
alt ty:: get( left_ty) . struct {
207
213
ty:: ty_box( _) | ty:: ty_uniq( _) | ty:: ty_tup( _) | ty:: ty_rec( _) {
208
214
for m. each { |r|
209
- if ! is_wild( tcx, r[ 0 ] ) { ret true ; }
215
+ if ! is_wild( tcx, r[ 0 ] ) { ret none ; }
210
216
}
211
- ret false ;
217
+ ret some ( single ) ;
212
218
}
213
219
ty:: ty_enum( eid, _) {
214
220
let mut found = [ ] ;
@@ -217,9 +223,17 @@ fn is_complete(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> bool {
217
223
if !vec:: contains( found, id) { found += [ id] ; }
218
224
}
219
225
}
220
- found. len( ) == ( * ty:: enum_variants( tcx, eid) ) . len( )
226
+ let variants = ty:: enum_variants( tcx, eid) ;
227
+ if found. len( ) != ( * variants) . len( ) {
228
+ for vec:: each( * variants) { |v|
229
+ if ! found. contains( variant( v. id) ) {
230
+ ret some( variant( v. id) ) ;
231
+ }
232
+ }
233
+ fail;
234
+ } else { none }
221
235
}
222
- ty:: ty_nil { true }
236
+ ty:: ty_nil { none }
223
237
ty:: ty_bool {
224
238
let mut true_found = false , false_found = false ;
225
239
for m. each { |r|
@@ -229,9 +243,11 @@ fn is_complete(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> bool {
229
243
some( val( const_int( 0i64 ) ) ) { false_found = true ; }
230
244
}
231
245
}
232
- true_found && false_found
246
+ if true_found && false_found { none }
247
+ else if true_found { some( val( const_int( 0i64 ) ) ) }
248
+ else { some( val( const_int( 1i64 ) ) ) }
233
249
}
234
- _ { false }
250
+ _ { some ( single ) }
235
251
}
236
252
}
237
253
0 commit comments