Skip to content

Commit d21b0e3

Browse files
author
Cengiz Can
committedFeb 27, 2017
Move two large error_reporting fn's to a separate file
·
1.88.01.17.0
1 parent 0ed75e1 commit d21b0e3

File tree

3 files changed

+478
-467
lines changed

3 files changed

+478
-467
lines changed
 

‎src/librustc/infer/error_reporting.rs renamed to ‎src/librustc/infer/error_reporting/mod.rs

Lines changed: 8 additions & 462 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,25 @@
5555
//! ported to this system, and which relies on string concatenation at the
5656
//! time of error detection.
5757
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};
6862

69-
use hir::map as hir_map;
63+
use std::fmt;
7064
use hir;
71-
65+
use hir::map as hir_map;
7266
use hir::def_id::DefId;
73-
use infer;
7467
use middle::region;
7568
use traits::{ObligationCause, ObligationCauseCode};
7669
use ty::{self, TyCtxt, TypeFoldable};
7770
use ty::{Region, Issue32330};
7871
use ty::error::TypeError;
79-
80-
use std::fmt;
8172
use syntax_pos::{Pos, Span};
8273
use errors::DiagnosticBuilder;
8374

75+
mod note;
76+
8477
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
8578
pub fn note_and_explain_region(self,
8679
err: &mut DiagnosticBuilder,
@@ -584,289 +577,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
584577
err.emit();
585578
}
586579

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-
870580
fn report_sub_sup_conflict(&self,
871581
var_origin: RegionVariableOrigin,
872582
sub_origin: SubregionOrigin<'tcx>,
@@ -939,170 +649,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
939649
due to conflicting requirements",
940650
var_description)
941651
}
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-
}
1106652
}
1107653

1108654
impl<'tcx> ObligationCause<'tcx> {
Lines changed: 465 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,465 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use infer::{self, InferCtxt, SubregionOrigin};
12+
use ty::Region;
13+
use ty::error::TypeError;
14+
use errors::DiagnosticBuilder;
15+
16+
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
17+
pub fn note_region_origin(&self, err: &mut DiagnosticBuilder, origin: &SubregionOrigin<'tcx>) {
18+
match *origin {
19+
infer::Subtype(ref trace) => {
20+
if let Some((expected, found)) = self.values_str(&trace.values) {
21+
// FIXME: do we want a "the" here?
22+
err.span_note(
23+
trace.cause.span,
24+
&format!("...so that {} (expected {}, found {})",
25+
trace.cause.as_requirement_str(), expected, found));
26+
} else {
27+
// FIXME: this really should be handled at some earlier stage. Our
28+
// handling of region checking when type errors are present is
29+
// *terrible*.
30+
31+
err.span_note(
32+
trace.cause.span,
33+
&format!("...so that {}",
34+
trace.cause.as_requirement_str()));
35+
}
36+
}
37+
infer::Reborrow(span) => {
38+
err.span_note(
39+
span,
40+
"...so that reference does not outlive \
41+
borrowed content");
42+
}
43+
infer::ReborrowUpvar(span, ref upvar_id) => {
44+
err.span_note(
45+
span,
46+
&format!(
47+
"...so that closure can access `{}`",
48+
self.tcx.local_var_name_str(upvar_id.var_id)
49+
.to_string()));
50+
}
51+
infer::InfStackClosure(span) => {
52+
err.span_note(
53+
span,
54+
"...so that closure does not outlive its stack frame");
55+
}
56+
infer::InvokeClosure(span) => {
57+
err.span_note(
58+
span,
59+
"...so that closure is not invoked outside its lifetime");
60+
}
61+
infer::DerefPointer(span) => {
62+
err.span_note(
63+
span,
64+
"...so that pointer is not dereferenced \
65+
outside its lifetime");
66+
}
67+
infer::FreeVariable(span, id) => {
68+
err.span_note(
69+
span,
70+
&format!("...so that captured variable `{}` \
71+
does not outlive the enclosing closure",
72+
self.tcx.local_var_name_str(id)));
73+
}
74+
infer::IndexSlice(span) => {
75+
err.span_note(
76+
span,
77+
"...so that slice is not indexed outside the lifetime");
78+
}
79+
infer::RelateObjectBound(span) => {
80+
err.span_note(
81+
span,
82+
"...so that it can be closed over into an object");
83+
}
84+
infer::CallRcvr(span) => {
85+
err.span_note(
86+
span,
87+
"...so that method receiver is valid for the method call");
88+
}
89+
infer::CallArg(span) => {
90+
err.span_note(
91+
span,
92+
"...so that argument is valid for the call");
93+
}
94+
infer::CallReturn(span) => {
95+
err.span_note(
96+
span,
97+
"...so that return value is valid for the call");
98+
}
99+
infer::Operand(span) => {
100+
err.span_note(
101+
span,
102+
"...so that operand is valid for operation");
103+
}
104+
infer::AddrOf(span) => {
105+
err.span_note(
106+
span,
107+
"...so that reference is valid \
108+
at the time of borrow");
109+
}
110+
infer::AutoBorrow(span) => {
111+
err.span_note(
112+
span,
113+
"...so that auto-reference is valid \
114+
at the time of borrow");
115+
}
116+
infer::ExprTypeIsNotInScope(t, span) => {
117+
err.span_note(
118+
span,
119+
&format!("...so type `{}` of expression is valid during the \
120+
expression",
121+
self.ty_to_string(t)));
122+
}
123+
infer::BindingTypeIsNotValidAtDecl(span) => {
124+
err.span_note(
125+
span,
126+
"...so that variable is valid at time of its declaration");
127+
}
128+
infer::ParameterInScope(_, span) => {
129+
err.span_note(
130+
span,
131+
"...so that a type/lifetime parameter is in scope here");
132+
}
133+
infer::DataBorrowed(ty, span) => {
134+
err.span_note(
135+
span,
136+
&format!("...so that the type `{}` is not borrowed for too long",
137+
self.ty_to_string(ty)));
138+
}
139+
infer::ReferenceOutlivesReferent(ty, span) => {
140+
err.span_note(
141+
span,
142+
&format!("...so that the reference type `{}` \
143+
does not outlive the data it points at",
144+
self.ty_to_string(ty)));
145+
}
146+
infer::RelateParamBound(span, t) => {
147+
err.span_note(
148+
span,
149+
&format!("...so that the type `{}` \
150+
will meet its required lifetime bounds",
151+
self.ty_to_string(t)));
152+
}
153+
infer::RelateDefaultParamBound(span, t) => {
154+
err.span_note(
155+
span,
156+
&format!("...so that type parameter \
157+
instantiated with `{}`, \
158+
will meet its declared lifetime bounds",
159+
self.ty_to_string(t)));
160+
}
161+
infer::RelateRegionParamBound(span) => {
162+
err.span_note(
163+
span,
164+
"...so that the declared lifetime parameter bounds \
165+
are satisfied");
166+
}
167+
infer::SafeDestructor(span) => {
168+
err.span_note(
169+
span,
170+
"...so that references are valid when the destructor \
171+
runs");
172+
}
173+
infer::CompareImplMethodObligation { span, .. } => {
174+
err.span_note(
175+
span,
176+
"...so that the definition in impl matches the definition from the trait");
177+
}
178+
}
179+
}
180+
181+
pub fn report_concrete_failure(&self,
182+
origin: SubregionOrigin<'tcx>,
183+
sub: &'tcx Region,
184+
sup: &'tcx Region)
185+
-> DiagnosticBuilder<'tcx> {
186+
match origin {
187+
infer::Subtype(trace) => {
188+
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
189+
self.report_and_explain_type_error(trace, &terr)
190+
}
191+
infer::Reborrow(span) => {
192+
let mut err = struct_span_err!(self.tcx.sess, span, E0312,
193+
"lifetime of reference outlives \
194+
lifetime of borrowed content...");
195+
self.tcx.note_and_explain_region(&mut err,
196+
"...the reference is valid for ",
197+
sub,
198+
"...");
199+
self.tcx.note_and_explain_region(&mut err,
200+
"...but the borrowed content is only valid for ",
201+
sup,
202+
"");
203+
err
204+
}
205+
infer::ReborrowUpvar(span, ref upvar_id) => {
206+
let mut err = struct_span_err!(self.tcx.sess, span, E0313,
207+
"lifetime of borrowed pointer outlives \
208+
lifetime of captured variable `{}`...",
209+
self.tcx.local_var_name_str(upvar_id.var_id));
210+
self.tcx.note_and_explain_region(&mut err,
211+
"...the borrowed pointer is valid for ",
212+
sub,
213+
"...");
214+
self.tcx.note_and_explain_region(&mut err,
215+
&format!("...but `{}` is only valid for ",
216+
self.tcx.local_var_name_str(upvar_id.var_id)),
217+
sup,
218+
"");
219+
err
220+
}
221+
infer::InfStackClosure(span) => {
222+
let mut err = struct_span_err!(self.tcx.sess, span, E0314,
223+
"closure outlives stack frame");
224+
self.tcx.note_and_explain_region(&mut err,
225+
"...the closure must be valid for ",
226+
sub,
227+
"...");
228+
self.tcx.note_and_explain_region(&mut err,
229+
"...but the closure's stack frame is only valid for ",
230+
sup,
231+
"");
232+
err
233+
}
234+
infer::InvokeClosure(span) => {
235+
let mut err = struct_span_err!(self.tcx.sess, span, E0315,
236+
"cannot invoke closure outside of its lifetime");
237+
self.tcx.note_and_explain_region(&mut err,
238+
"the closure is only valid for ",
239+
sup,
240+
"");
241+
err
242+
}
243+
infer::DerefPointer(span) => {
244+
let mut err = struct_span_err!(self.tcx.sess, span, E0473,
245+
"dereference of reference outside its lifetime");
246+
self.tcx.note_and_explain_region(&mut err,
247+
"the reference is only valid for ",
248+
sup,
249+
"");
250+
err
251+
}
252+
infer::FreeVariable(span, id) => {
253+
let mut err = struct_span_err!(self.tcx.sess, span, E0474,
254+
"captured variable `{}` does not outlive the enclosing closure",
255+
self.tcx.local_var_name_str(id));
256+
self.tcx.note_and_explain_region(&mut err,
257+
"captured variable is valid for ",
258+
sup,
259+
"");
260+
self.tcx.note_and_explain_region(&mut err,
261+
"closure is valid for ",
262+
sub,
263+
"");
264+
err
265+
}
266+
infer::IndexSlice(span) => {
267+
let mut err = struct_span_err!(self.tcx.sess, span, E0475,
268+
"index of slice outside its lifetime");
269+
self.tcx.note_and_explain_region(&mut err,
270+
"the slice is only valid for ",
271+
sup,
272+
"");
273+
err
274+
}
275+
infer::RelateObjectBound(span) => {
276+
let mut err = struct_span_err!(self.tcx.sess, span, E0476,
277+
"lifetime of the source pointer does not outlive \
278+
lifetime bound of the object type");
279+
self.tcx.note_and_explain_region(&mut err,
280+
"object type is valid for ",
281+
sub,
282+
"");
283+
self.tcx.note_and_explain_region(&mut err,
284+
"source pointer is only valid for ",
285+
sup,
286+
"");
287+
err
288+
}
289+
infer::RelateParamBound(span, ty) => {
290+
let mut err = struct_span_err!(self.tcx.sess, span, E0477,
291+
"the type `{}` does not fulfill the required lifetime",
292+
self.ty_to_string(ty));
293+
self.tcx.note_and_explain_region(&mut err,
294+
"type must outlive ",
295+
sub,
296+
"");
297+
err
298+
}
299+
infer::RelateRegionParamBound(span) => {
300+
let mut err = struct_span_err!(self.tcx.sess, span, E0478,
301+
"lifetime bound not satisfied");
302+
self.tcx.note_and_explain_region(&mut err,
303+
"lifetime parameter instantiated with ",
304+
sup,
305+
"");
306+
self.tcx.note_and_explain_region(&mut err,
307+
"but lifetime parameter must outlive ",
308+
sub,
309+
"");
310+
err
311+
}
312+
infer::RelateDefaultParamBound(span, ty) => {
313+
let mut err = struct_span_err!(self.tcx.sess, span, E0479,
314+
"the type `{}` (provided as the value of \
315+
a type parameter) is not valid at this point",
316+
self.ty_to_string(ty));
317+
self.tcx.note_and_explain_region(&mut err,
318+
"type must outlive ",
319+
sub,
320+
"");
321+
err
322+
}
323+
infer::CallRcvr(span) => {
324+
let mut err = struct_span_err!(self.tcx.sess, span, E0480,
325+
"lifetime of method receiver does not outlive \
326+
the method call");
327+
self.tcx.note_and_explain_region(&mut err,
328+
"the receiver is only valid for ",
329+
sup,
330+
"");
331+
err
332+
}
333+
infer::CallArg(span) => {
334+
let mut err = struct_span_err!(self.tcx.sess, span, E0481,
335+
"lifetime of function argument does not outlive \
336+
the function call");
337+
self.tcx.note_and_explain_region(&mut err,
338+
"the function argument is only valid for ",
339+
sup,
340+
"");
341+
err
342+
}
343+
infer::CallReturn(span) => {
344+
let mut err = struct_span_err!(self.tcx.sess, span, E0482,
345+
"lifetime of return value does not outlive \
346+
the function call");
347+
self.tcx.note_and_explain_region(&mut err,
348+
"the return value is only valid for ",
349+
sup,
350+
"");
351+
err
352+
}
353+
infer::Operand(span) => {
354+
let mut err = struct_span_err!(self.tcx.sess, span, E0483,
355+
"lifetime of operand does not outlive \
356+
the operation");
357+
self.tcx.note_and_explain_region(&mut err,
358+
"the operand is only valid for ",
359+
sup,
360+
"");
361+
err
362+
}
363+
infer::AddrOf(span) => {
364+
let mut err = struct_span_err!(self.tcx.sess, span, E0484,
365+
"reference is not valid at the time of borrow");
366+
self.tcx.note_and_explain_region(&mut err,
367+
"the borrow is only valid for ",
368+
sup,
369+
"");
370+
err
371+
}
372+
infer::AutoBorrow(span) => {
373+
let mut err = struct_span_err!(self.tcx.sess, span, E0485,
374+
"automatically reference is not valid \
375+
at the time of borrow");
376+
self.tcx.note_and_explain_region(&mut err,
377+
"the automatic borrow is only valid for ",
378+
sup,
379+
"");
380+
err
381+
}
382+
infer::ExprTypeIsNotInScope(t, span) => {
383+
let mut err = struct_span_err!(self.tcx.sess, span, E0486,
384+
"type of expression contains references \
385+
that are not valid during the expression: `{}`",
386+
self.ty_to_string(t));
387+
self.tcx.note_and_explain_region(&mut err,
388+
"type is only valid for ",
389+
sup,
390+
"");
391+
err
392+
}
393+
infer::SafeDestructor(span) => {
394+
let mut err = struct_span_err!(self.tcx.sess, span, E0487,
395+
"unsafe use of destructor: destructor might be called \
396+
while references are dead");
397+
// FIXME (22171): terms "super/subregion" are suboptimal
398+
self.tcx.note_and_explain_region(&mut err,
399+
"superregion: ",
400+
sup,
401+
"");
402+
self.tcx.note_and_explain_region(&mut err,
403+
"subregion: ",
404+
sub,
405+
"");
406+
err
407+
}
408+
infer::BindingTypeIsNotValidAtDecl(span) => {
409+
let mut err = struct_span_err!(self.tcx.sess, span, E0488,
410+
"lifetime of variable does not enclose its declaration");
411+
self.tcx.note_and_explain_region(&mut err,
412+
"the variable is only valid for ",
413+
sup,
414+
"");
415+
err
416+
}
417+
infer::ParameterInScope(_, span) => {
418+
let mut err = struct_span_err!(self.tcx.sess, span, E0489,
419+
"type/lifetime parameter not in scope here");
420+
self.tcx.note_and_explain_region(&mut err,
421+
"the parameter is only valid for ",
422+
sub,
423+
"");
424+
err
425+
}
426+
infer::DataBorrowed(ty, span) => {
427+
let mut err = struct_span_err!(self.tcx.sess, span, E0490,
428+
"a value of type `{}` is borrowed for too long",
429+
self.ty_to_string(ty));
430+
self.tcx.note_and_explain_region(&mut err, "the type is valid for ", sub, "");
431+
self.tcx.note_and_explain_region(&mut err, "but the borrow lasts for ", sup, "");
432+
err
433+
}
434+
infer::ReferenceOutlivesReferent(ty, span) => {
435+
let mut err = struct_span_err!(self.tcx.sess, span, E0491,
436+
"in type `{}`, reference has a longer lifetime \
437+
than the data it references",
438+
self.ty_to_string(ty));
439+
self.tcx.note_and_explain_region(&mut err,
440+
"the pointer is valid for ",
441+
sub,
442+
"");
443+
self.tcx.note_and_explain_region(&mut err,
444+
"but the referenced data is only valid for ",
445+
sup,
446+
"");
447+
err
448+
}
449+
infer::CompareImplMethodObligation {
450+
span,
451+
item_name,
452+
impl_item_def_id,
453+
trait_item_def_id,
454+
lint_id
455+
} => {
456+
self.report_extra_impl_obligation(span,
457+
item_name,
458+
impl_item_def_id,
459+
trait_item_def_id,
460+
&format!("`{}: {}`", sup, sub),
461+
lint_id)
462+
}
463+
}
464+
}
465+
}

‎src/librustc/infer/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
210210
/// region that each late-bound region was replaced with.
211211
pub type SkolemizationMap<'tcx> = FxHashMap<ty::BoundRegion, &'tcx ty::Region>;
212212

213-
/// See `error_reporting.rs` for more details
213+
/// See `error_reporting` module for more details
214214
#[derive(Clone, Debug)]
215215
pub enum ValuePairs<'tcx> {
216216
Types(ExpectedFound<Ty<'tcx>>),
@@ -221,7 +221,7 @@ pub enum ValuePairs<'tcx> {
221221
/// The trace designates the path through inference that we took to
222222
/// encounter an error or subtyping constraint.
223223
///
224-
/// See `error_reporting.rs` for more details.
224+
/// See `error_reporting` module for more details.
225225
#[derive(Clone)]
226226
pub struct TypeTrace<'tcx> {
227227
cause: ObligationCause<'tcx>,
@@ -230,7 +230,7 @@ pub struct TypeTrace<'tcx> {
230230

231231
/// The origin of a `r1 <= r2` constraint.
232232
///
233-
/// See `error_reporting.rs` for more details
233+
/// See `error_reporting` module for more details
234234
#[derive(Clone, Debug)]
235235
pub enum SubregionOrigin<'tcx> {
236236
// Arose from a subtyping relation
@@ -348,7 +348,7 @@ pub enum LateBoundRegionConversionTime {
348348

349349
/// Reasons to create a region inference variable
350350
///
351-
/// See `error_reporting.rs` for more details
351+
/// See `error_reporting` module for more details
352352
#[derive(Clone, Debug)]
353353
pub enum RegionVariableOrigin {
354354
// Region variables created for ill-categorized reasons,
@@ -1292,7 +1292,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12921292
// this infcx was in use. This is totally hokey but
12931293
// otherwise we have a hard time separating legit region
12941294
// errors from silly ones.
1295-
self.report_region_errors(&errors); // see error_reporting.rs
1295+
self.report_region_errors(&errors); // see error_reporting module
12961296
}
12971297
}
12981298

0 commit comments

Comments
 (0)
Please sign in to comment.