Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0b5bf67

Browse files
authoredMar 1, 2017
Rollup merge of #40128 - cengizIO:master, r=nikomatsakis
Move two large error_reporting fn's to a separate file Hello! I tried to make `librustc/infer/error_reporting,rs` more readable by modularizing it and moving its two largest functions to a separate file. If you have any suggestions, please send it right away! 🚀 Thanks goes to @nikomatsakis for supporting.
2 parents 0a008b9 + e136bf6 commit 0b5bf67

File tree

3 files changed

+445
-467
lines changed

3 files changed

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

‎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,
@@ -1295,7 +1295,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12951295
// this infcx was in use. This is totally hokey but
12961296
// otherwise we have a hard time separating legit region
12971297
// errors from silly ones.
1298-
self.report_region_errors(&errors); // see error_reporting.rs
1298+
self.report_region_errors(&errors); // see error_reporting module
12991299
}
13001300
}
13011301

0 commit comments

Comments
 (0)
Please sign in to comment.