@@ -20,7 +20,8 @@ use syntax::ast;
20
20
use syntax:: codemap:: Span ;
21
21
use util:: ppaux:: Repr ;
22
22
23
- use super :: { Obligation , ObligationCause , VtableImpl , VtableParam , VtableParamData , VtableImplData } ;
23
+ use super :: { ErrorReported , Obligation , ObligationCause , VtableImpl ,
24
+ VtableParam , VtableParamData , VtableImplData } ;
24
25
25
26
///////////////////////////////////////////////////////////////////////////
26
27
// Supertrait iterator
@@ -82,7 +83,7 @@ impl<'cx, 'tcx> Supertraits<'cx, 'tcx> {
82
83
let bound_trait_ref = trait_ref_for_builtin_bound ( self . tcx ,
83
84
builtin_bound,
84
85
trait_ref. self_ty ( ) ) ;
85
- trait_bounds. push ( bound_trait_ref ) ;
86
+ bound_trait_ref . map ( |trait_ref| trait_bounds. push ( trait_ref ) ) ;
86
87
}
87
88
88
89
// Only keep those bounds that we haven't already seen. This
@@ -213,13 +214,15 @@ fn push_obligations_for_param_bounds(
213
214
let param_ty = * param_substs. types . get ( space, index) ;
214
215
215
216
for builtin_bound in param_bounds. builtin_bounds . iter ( ) {
216
- obligations. push (
217
- space,
218
- obligation_for_builtin_bound ( tcx,
219
- cause,
220
- builtin_bound,
221
- recursion_depth,
222
- param_ty) ) ;
217
+ let obligation = obligation_for_builtin_bound ( tcx,
218
+ cause,
219
+ builtin_bound,
220
+ recursion_depth,
221
+ param_ty) ;
222
+ match obligation {
223
+ Ok ( ob) => obligations. push ( space, ob) ,
224
+ _ => { }
225
+ }
223
226
}
224
227
225
228
for bound_trait_ref in param_bounds. trait_bounds . iter ( ) {
@@ -236,17 +239,18 @@ pub fn trait_ref_for_builtin_bound(
236
239
tcx : & ty:: ctxt ,
237
240
builtin_bound : ty:: BuiltinBound ,
238
241
param_ty : ty:: t )
239
- -> Rc < ty:: TraitRef >
242
+ -> Option < Rc < ty:: TraitRef > >
240
243
{
241
244
match tcx. lang_items . from_builtin_kind ( builtin_bound) {
242
245
Ok ( def_id) => {
243
- Rc :: new ( ty:: TraitRef {
246
+ Some ( Rc :: new ( ty:: TraitRef {
244
247
def_id : def_id,
245
248
substs : Substs :: empty ( ) . with_self_ty ( param_ty)
246
- } )
249
+ } ) )
247
250
}
248
251
Err ( e) => {
249
- tcx. sess . bug ( e. as_slice ( ) ) ;
252
+ tcx. sess . err ( e. as_slice ( ) ) ;
253
+ None
250
254
}
251
255
}
252
256
}
@@ -257,13 +261,16 @@ pub fn obligation_for_builtin_bound(
257
261
builtin_bound : ty:: BuiltinBound ,
258
262
recursion_depth : uint ,
259
263
param_ty : ty:: t )
260
- -> Obligation
264
+ -> Result < Obligation , ErrorReported >
261
265
{
262
266
let trait_ref = trait_ref_for_builtin_bound ( tcx, builtin_bound, param_ty) ;
263
- Obligation {
264
- cause : cause,
265
- recursion_depth : recursion_depth,
266
- trait_ref : trait_ref
267
+ match trait_ref {
268
+ Some ( trait_ref) => Ok ( Obligation {
269
+ cause : cause,
270
+ recursion_depth : recursion_depth,
271
+ trait_ref : trait_ref
272
+ } ) ,
273
+ None => Err ( ErrorReported )
267
274
}
268
275
}
269
276
0 commit comments