Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize dependencies on trait and infer inside librustc #67970

Merged
merged 18 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
47256b8
Remove private methods from TyCtxt impl block: rustc::infer::error_re…
cjgillot Jan 5, 2020
811adb5
Remove private methods from TyCtxt impl block: rustc::middle::stability.
cjgillot Jan 5, 2020
c1afe6a
Remove private methods from TyCtxt impl block: rustc::trait::object_s…
cjgillot Jan 5, 2020
0d9f4fb
Remove trivial function.
cjgillot Jan 5, 2020
640cae2
Remove private methods from TyCtxt impl block: rustc::ty::outlives.
cjgillot Jan 5, 2020
7118e33
Remove private methods from TyCtxt impl block: rustc::ty::print::pretty.
cjgillot Jan 5, 2020
d53bf7a
Make rustc::infer::error_reporting::{note_and_explain_free_region, no…
cjgillot Jan 5, 2020
0b1521e
Make rustc::traits::error_reporting::{recursive_type_with_infinite_si…
cjgillot Jan 5, 2020
7770bce
Make rustc::traits::object_safety::{astconv_object_safety_violations,…
cjgillot Jan 5, 2020
a80bff8
Move normalize_erasing_regions to rustc::ty.
cjgillot Jan 5, 2020
56a0aec
Move subst_and_normalize_erasing_regionsto rustc::ty.
cjgillot Jan 5, 2020
787cd54
Make traits::util::* free functions.
cjgillot Jan 5, 2020
73667af
Move ty::wf to traits.
cjgillot Jan 5, 2020
e905d5d
Move structural_match to rustc::traits.
cjgillot Jan 5, 2020
24d09c7
Move free_region_map to rustc::ty.
cjgillot Jan 5, 2020
86ec4b5
Move required_region_bounds to rustc::infer::opaque_types.
cjgillot Jan 5, 2020
f629baf
Move magic traits queries to rustc::traits::drop.
cjgillot Jan 5, 2020
700ac84
Rename traits::drop -> traits::misc.
cjgillot Jan 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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