@@ -19,7 +19,7 @@ use hir;
19
19
use hir:: def_id:: DefId ;
20
20
use middle:: free_region:: FreeRegionMap ;
21
21
use ty:: subst:: Substs ;
22
- use ty:: { self , Ty , TyCtxt , TypeFoldable } ;
22
+ use ty:: { self , Ty , TyCtxt , TypeFoldable , ToPredicate } ;
23
23
use infer:: InferCtxt ;
24
24
25
25
use std:: rc:: Rc ;
@@ -125,10 +125,6 @@ pub enum ObligationCauseCode<'tcx> {
125
125
ReturnType , // Return type must be Sized
126
126
RepeatVec , // [T,..n] --> T must be Copy
127
127
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
-
132
128
// Types of fields (other than the last) in a struct must be sized.
133
129
FieldSized ,
134
130
@@ -369,27 +365,30 @@ pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
369
365
/// `bound` or is not known to meet bound (note that this is
370
366
/// conservative towards *no impl*, which is the opposite of the
371
367
/// `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 > ,
373
369
ty : Ty < ' tcx > ,
374
- bound : ty :: BuiltinBound ,
370
+ def_id : DefId ,
375
371
span : Span )
376
372
-> bool
377
373
{
378
- debug ! ( "type_known_to_meet_builtin_bound (ty={:?}, bound={:?})" ,
374
+ debug ! ( "type_known_to_meet_bound (ty={:?}, bound={:?})" ,
379
375
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, & [ ] ) ,
388
381
} ;
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
+
389
388
let result = SelectionContext :: new ( infcx)
390
389
. 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) ;
393
392
394
393
if result && ( ty. has_infer_types ( ) || ty. has_closure_types ( ) ) {
395
394
// 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
404
403
// anyhow).
405
404
let cause = ObligationCause :: misc ( span, ast:: DUMMY_NODE_ID ) ;
406
405
407
- fulfill_cx. register_builtin_bound ( infcx, ty, bound , cause) ;
406
+ fulfill_cx. register_bound ( infcx, ty, def_id , cause) ;
408
407
409
408
// Note: we only assume something is `Copy` if we can
410
409
// *definitively* show that it implements `Copy`. Otherwise,
411
410
// assume it is move; linear is always ok.
412
411
match fulfill_cx. select_all_or_error ( infcx) {
413
412
Ok ( ( ) ) => {
414
- debug ! ( "type_known_to_meet_builtin_bound : ty={:?} bound={:? } success" ,
413
+ debug ! ( "type_known_to_meet_bound : ty={:?} bound={} success" ,
415
414
ty,
416
- bound ) ;
415
+ infcx . tcx . item_path_str ( def_id ) ) ;
417
416
true
418
417
}
419
418
Err ( e) => {
420
- debug ! ( "type_known_to_meet_builtin_bound : ty={:?} bound={:? } errors={:?}" ,
419
+ debug ! ( "type_known_to_meet_bound : ty={:?} bound={} errors={:?}" ,
421
420
ty,
422
- bound ,
421
+ infcx . tcx . item_path_str ( def_id ) ,
423
422
e) ;
424
423
false
425
424
}
0 commit comments