|
55 | 55 | //! ported to this system, and which relies on string concatenation at the
|
56 | 56 | //! time of error detection.
|
57 | 57 |
|
58 |
| -use super::InferCtxt; |
59 |
| -use super::TypeTrace; |
60 |
| -use super::SubregionOrigin; |
61 |
| -use super::RegionVariableOrigin; |
62 |
| -use super::ValuePairs; |
63 |
| -use super::region_inference::RegionResolutionError; |
64 |
| -use super::region_inference::ConcreteFailure; |
65 |
| -use super::region_inference::SubSupConflict; |
66 |
| -use super::region_inference::GenericBoundFailure; |
67 |
| -use super::region_inference::GenericKind; |
| 58 | +use infer; |
| 59 | +use super::{InferCtxt, TypeTrace, SubregionOrigin, RegionVariableOrigin, ValuePairs}; |
| 60 | +use super::region_inference::{RegionResolutionError, ConcreteFailure, SubSupConflict, |
| 61 | + GenericBoundFailure, GenericKind}; |
68 | 62 |
|
69 |
| -use hir::map as hir_map; |
| 63 | +use std::fmt; |
70 | 64 | use hir;
|
71 |
| - |
| 65 | +use hir::map as hir_map; |
72 | 66 | use hir::def_id::DefId;
|
73 |
| -use infer; |
74 | 67 | use middle::region;
|
75 | 68 | use traits::{ObligationCause, ObligationCauseCode};
|
76 | 69 | use ty::{self, TyCtxt, TypeFoldable};
|
77 | 70 | use ty::{Region, Issue32330};
|
78 | 71 | use ty::error::TypeError;
|
79 |
| - |
80 |
| -use std::fmt; |
81 | 72 | use syntax_pos::{Pos, Span};
|
82 | 73 | use errors::DiagnosticBuilder;
|
83 | 74 |
|
| 75 | +mod note; |
| 76 | + |
84 | 77 | impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
85 | 78 | pub fn note_and_explain_region(self,
|
86 | 79 | err: &mut DiagnosticBuilder,
|
@@ -584,289 +577,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
584 | 577 | err.emit();
|
585 | 578 | }
|
586 | 579 |
|
587 |
| - fn report_concrete_failure(&self, |
588 |
| - origin: SubregionOrigin<'tcx>, |
589 |
| - sub: &'tcx Region, |
590 |
| - sup: &'tcx Region) |
591 |
| - -> DiagnosticBuilder<'tcx> { |
592 |
| - match origin { |
593 |
| - infer::Subtype(trace) => { |
594 |
| - let terr = TypeError::RegionsDoesNotOutlive(sup, sub); |
595 |
| - self.report_and_explain_type_error(trace, &terr) |
596 |
| - } |
597 |
| - infer::Reborrow(span) => { |
598 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0312, |
599 |
| - "lifetime of reference outlives \ |
600 |
| - lifetime of borrowed content..."); |
601 |
| - self.tcx.note_and_explain_region(&mut err, |
602 |
| - "...the reference is valid for ", |
603 |
| - sub, |
604 |
| - "..."); |
605 |
| - self.tcx.note_and_explain_region(&mut err, |
606 |
| - "...but the borrowed content is only valid for ", |
607 |
| - sup, |
608 |
| - ""); |
609 |
| - err |
610 |
| - } |
611 |
| - infer::ReborrowUpvar(span, ref upvar_id) => { |
612 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0313, |
613 |
| - "lifetime of borrowed pointer outlives \ |
614 |
| - lifetime of captured variable `{}`...", |
615 |
| - self.tcx.local_var_name_str(upvar_id.var_id)); |
616 |
| - self.tcx.note_and_explain_region(&mut err, |
617 |
| - "...the borrowed pointer is valid for ", |
618 |
| - sub, |
619 |
| - "..."); |
620 |
| - self.tcx.note_and_explain_region(&mut err, |
621 |
| - &format!("...but `{}` is only valid for ", |
622 |
| - self.tcx.local_var_name_str(upvar_id.var_id)), |
623 |
| - sup, |
624 |
| - ""); |
625 |
| - err |
626 |
| - } |
627 |
| - infer::InfStackClosure(span) => { |
628 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0314, |
629 |
| - "closure outlives stack frame"); |
630 |
| - self.tcx.note_and_explain_region(&mut err, |
631 |
| - "...the closure must be valid for ", |
632 |
| - sub, |
633 |
| - "..."); |
634 |
| - self.tcx.note_and_explain_region(&mut err, |
635 |
| - "...but the closure's stack frame is only valid for ", |
636 |
| - sup, |
637 |
| - ""); |
638 |
| - err |
639 |
| - } |
640 |
| - infer::InvokeClosure(span) => { |
641 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0315, |
642 |
| - "cannot invoke closure outside of its lifetime"); |
643 |
| - self.tcx.note_and_explain_region(&mut err, |
644 |
| - "the closure is only valid for ", |
645 |
| - sup, |
646 |
| - ""); |
647 |
| - err |
648 |
| - } |
649 |
| - infer::DerefPointer(span) => { |
650 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0473, |
651 |
| - "dereference of reference outside its lifetime"); |
652 |
| - self.tcx.note_and_explain_region(&mut err, |
653 |
| - "the reference is only valid for ", |
654 |
| - sup, |
655 |
| - ""); |
656 |
| - err |
657 |
| - } |
658 |
| - infer::FreeVariable(span, id) => { |
659 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0474, |
660 |
| - "captured variable `{}` does not outlive the enclosing closure", |
661 |
| - self.tcx.local_var_name_str(id)); |
662 |
| - self.tcx.note_and_explain_region(&mut err, |
663 |
| - "captured variable is valid for ", |
664 |
| - sup, |
665 |
| - ""); |
666 |
| - self.tcx.note_and_explain_region(&mut err, |
667 |
| - "closure is valid for ", |
668 |
| - sub, |
669 |
| - ""); |
670 |
| - err |
671 |
| - } |
672 |
| - infer::IndexSlice(span) => { |
673 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0475, |
674 |
| - "index of slice outside its lifetime"); |
675 |
| - self.tcx.note_and_explain_region(&mut err, |
676 |
| - "the slice is only valid for ", |
677 |
| - sup, |
678 |
| - ""); |
679 |
| - err |
680 |
| - } |
681 |
| - infer::RelateObjectBound(span) => { |
682 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0476, |
683 |
| - "lifetime of the source pointer does not outlive \ |
684 |
| - lifetime bound of the object type"); |
685 |
| - self.tcx.note_and_explain_region(&mut err, |
686 |
| - "object type is valid for ", |
687 |
| - sub, |
688 |
| - ""); |
689 |
| - self.tcx.note_and_explain_region(&mut err, |
690 |
| - "source pointer is only valid for ", |
691 |
| - sup, |
692 |
| - ""); |
693 |
| - err |
694 |
| - } |
695 |
| - infer::RelateParamBound(span, ty) => { |
696 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0477, |
697 |
| - "the type `{}` does not fulfill the required lifetime", |
698 |
| - self.ty_to_string(ty)); |
699 |
| - self.tcx.note_and_explain_region(&mut err, |
700 |
| - "type must outlive ", |
701 |
| - sub, |
702 |
| - ""); |
703 |
| - err |
704 |
| - } |
705 |
| - infer::RelateRegionParamBound(span) => { |
706 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0478, |
707 |
| - "lifetime bound not satisfied"); |
708 |
| - self.tcx.note_and_explain_region(&mut err, |
709 |
| - "lifetime parameter instantiated with ", |
710 |
| - sup, |
711 |
| - ""); |
712 |
| - self.tcx.note_and_explain_region(&mut err, |
713 |
| - "but lifetime parameter must outlive ", |
714 |
| - sub, |
715 |
| - ""); |
716 |
| - err |
717 |
| - } |
718 |
| - infer::RelateDefaultParamBound(span, ty) => { |
719 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0479, |
720 |
| - "the type `{}` (provided as the value of \ |
721 |
| - a type parameter) is not valid at this point", |
722 |
| - self.ty_to_string(ty)); |
723 |
| - self.tcx.note_and_explain_region(&mut err, |
724 |
| - "type must outlive ", |
725 |
| - sub, |
726 |
| - ""); |
727 |
| - err |
728 |
| - } |
729 |
| - infer::CallRcvr(span) => { |
730 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0480, |
731 |
| - "lifetime of method receiver does not outlive \ |
732 |
| - the method call"); |
733 |
| - self.tcx.note_and_explain_region(&mut err, |
734 |
| - "the receiver is only valid for ", |
735 |
| - sup, |
736 |
| - ""); |
737 |
| - err |
738 |
| - } |
739 |
| - infer::CallArg(span) => { |
740 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0481, |
741 |
| - "lifetime of function argument does not outlive \ |
742 |
| - the function call"); |
743 |
| - self.tcx.note_and_explain_region(&mut err, |
744 |
| - "the function argument is only valid for ", |
745 |
| - sup, |
746 |
| - ""); |
747 |
| - err |
748 |
| - } |
749 |
| - infer::CallReturn(span) => { |
750 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0482, |
751 |
| - "lifetime of return value does not outlive \ |
752 |
| - the function call"); |
753 |
| - self.tcx.note_and_explain_region(&mut err, |
754 |
| - "the return value is only valid for ", |
755 |
| - sup, |
756 |
| - ""); |
757 |
| - err |
758 |
| - } |
759 |
| - infer::Operand(span) => { |
760 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0483, |
761 |
| - "lifetime of operand does not outlive \ |
762 |
| - the operation"); |
763 |
| - self.tcx.note_and_explain_region(&mut err, |
764 |
| - "the operand is only valid for ", |
765 |
| - sup, |
766 |
| - ""); |
767 |
| - err |
768 |
| - } |
769 |
| - infer::AddrOf(span) => { |
770 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0484, |
771 |
| - "reference is not valid at the time of borrow"); |
772 |
| - self.tcx.note_and_explain_region(&mut err, |
773 |
| - "the borrow is only valid for ", |
774 |
| - sup, |
775 |
| - ""); |
776 |
| - err |
777 |
| - } |
778 |
| - infer::AutoBorrow(span) => { |
779 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0485, |
780 |
| - "automatically reference is not valid \ |
781 |
| - at the time of borrow"); |
782 |
| - self.tcx.note_and_explain_region(&mut err, |
783 |
| - "the automatic borrow is only valid for ", |
784 |
| - sup, |
785 |
| - ""); |
786 |
| - err |
787 |
| - } |
788 |
| - infer::ExprTypeIsNotInScope(t, span) => { |
789 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0486, |
790 |
| - "type of expression contains references \ |
791 |
| - that are not valid during the expression: `{}`", |
792 |
| - self.ty_to_string(t)); |
793 |
| - self.tcx.note_and_explain_region(&mut err, |
794 |
| - "type is only valid for ", |
795 |
| - sup, |
796 |
| - ""); |
797 |
| - err |
798 |
| - } |
799 |
| - infer::SafeDestructor(span) => { |
800 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0487, |
801 |
| - "unsafe use of destructor: destructor might be called \ |
802 |
| - while references are dead"); |
803 |
| - // FIXME (22171): terms "super/subregion" are suboptimal |
804 |
| - self.tcx.note_and_explain_region(&mut err, |
805 |
| - "superregion: ", |
806 |
| - sup, |
807 |
| - ""); |
808 |
| - self.tcx.note_and_explain_region(&mut err, |
809 |
| - "subregion: ", |
810 |
| - sub, |
811 |
| - ""); |
812 |
| - err |
813 |
| - } |
814 |
| - infer::BindingTypeIsNotValidAtDecl(span) => { |
815 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0488, |
816 |
| - "lifetime of variable does not enclose its declaration"); |
817 |
| - self.tcx.note_and_explain_region(&mut err, |
818 |
| - "the variable is only valid for ", |
819 |
| - sup, |
820 |
| - ""); |
821 |
| - err |
822 |
| - } |
823 |
| - infer::ParameterInScope(_, span) => { |
824 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0489, |
825 |
| - "type/lifetime parameter not in scope here"); |
826 |
| - self.tcx.note_and_explain_region(&mut err, |
827 |
| - "the parameter is only valid for ", |
828 |
| - sub, |
829 |
| - ""); |
830 |
| - err |
831 |
| - } |
832 |
| - infer::DataBorrowed(ty, span) => { |
833 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0490, |
834 |
| - "a value of type `{}` is borrowed for too long", |
835 |
| - self.ty_to_string(ty)); |
836 |
| - self.tcx.note_and_explain_region(&mut err, "the type is valid for ", sub, ""); |
837 |
| - self.tcx.note_and_explain_region(&mut err, "but the borrow lasts for ", sup, ""); |
838 |
| - err |
839 |
| - } |
840 |
| - infer::ReferenceOutlivesReferent(ty, span) => { |
841 |
| - let mut err = struct_span_err!(self.tcx.sess, span, E0491, |
842 |
| - "in type `{}`, reference has a longer lifetime \ |
843 |
| - than the data it references", |
844 |
| - self.ty_to_string(ty)); |
845 |
| - self.tcx.note_and_explain_region(&mut err, |
846 |
| - "the pointer is valid for ", |
847 |
| - sub, |
848 |
| - ""); |
849 |
| - self.tcx.note_and_explain_region(&mut err, |
850 |
| - "but the referenced data is only valid for ", |
851 |
| - sup, |
852 |
| - ""); |
853 |
| - err |
854 |
| - } |
855 |
| - infer::CompareImplMethodObligation { span, |
856 |
| - item_name, |
857 |
| - impl_item_def_id, |
858 |
| - trait_item_def_id, |
859 |
| - lint_id } => { |
860 |
| - self.report_extra_impl_obligation(span, |
861 |
| - item_name, |
862 |
| - impl_item_def_id, |
863 |
| - trait_item_def_id, |
864 |
| - &format!("`{}: {}`", sup, sub), |
865 |
| - lint_id) |
866 |
| - } |
867 |
| - } |
868 |
| - } |
869 |
| - |
870 | 580 | fn report_sub_sup_conflict(&self,
|
871 | 581 | var_origin: RegionVariableOrigin,
|
872 | 582 | sub_origin: SubregionOrigin<'tcx>,
|
@@ -939,170 +649,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
939 | 649 | due to conflicting requirements",
|
940 | 650 | var_description)
|
941 | 651 | }
|
942 |
| - |
943 |
| - fn note_region_origin(&self, err: &mut DiagnosticBuilder, origin: &SubregionOrigin<'tcx>) { |
944 |
| - match *origin { |
945 |
| - infer::Subtype(ref trace) => { |
946 |
| - if let Some((expected, found)) = self.values_str(&trace.values) { |
947 |
| - // FIXME: do we want a "the" here? |
948 |
| - err.span_note( |
949 |
| - trace.cause.span, |
950 |
| - &format!("...so that {} (expected {}, found {})", |
951 |
| - trace.cause.as_requirement_str(), expected, found)); |
952 |
| - } else { |
953 |
| - // FIXME: this really should be handled at some earlier stage. Our |
954 |
| - // handling of region checking when type errors are present is |
955 |
| - // *terrible*. |
956 |
| - |
957 |
| - err.span_note( |
958 |
| - trace.cause.span, |
959 |
| - &format!("...so that {}", |
960 |
| - trace.cause.as_requirement_str())); |
961 |
| - } |
962 |
| - } |
963 |
| - infer::Reborrow(span) => { |
964 |
| - err.span_note( |
965 |
| - span, |
966 |
| - "...so that reference does not outlive \ |
967 |
| - borrowed content"); |
968 |
| - } |
969 |
| - infer::ReborrowUpvar(span, ref upvar_id) => { |
970 |
| - err.span_note( |
971 |
| - span, |
972 |
| - &format!( |
973 |
| - "...so that closure can access `{}`", |
974 |
| - self.tcx.local_var_name_str(upvar_id.var_id) |
975 |
| - .to_string())); |
976 |
| - } |
977 |
| - infer::InfStackClosure(span) => { |
978 |
| - err.span_note( |
979 |
| - span, |
980 |
| - "...so that closure does not outlive its stack frame"); |
981 |
| - } |
982 |
| - infer::InvokeClosure(span) => { |
983 |
| - err.span_note( |
984 |
| - span, |
985 |
| - "...so that closure is not invoked outside its lifetime"); |
986 |
| - } |
987 |
| - infer::DerefPointer(span) => { |
988 |
| - err.span_note( |
989 |
| - span, |
990 |
| - "...so that pointer is not dereferenced \ |
991 |
| - outside its lifetime"); |
992 |
| - } |
993 |
| - infer::FreeVariable(span, id) => { |
994 |
| - err.span_note( |
995 |
| - span, |
996 |
| - &format!("...so that captured variable `{}` \ |
997 |
| - does not outlive the enclosing closure", |
998 |
| - self.tcx.local_var_name_str(id))); |
999 |
| - } |
1000 |
| - infer::IndexSlice(span) => { |
1001 |
| - err.span_note( |
1002 |
| - span, |
1003 |
| - "...so that slice is not indexed outside the lifetime"); |
1004 |
| - } |
1005 |
| - infer::RelateObjectBound(span) => { |
1006 |
| - err.span_note( |
1007 |
| - span, |
1008 |
| - "...so that it can be closed over into an object"); |
1009 |
| - } |
1010 |
| - infer::CallRcvr(span) => { |
1011 |
| - err.span_note( |
1012 |
| - span, |
1013 |
| - "...so that method receiver is valid for the method call"); |
1014 |
| - } |
1015 |
| - infer::CallArg(span) => { |
1016 |
| - err.span_note( |
1017 |
| - span, |
1018 |
| - "...so that argument is valid for the call"); |
1019 |
| - } |
1020 |
| - infer::CallReturn(span) => { |
1021 |
| - err.span_note( |
1022 |
| - span, |
1023 |
| - "...so that return value is valid for the call"); |
1024 |
| - } |
1025 |
| - infer::Operand(span) => { |
1026 |
| - err.span_note( |
1027 |
| - span, |
1028 |
| - "...so that operand is valid for operation"); |
1029 |
| - } |
1030 |
| - infer::AddrOf(span) => { |
1031 |
| - err.span_note( |
1032 |
| - span, |
1033 |
| - "...so that reference is valid \ |
1034 |
| - at the time of borrow"); |
1035 |
| - } |
1036 |
| - infer::AutoBorrow(span) => { |
1037 |
| - err.span_note( |
1038 |
| - span, |
1039 |
| - "...so that auto-reference is valid \ |
1040 |
| - at the time of borrow"); |
1041 |
| - } |
1042 |
| - infer::ExprTypeIsNotInScope(t, span) => { |
1043 |
| - err.span_note( |
1044 |
| - span, |
1045 |
| - &format!("...so type `{}` of expression is valid during the \ |
1046 |
| - expression", |
1047 |
| - self.ty_to_string(t))); |
1048 |
| - } |
1049 |
| - infer::BindingTypeIsNotValidAtDecl(span) => { |
1050 |
| - err.span_note( |
1051 |
| - span, |
1052 |
| - "...so that variable is valid at time of its declaration"); |
1053 |
| - } |
1054 |
| - infer::ParameterInScope(_, span) => { |
1055 |
| - err.span_note( |
1056 |
| - span, |
1057 |
| - "...so that a type/lifetime parameter is in scope here"); |
1058 |
| - } |
1059 |
| - infer::DataBorrowed(ty, span) => { |
1060 |
| - err.span_note( |
1061 |
| - span, |
1062 |
| - &format!("...so that the type `{}` is not borrowed for too long", |
1063 |
| - self.ty_to_string(ty))); |
1064 |
| - } |
1065 |
| - infer::ReferenceOutlivesReferent(ty, span) => { |
1066 |
| - err.span_note( |
1067 |
| - span, |
1068 |
| - &format!("...so that the reference type `{}` \ |
1069 |
| - does not outlive the data it points at", |
1070 |
| - self.ty_to_string(ty))); |
1071 |
| - } |
1072 |
| - infer::RelateParamBound(span, t) => { |
1073 |
| - err.span_note( |
1074 |
| - span, |
1075 |
| - &format!("...so that the type `{}` \ |
1076 |
| - will meet its required lifetime bounds", |
1077 |
| - self.ty_to_string(t))); |
1078 |
| - } |
1079 |
| - infer::RelateDefaultParamBound(span, t) => { |
1080 |
| - err.span_note( |
1081 |
| - span, |
1082 |
| - &format!("...so that type parameter \ |
1083 |
| - instantiated with `{}`, \ |
1084 |
| - will meet its declared lifetime bounds", |
1085 |
| - self.ty_to_string(t))); |
1086 |
| - } |
1087 |
| - infer::RelateRegionParamBound(span) => { |
1088 |
| - err.span_note( |
1089 |
| - span, |
1090 |
| - "...so that the declared lifetime parameter bounds \ |
1091 |
| - are satisfied"); |
1092 |
| - } |
1093 |
| - infer::SafeDestructor(span) => { |
1094 |
| - err.span_note( |
1095 |
| - span, |
1096 |
| - "...so that references are valid when the destructor \ |
1097 |
| - runs"); |
1098 |
| - } |
1099 |
| - infer::CompareImplMethodObligation { span, .. } => { |
1100 |
| - err.span_note( |
1101 |
| - span, |
1102 |
| - "...so that the definition in impl matches the definition from the trait"); |
1103 |
| - } |
1104 |
| - } |
1105 |
| - } |
1106 | 652 | }
|
1107 | 653 |
|
1108 | 654 | impl<'tcx> ObligationCause<'tcx> {
|
|
0 commit comments