@@ -20,7 +20,8 @@ use syntax::ast;
2020use syntax:: codemap:: Span ;
2121use util:: ppaux:: Repr ;
2222
23- use super :: { Obligation , ObligationCause , VtableImpl , VtableParam , VtableParamData , VtableImplData } ;
23+ use super :: { ErrorReported , Obligation , ObligationCause , VtableImpl ,
24+ VtableParam , VtableParamData , VtableImplData } ;
2425
2526///////////////////////////////////////////////////////////////////////////
2627// Supertrait iterator
@@ -82,7 +83,7 @@ impl<'cx, 'tcx> Supertraits<'cx, 'tcx> {
8283 let bound_trait_ref = trait_ref_for_builtin_bound ( self . tcx ,
8384 builtin_bound,
8485 trait_ref. self_ty ( ) ) ;
85- trait_bounds. push ( bound_trait_ref ) ;
86+ bound_trait_ref . map ( |trait_ref| trait_bounds. push ( trait_ref ) ) ;
8687 }
8788
8889 // Only keep those bounds that we haven't already seen. This
@@ -213,13 +214,15 @@ fn push_obligations_for_param_bounds(
213214 let param_ty = * param_substs. types . get ( space, index) ;
214215
215216 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+ }
223226 }
224227
225228 for bound_trait_ref in param_bounds. trait_bounds . iter ( ) {
@@ -236,17 +239,18 @@ pub fn trait_ref_for_builtin_bound(
236239 tcx : & ty:: ctxt ,
237240 builtin_bound : ty:: BuiltinBound ,
238241 param_ty : ty:: t )
239- -> Rc < ty:: TraitRef >
242+ -> Option < Rc < ty:: TraitRef > >
240243{
241244 match tcx. lang_items . from_builtin_kind ( builtin_bound) {
242245 Ok ( def_id) => {
243- Rc :: new ( ty:: TraitRef {
246+ Some ( Rc :: new ( ty:: TraitRef {
244247 def_id : def_id,
245248 substs : Substs :: empty ( ) . with_self_ty ( param_ty)
246- } )
249+ } ) )
247250 }
248251 Err ( e) => {
249- tcx. sess . bug ( e. as_slice ( ) ) ;
252+ tcx. sess . err ( e. as_slice ( ) ) ;
253+ None
250254 }
251255 }
252256}
@@ -257,13 +261,16 @@ pub fn obligation_for_builtin_bound(
257261 builtin_bound : ty:: BuiltinBound ,
258262 recursion_depth : uint ,
259263 param_ty : ty:: t )
260- -> Obligation
264+ -> Result < Obligation , ErrorReported >
261265{
262266 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 )
267274 }
268275}
269276
0 commit comments