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