@@ -83,13 +83,14 @@ use hir::def_id::DefId;
83
83
use infer;
84
84
use middle:: region;
85
85
use traits:: { ObligationCause , ObligationCauseCode } ;
86
- use ty:: { self , ImplOrTraitItem , Ty , TyCtxt , TypeFoldable } ;
86
+ use ty:: { self , TyCtxt , TypeFoldable } ;
87
87
use ty:: { Region , ReFree } ;
88
88
use ty:: error:: TypeError ;
89
89
90
90
use std:: cell:: { Cell , RefCell } ;
91
91
use std:: char:: from_u32;
92
92
use std:: fmt;
93
+ //use std::rc::Rc;
93
94
use syntax:: ast;
94
95
use syntax:: ptr:: P ;
95
96
use syntax:: symbol:: Symbol ;
@@ -233,6 +234,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
233
234
}
234
235
}
235
236
237
+ /*struct MethodInfo<'tcx> {
238
+ ast: Option<ast::Attribute>,
239
+ id: DefId,
240
+ item: Rc<ImplOrTraitItem<'tcx>>,
241
+ }
242
+
243
+ impl<'tcx> MethodInfo<'tcx> {
244
+ fn new(ast: Option<ast::Attribute>, id: DefId, item: Rc<ImplOrTraitItem<'tcx>>) -> MethodInfo {
245
+ MethodInfo {
246
+ ast: ast,
247
+ id: id,
248
+ item: item,
249
+ }
250
+ }
251
+ }*/
252
+
236
253
impl < ' a , ' gcx , ' tcx > InferCtxt < ' a , ' gcx , ' tcx > {
237
254
pub fn report_region_errors ( & self ,
238
255
errors : & Vec < RegionResolutionError < ' tcx > > ) {
@@ -583,36 +600,53 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
583
600
}
584
601
}
585
602
586
- if let Some ( ( found, ( expected_ty, _ ) ) ) = self . get_ids ( values) {
603
+ // if let Some((found, (expected_ty, expected ))) = self.get_ids(values) {
587
604
// look for expected with found id
588
- self . tcx . populate_inherent_implementations_for_type_if_necessary ( found) ;
605
+ /* self.tcx.populate_inherent_implementations_for_type_if_necessary(found);
589
606
if let Some(impl_infos) = self.tcx.inherent_impls.borrow().get(&found) {
590
- let mut methods: Vec < ( Option < ast :: Attribute > , DefId , ImplOrTraitItem < ' tcx > ) > = Vec :: new ( ) ;
607
+ let mut methods: Vec<MethodInfo > = Vec::new();
591
608
for impl_ in impl_infos {
592
609
methods.append(&mut self.tcx
593
610
.impl_or_trait_items(*impl_)
594
611
.iter()
595
- . map ( |& did| ( None , did, self . tcx . impl_or_trait_item ( did) ) )
596
- . filter ( |& ( _ , _ , ref x) | {
597
- self . matches_return_type ( x , & expected_ty)
612
+ .map(|&did| MethodInfo::new (None, did, Rc::new( self.tcx.impl_or_trait_item(did) )))
613
+ .filter(|ref x| {
614
+ self.matches_return_type(&*x.item , &expected_ty)
598
615
})
599
616
.collect());
600
617
}
601
- let safe_suggestions : Vec < _ > = methods . iter ( )
602
- . map ( | & ( _ , ref id , ref x ) | ( self . find_attr ( * id , "safe_suggestion" ) , id , x ) )
603
- . filter ( | & ( ref res , _ , _ ) | res . is_some ( ) )
604
- . collect ( ) ;
605
- if safe_suggestions . len ( ) > 0 {
606
- for ( _ , _ , method ) in safe_suggestions {
607
- println ! ( "safe ==> {:?}" , method . name ( ) ) ;
608
- }
609
- } else {
610
- for & ( _ , _ , ref method ) in methods . iter ( ) {
611
- println ! ( "not safe ==> {:?}" , method . name ( ) ) ;
618
+ for did in self.tcx.sess.cstore.implementations_of_trait(None) {
619
+ if did == found {
620
+ methods.append(
621
+ self.tcx.sess.cstore.impl_or_trait_items(did)
622
+ .iter()
623
+ .map(|&did| MethodInfo::new(None, did, Rc::new(self.tcx.impl_or_trait_item(did))))
624
+ .filter(|ref x| {
625
+ self.matches_return_type(&*x.item, &expected_ty)
626
+ })
627
+ .collect());
628
+ ;
612
629
}
613
630
}
614
- }
615
- }
631
+ let safe_suggestions: Vec<_> =
632
+ methods.iter()
633
+ .map(|ref x| MethodInfo::new(self.find_attr(x.id, "safe_suggestion"), x.id, x.item.clone()))
634
+ .filter(|ref x| x.ast.is_some())
635
+ .collect();
636
+ if safe_suggestions.len() > 0 {
637
+ println!("safe");
638
+ self.get_best_match(&safe_suggestions);
639
+ } else {
640
+ println!("not safe");
641
+ self.get_best_match(&methods);
642
+ }*/
643
+ /*let mode = probe::Mode::MethodCall;
644
+ if let Ok(ret) = self.probe_return(DUMMY_SP, mode, expected, found, DUMMY_NODE_ID) {
645
+ println!("got it");
646
+ } else {
647
+ println!("sad...");
648
+ }*/
649
+ //}
616
650
}
617
651
618
652
diag. span_label ( span, & terr) ;
@@ -625,14 +659,31 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
625
659
self . tcx . note_and_explain_type_err ( diag, terr, span) ;
626
660
}
627
661
662
+ /*fn get_best_match(&self, methods: &[MethodInfo<'tcx>]) -> String {
663
+ let no_argument_methods: Vec<&MethodInfo> =
664
+ methods.iter()
665
+ .filter(|ref x| self.has_not_input_arg(&*x.item))
666
+ .collect();
667
+ if no_argument_methods.len() > 0 {
668
+ for ref method in no_argument_methods {
669
+ println!("best match ==> {:?}", method.item.name());
670
+ }
671
+ } else {
672
+ for ref method in methods.iter() {
673
+ println!("not best ==> {:?}", method.item.name());
674
+ }
675
+ }
676
+ String::new()
677
+ }
678
+
628
679
fn find_attr(&self, def_id: DefId, attr_name: &str) -> Option<ast::Attribute> {
629
680
for item in self.tcx.get_attrs(def_id).iter() {
630
681
if item.check_name(attr_name) {
631
682
return Some(item.clone());
632
683
}
633
684
}
634
685
None
635
- }
686
+ }*/
636
687
637
688
pub fn report_and_explain_type_error ( & self ,
638
689
trace : TypeTrace < ' tcx > ,
@@ -662,6 +713,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
662
713
}
663
714
}
664
715
716
+ /*fn has_not_input_arg(&self, method: &ImplOrTraitItem<'tcx>) -> bool {
717
+ match *method {
718
+ ImplOrTraitItem::MethodTraitItem(ref x) => {
719
+ x.fty.sig.skip_binder().inputs.len() == 1
720
+ }
721
+ _ => false,
722
+ }
723
+ }
724
+
665
725
fn matches_return_type(&self, method: &ImplOrTraitItem<'tcx>, expected: &ty::Ty<'tcx>) -> bool {
666
726
match *method {
667
727
ImplOrTraitItem::MethodTraitItem(ref x) => {
@@ -714,7 +774,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
714
774
}
715
775
_ => None,
716
776
}
717
- }
777
+ }*/
718
778
719
779
fn expected_found_str < T : fmt:: Display + TypeFoldable < ' tcx > > (
720
780
& self ,
0 commit comments