@@ -19,7 +19,7 @@ use hir;
1919use hir:: def_id:: DefId ;
2020use middle:: free_region:: FreeRegionMap ;
2121use ty:: subst:: Substs ;
22- use ty:: { self , Ty , TyCtxt , TypeFoldable } ;
22+ use ty:: { self , Ty , TyCtxt , TypeFoldable , ToPredicate } ;
2323use infer:: InferCtxt ;
2424
2525use std:: rc:: Rc ;
@@ -125,10 +125,6 @@ pub enum ObligationCauseCode<'tcx> {
125125 ReturnType , // Return type must be Sized
126126 RepeatVec , // [T,..n] --> T must be Copy
127127
128- // Captures of variable the given id by a closure (span is the
129- // span of the closure)
130- ClosureCapture ( ast:: NodeId , Span , ty:: BuiltinBound ) ,
131-
132128 // Types of fields (other than the last) in a struct must be sized.
133129 FieldSized ,
134130
@@ -369,27 +365,30 @@ pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
369365/// `bound` or is not known to meet bound (note that this is
370366/// conservative towards *no impl*, which is the opposite of the
371367/// `evaluate` methods).
372- pub fn type_known_to_meet_builtin_bound < ' a , ' gcx , ' tcx > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
368+ pub fn type_known_to_meet_bound < ' a , ' gcx , ' tcx > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
373369 ty : Ty < ' tcx > ,
374- bound : ty :: BuiltinBound ,
370+ def_id : DefId ,
375371 span : Span )
376372 -> bool
377373{
378- debug ! ( "type_known_to_meet_builtin_bound (ty={:?}, bound={:?})" ,
374+ debug ! ( "type_known_to_meet_bound (ty={:?}, bound={:?})" ,
379375 ty,
380- bound) ;
381-
382- let cause = ObligationCause :: misc ( span, ast:: DUMMY_NODE_ID ) ;
383- let obligation =
384- infcx. tcx . predicate_for_builtin_bound ( cause, bound, 0 , ty) ;
385- let obligation = match obligation {
386- Ok ( o) => o,
387- Err ( ..) => return false
376+ infcx. tcx. item_path_str( def_id) ) ;
377+
378+ let trait_ref = ty:: TraitRef {
379+ def_id : def_id,
380+ substs : infcx. tcx . mk_substs_trait ( ty, & [ ] ) ,
388381 } ;
382+ let obligation = Obligation {
383+ cause : ObligationCause :: misc ( span, ast:: DUMMY_NODE_ID ) ,
384+ recursion_depth : 0 ,
385+ predicate : trait_ref. to_predicate ( ) ,
386+ } ;
387+
389388 let result = SelectionContext :: new ( infcx)
390389 . evaluate_obligation_conservatively ( & obligation) ;
391- debug ! ( "type_known_to_meet_builtin_bound: ty ={:?} bound={:? } => {:?}" ,
392- ty, bound , result) ;
390+ debug ! ( "type_known_to_meet_ty ={:?} bound={} => {:?}" ,
391+ ty, infcx . tcx . item_path_str ( def_id ) , result) ;
393392
394393 if result && ( ty. has_infer_types ( ) || ty. has_closure_types ( ) ) {
395394 // Because of inference "guessing", selection can sometimes claim
@@ -404,22 +403,22 @@ pub fn type_known_to_meet_builtin_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'g
404403 // anyhow).
405404 let cause = ObligationCause :: misc ( span, ast:: DUMMY_NODE_ID ) ;
406405
407- fulfill_cx. register_builtin_bound ( infcx, ty, bound , cause) ;
406+ fulfill_cx. register_bound ( infcx, ty, def_id , cause) ;
408407
409408 // Note: we only assume something is `Copy` if we can
410409 // *definitively* show that it implements `Copy`. Otherwise,
411410 // assume it is move; linear is always ok.
412411 match fulfill_cx. select_all_or_error ( infcx) {
413412 Ok ( ( ) ) => {
414- debug ! ( "type_known_to_meet_builtin_bound : ty={:?} bound={:? } success" ,
413+ debug ! ( "type_known_to_meet_bound : ty={:?} bound={} success" ,
415414 ty,
416- bound ) ;
415+ infcx . tcx . item_path_str ( def_id ) ) ;
417416 true
418417 }
419418 Err ( e) => {
420- debug ! ( "type_known_to_meet_builtin_bound : ty={:?} bound={:? } errors={:?}" ,
419+ debug ! ( "type_known_to_meet_bound : ty={:?} bound={} errors={:?}" ,
421420 ty,
422- bound ,
421+ infcx . tcx . item_path_str ( def_id ) ,
423422 e) ;
424423 false
425424 }
0 commit comments