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