@@ -82,14 +82,13 @@ 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 , 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;
93
92
use syntax:: ast;
94
93
use syntax:: parse:: token;
95
94
use syntax:: ptr:: P ;
@@ -233,22 +232,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
233
232
}
234
233
}
235
234
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
-
252
235
impl < ' a , ' gcx , ' tcx > InferCtxt < ' a , ' gcx , ' tcx > {
253
236
pub fn report_region_errors ( & self ,
254
237
errors : & Vec < RegionResolutionError < ' tcx > > ) {
@@ -598,54 +581,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
598
581
diag. note_expected_found ( & "type" , & expected, & found) ;
599
582
}
600
583
}
601
-
602
- //if let Some((found, (expected_ty, expected))) = self.get_ids(values) {
603
- // look for expected with found id
604
- /*self.tcx.populate_inherent_implementations_for_type_if_necessary(found);
605
- if let Some(impl_infos) = self.tcx.inherent_impls.borrow().get(&found) {
606
- let mut methods: Vec<MethodInfo> = Vec::new();
607
- for impl_ in impl_infos {
608
- methods.append(&mut self.tcx
609
- .impl_or_trait_items(*impl_)
610
- .iter()
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)
614
- })
615
- .collect());
616
- }
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
- ;
628
- }
629
- }
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
- //}
649
584
}
650
585
651
586
diag. span_label ( span, & terr) ;
@@ -658,32 +593,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
658
593
self . tcx . note_and_explain_type_err ( diag, terr, span) ;
659
594
}
660
595
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
-
678
- fn find_attr(&self, def_id: DefId, attr_name: &str) -> Option<ast::Attribute> {
679
- for item in self.tcx.get_attrs(def_id).iter() {
680
- if item.check_name(attr_name) {
681
- return Some(item.clone());
682
- }
683
- }
684
- None
685
- }*/
686
-
687
596
pub fn report_and_explain_type_error ( & self ,
688
597
trace : TypeTrace < ' tcx > ,
689
598
terr : & TypeError < ' tcx > )
@@ -712,69 +621,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
712
621
}
713
622
}
714
623
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
-
724
- fn matches_return_type(&self, method: &ImplOrTraitItem<'tcx>, expected: &ty::Ty<'tcx>) -> bool {
725
- match *method {
726
- ImplOrTraitItem::MethodTraitItem(ref x) => {
727
- self.can_sub_types(x.fty.sig.skip_binder().output, expected).is_ok()
728
- }
729
- _ => false,
730
- }
731
- }
732
-
733
- fn get_id(&self, ty: Ty<'tcx>) -> Option<DefId> {
734
- match ty.sty {
735
- ty::TyTrait(box ref data) => Some(data.principal.def_id()),
736
- ty::TyAdt(def, _) => Some(def.did),
737
- ty::TyBox(ref ty) => self.get_id(*ty), // since we don't want box's methods by type's
738
- ty::TyChar => self.tcx.lang_items.char_impl(),
739
- ty::TyStr => self.tcx.lang_items.str_impl(),
740
- ty::TySlice(_) => self.tcx.lang_items.slice_impl(),
741
- ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutImmutable }) => {
742
- self.tcx.lang_items.const_ptr_impl()
743
- }
744
- ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
745
- self.tcx.lang_items.mut_ptr_impl()
746
- }
747
- ty::TyInt(ast::IntTy::I8) => self.tcx.lang_items.i8_impl(),
748
- ty::TyInt(ast::IntTy::I16) => self.tcx.lang_items.i16_impl(),
749
- ty::TyInt(ast::IntTy::I32) => self.tcx.lang_items.i32_impl(),
750
- ty::TyInt(ast::IntTy::I64) => self.tcx.lang_items.i64_impl(),
751
- ty::TyInt(ast::IntTy::Is) => self.tcx.lang_items.isize_impl(),
752
- ty::TyUint(ast::UintTy::U8) => self.tcx.lang_items.u8_impl(),
753
- ty::TyUint(ast::UintTy::U16) => self.tcx.lang_items.u16_impl(),
754
- ty::TyUint(ast::UintTy::U32) => self.tcx.lang_items.u32_impl(),
755
- ty::TyUint(ast::UintTy::U64) => self.tcx.lang_items.u64_impl(),
756
- ty::TyUint(ast::UintTy::Us) => self.tcx.lang_items.usize_impl(),
757
- ty::TyFloat(ast::FloatTy::F32) => self.tcx.lang_items.f32_impl(),
758
- ty::TyFloat(ast::FloatTy::F64) => self.tcx.lang_items.f64_impl(),
759
- _ => None,
760
- }
761
- }
762
-
763
- // Yep, returned value super ugly. it'll certainly become `Option<(DefId, ty::Ty<'tcx>)>`
764
- // in a close future. Or maybe a struct?
765
- fn get_ids(&self, values: Option<ValuePairs<'tcx>>) -> Option<(DefId, (ty::Ty<'tcx>, DefId))> {
766
- match values {
767
- // for now, only handling non trait types
768
- Some(infer::Types(ref exp_found)) => {
769
- match (self.get_id(exp_found.found), self.get_id(exp_found.expected)) {
770
- (Some(found), Some(expected)) => Some((found, (exp_found.expected, expected))),
771
- _ => None,
772
- }
773
- }
774
- _ => None,
775
- }
776
- }*/
777
-
778
624
fn expected_found_str < T : fmt:: Display + TypeFoldable < ' tcx > > (
779
625
& self ,
780
626
exp_found : & ty:: error:: ExpectedFound < T > )
0 commit comments