Skip to content

Commit

Permalink
Auto merge of #67970 - cjgillot:inherent, r=Centril
Browse files Browse the repository at this point in the history
Minimize dependencies on trait and infer inside librustc

Split from #67953

All commits should pass check on their own.

r? @Centril
  • Loading branch information
bors committed Jan 7, 2020
2 parents 8597644 + 700ac84 commit 7e393b5
Show file tree
Hide file tree
Showing 42 changed files with 1,512 additions and 1,442 deletions.
381 changes: 192 additions & 189 deletions src/librustc/infer/error_reporting/mod.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Error Reporting for static impl Traits.

use crate::infer::error_reporting::msg_span_from_free_region;
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::ty::{BoundRegion, FreeRegion, RegionKind};
Expand Down Expand Up @@ -32,7 +33,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
);
err.span_label(sup_origin.span(), "...but this borrow...");

let (lifetime, lt_sp_opt) = self.tcx().msg_span_from_free_region(sup_r);
let (lifetime, lt_sp_opt) = msg_span_from_free_region(self.tcx(), sup_r);
if let Some(lifetime_sp) = lt_sp_opt {
err.span_note(lifetime_sp, &format!("...can't outlive {}", lifetime));
}
Expand Down
105 changes: 70 additions & 35 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::infer::error_reporting::note_and_explain_region;
use crate::infer::{self, InferCtxt, SubregionOrigin};
use crate::middle::region;
use crate::ty::error::TypeError;
Expand Down Expand Up @@ -167,8 +168,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
infer::Subtype(box trace) => {
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
let mut err = self.report_and_explain_type_error(trace, &terr);
self.tcx.note_and_explain_region(region_scope_tree, &mut err, "", sup, "...");
self.tcx.note_and_explain_region(
note_and_explain_region(self.tcx, region_scope_tree, &mut err, "", sup, "...");
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"...does not necessarily outlive ",
Expand All @@ -185,14 +187,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"lifetime of reference outlives lifetime of \
borrowed content..."
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"...the reference is valid for ",
sub,
"...",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"...but the borrowed content is only valid for ",
Expand All @@ -211,14 +215,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
of captured variable `{}`...",
var_name
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"...the borrowed pointer is valid for ",
sub,
"...",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
&format!("...but `{}` is only valid for ", var_name),
Expand All @@ -230,14 +236,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
infer::InfStackClosure(span) => {
let mut err =
struct_span_err!(self.tcx.sess, span, E0314, "closure outlives stack frame");
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"...the closure must be valid for ",
sub,
"...",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"...but the closure's stack frame is only valid \
Expand All @@ -254,7 +262,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
E0315,
"cannot invoke closure outside of its lifetime"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the closure is only valid for ",
Expand All @@ -270,7 +279,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
E0473,
"dereference of reference outside its lifetime"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the reference is only valid for ",
Expand All @@ -288,14 +298,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
enclosing closure",
self.tcx.hir().name(id)
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"captured variable is valid for ",
sup,
"",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"closure is valid for ",
Expand All @@ -311,7 +323,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
E0475,
"index of slice outside its lifetime"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the slice is only valid for ",
Expand All @@ -328,14 +341,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"lifetime of the source pointer does not outlive \
lifetime bound of the object type"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"object type is valid for ",
sub,
"",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"source pointer is only valid for ",
Expand All @@ -354,14 +369,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.ty_to_string(ty)
);
match *sub {
ty::ReStatic => self.tcx.note_and_explain_region(
ty::ReStatic => note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"type must satisfy ",
sub,
"",
),
_ => self.tcx.note_and_explain_region(
_ => note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"type must outlive ",
Expand All @@ -374,14 +391,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
infer::RelateRegionParamBound(span) => {
let mut err =
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"lifetime parameter instantiated with ",
sup,
"",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"but lifetime parameter must outlive ",
Expand All @@ -399,7 +418,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
parameter) is not valid at this point",
self.ty_to_string(ty)
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"type must outlive ",
Expand All @@ -416,7 +436,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"lifetime of method receiver does not outlive the \
method call"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the receiver is only valid for ",
Expand All @@ -433,7 +454,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"lifetime of function argument does not outlive \
the function call"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the function argument is only valid for ",
Expand All @@ -450,7 +472,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"lifetime of return value does not outlive the \
function call"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the return value is only valid for ",
Expand All @@ -467,7 +490,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"lifetime of operand does not outlive the \
operation"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the operand is only valid for ",
Expand All @@ -483,7 +507,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
E0484,
"reference is not valid at the time of borrow"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the borrow is only valid for ",
Expand All @@ -500,7 +525,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"automatically reference is not valid at the time \
of borrow"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the automatic borrow is only valid for ",
Expand All @@ -518,7 +544,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
not valid during the expression: `{}`",
self.ty_to_string(t)
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"type is only valid for ",
Expand All @@ -536,14 +563,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
called while references are dead"
);
// FIXME (22171): terms "super/subregion" are suboptimal
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"superregion: ",
sup,
"",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"subregion: ",
Expand All @@ -560,7 +589,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"lifetime of variable does not enclose its \
declaration"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the variable is only valid for ",
Expand All @@ -576,7 +606,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
E0489,
"type/lifetime parameter not in scope here"
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the parameter is only valid for ",
Expand All @@ -593,14 +624,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"a value of type `{}` is borrowed for too long",
self.ty_to_string(ty)
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the type is valid for ",
sub,
"",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"but the borrow lasts for ",
Expand All @@ -618,14 +651,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
than the data it references",
self.ty_to_string(ty)
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"the pointer is valid for ",
sub,
"",
);
self.tcx.note_and_explain_region(
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"but the referenced data is only valid for ",
Expand Down
Loading

0 comments on commit 7e393b5

Please sign in to comment.