@@ -51,8 +51,13 @@ fn lookup_vtables(fcx: @fn_ctxt,
51
51
match * bound {
52
52
ty:: bound_trait( i_ty) => {
53
53
let i_ty = ty:: subst ( tcx, substs, i_ty) ;
54
- result. push ( lookup_vtable ( fcx, expr, * ty, i_ty,
55
- allow_unsafe, is_early) ) ;
54
+ match lookup_vtable ( fcx, expr, * ty, i_ty, allow_unsafe,
55
+ is_early) {
56
+ None => { }
57
+ Some ( vtable) => {
58
+ result. push ( vtable) ;
59
+ }
60
+ }
56
61
}
57
62
_ => ( )
58
63
}
@@ -91,7 +96,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
91
96
trait_ty : ty:: t ,
92
97
allow_unsafe : bool ,
93
98
is_early : bool )
94
- -> vtable_origin
99
+ -> Option < vtable_origin >
95
100
{
96
101
97
102
debug ! ( "lookup_vtable(ty=%s, trait_ty=%s)" ,
@@ -113,7 +118,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
113
118
// The type has unconstrained type variables in it, so we can't
114
119
// do early resolution on it. Return some completely bogus vtable
115
120
// information: we aren't storing it anyways.
116
- return vtable_param ( 0 , 0 ) ;
121
+ return Some ( vtable_param ( 0 , 0 ) ) ;
117
122
}
118
123
} ;
119
124
@@ -135,7 +140,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
135
140
idid) ;
136
141
relate_trait_tys ( fcx, expr,
137
142
trait_ty, ity) ;
138
- return vtable_param ( n, n_bound) ;
143
+ return Some ( vtable_param ( n, n_bound) ) ;
139
144
}
140
145
}
141
146
_ => tcx. sess . impossible_case (
@@ -170,7 +175,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
170
175
}
171
176
}
172
177
}
173
- return vtable_trait ( did, substs. tps ) ;
178
+ return Some ( vtable_trait ( did, substs. tps ) ) ;
174
179
}
175
180
176
181
_ => {
@@ -303,7 +308,7 @@ fn lookup_vtable(fcx: @fn_ctxt,
303
308
None => {
304
309
assert is_early;
305
310
// Bail out with a bogus answer
306
- return vtable_param ( 0 , 0 ) ;
311
+ return Some ( vtable_param ( 0 , 0 ) ) ;
307
312
}
308
313
} ;
309
314
@@ -341,23 +346,20 @@ fn lookup_vtable(fcx: @fn_ctxt,
341
346
342
347
match found. len ( ) {
343
348
0 => { /* fallthrough */ }
344
- 1 => { return found[ 0 ] ; }
349
+ 1 => { return Some ( found[ 0 ] ) ; }
345
350
_ => {
346
351
if !is_early {
347
352
fcx. ccx . tcx . sess . span_err (
348
353
expr. span ,
349
354
~"multiple applicable methods in scope") ;
350
355
}
351
- return found[ 0 ] ;
356
+ return Some ( found[ 0 ] ) ;
352
357
}
353
358
}
354
359
}
355
360
}
356
361
357
- tcx. sess . span_fatal (
358
- expr. span ,
359
- fmt ! ( "failed to find an implementation of trait %s for %s" ,
360
- ty_to_str( tcx, trait_ty) , ty_to_str( tcx, ty) ) ) ;
362
+ return None ;
361
363
}
362
364
363
365
fn fixup_ty ( fcx : @fn_ctxt ,
@@ -459,13 +461,26 @@ fn early_resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, is_early: bool) {
459
461
Look up vtables for the type we're casting to,
460
462
passing in the source and target type
461
463
*/
462
- let vtable = lookup_vtable ( fcx, ex, fcx. expr_ty ( src) ,
463
- target_ty, true , is_early) ;
464
- /*
465
- Map this expression to that vtable (that is: "ex has
466
- vtable <vtable>")
467
- */
468
- if !is_early { cx. vtable_map . insert ( ex. id , @~[ vtable] ) ; }
464
+ let ty = fcx. expr_ty ( src) ;
465
+ let vtable_opt = lookup_vtable ( fcx, ex, ty, target_ty, true ,
466
+ is_early) ;
467
+ match vtable_opt {
468
+ None => {
469
+ fcx. tcx ( ) . sess . span_err (
470
+ ex. span ,
471
+ fmt ! ( "failed to find an implementation of trait %s \
472
+ for %s",
473
+ ty_to_str( fcx. tcx( ) , target_ty) ,
474
+ ty_to_str( fcx. tcx( ) , ty) ) ) ;
475
+ }
476
+ Some ( vtable) => {
477
+ /*
478
+ Map this expression to that vtable (that is: "ex has
479
+ vtable <vtable>")
480
+ */
481
+ if !is_early { cx. vtable_map . insert ( ex. id , @~[ vtable] ) ; }
482
+ }
483
+ }
469
484
}
470
485
_ => ( )
471
486
}
0 commit comments