Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f3335c6
simplify `AnonTypeDecl` in the impl trait code
nikomatsakis Dec 6, 2017
f6741d0
region_infer/values.rs: rustfmt
nikomatsakis Dec 6, 2017
e447b54
Add tracking of causes for nll
Nashenas88 Nov 21, 2017
39b0e49
rustfmt: borrow_check/mod.rs
nikomatsakis Dec 14, 2017
594c386
dump out causal information for "free region" errors
nikomatsakis Dec 7, 2017
741ef41
use Rc to store nonlexical_regioncx in Borrows
nikomatsakis Dec 7, 2017
0e64a75
integrate -Znll-dump-cause into borrowck
nikomatsakis Dec 7, 2017
fe89f4b
get the `DefiningTy` from the `body_owner_kind` not type
nikomatsakis Dec 8, 2017
4a967c9
propagate `region_bound_pairs` into MIR type-check
nikomatsakis Dec 8, 2017
e96f4be
extract `instantiate_anon_types` to the `InferCtxt`
nikomatsakis Dec 9, 2017
8e64ba8
extract `constrain_anon_types` to the `InferCtxt`
nikomatsakis Dec 9, 2017
7f50e7c
extract the writeback code for anon types into InferCtxt
nikomatsakis Dec 9, 2017
a66c651
pass `UniversalRegions` to MIR type-checker instead of fields
nikomatsakis Dec 10, 2017
da63aaa
extract `input_output` code into its own module
nikomatsakis Dec 10, 2017
93afb1a
connect NLL type checker to the impl trait code
nikomatsakis Dec 10, 2017
58b0506
Move MirVisitable to visit.rs
spastorino Dec 12, 2017
6d2987c
Move categorize logic out of visit_local function
nikomatsakis Dec 20, 2017
3a185a5
Add three point error handling to borrowck
spastorino Dec 12, 2017
e28d03f
only dump causes if we have nothing better
nikomatsakis Dec 14, 2017
4089d14
move nice-region-error reporting into its own module
nikomatsakis Dec 12, 2017
93498e0
make `util` fns private to nice_region_error
nikomatsakis Dec 12, 2017
3720242
extract `find_anon_type` into its own module
nikomatsakis Dec 12, 2017
a28ab84
nice_region_error: rustfmt
nikomatsakis Dec 12, 2017
cba4732
introduce a `NiceRegionError` type and define methods on that
nikomatsakis Dec 12, 2017
de56308
use `Option<ErrorReported>` instead of `bool`
nikomatsakis Dec 12, 2017
94e7072
give precedence to `try_report_named_anon_conflict` method
nikomatsakis Dec 12, 2017
6b39781
connect NLL machinery to the `NiceRegionError` code
nikomatsakis Dec 12, 2017
3788f42
refactor `report_generic_bound_failure` to be usable by NLL code
nikomatsakis Dec 19, 2017
508a831
use `report_generic_bound_failure` when we can in the compiler
nikomatsakis Dec 19, 2017
95b6148
Add nll_dump_cause helper to Session
spastorino Dec 19, 2017
0b2db1e
Add nll feature and make nll imply nll_dump_cause
spastorino Dec 19, 2017
2019d69
feature nll implies two-phase-borrows
spastorino Dec 19, 2017
e980fb8
feature nll implies borrowck=mir
spastorino Dec 19, 2017
cfa4ffa
document and tweak the nll, use_mir, etc helpers
nikomatsakis Dec 20, 2017
80c510e
when using feature(nll), don't warn about AST-based region errors
nikomatsakis Dec 20, 2017
cba8256
add some run-pass tests for NLL showing that things work as expected
nikomatsakis Dec 7, 2017
3f490ca
convert region-liveness-drop{-,-no-}may-dangle.rs into ui tests
nikomatsakis Dec 20, 2017
4f549fe
improve comment about instantiating anon types
nikomatsakis Dec 20, 2017
d925f4d
fix truncated comment
nikomatsakis Dec 20, 2017
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
Prev Previous commit
Next Next commit
connect NLL machinery to the NiceRegionError code
  • Loading branch information
nikomatsakis committed Dec 20, 2017
commit 6b39781df6ad149c4fb5cb7d714daf1b7168081f
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ mod note;

mod need_type_info;

mod nice_region_error;
pub mod nice_region_error;

impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn note_and_explain_region(self,
Expand Down
34 changes: 28 additions & 6 deletions src/librustc_mir/borrow_check/nll/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ use rustc::infer::NLLRegionVariableOrigin;
use rustc::infer::RegionObligation;
use rustc::infer::RegionVariableOrigin;
use rustc::infer::SubregionOrigin;
use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
use rustc::infer::region_constraints::{GenericKind, VarOrigins};
use rustc::mir::{ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements,
Local, Location, Mir};
use rustc::traits::ObligationCause;
use rustc::ty::{self, RegionVid, Ty, TypeFoldable};
use rustc::util::common::ErrorReported;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_errors::DiagnosticBuilder;
use std::fmt;
Expand Down Expand Up @@ -230,7 +232,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// `num_region_variables` valid inference variables; the first N
/// of those will be constant regions representing the free
/// regions defined in `universal_regions`.
pub fn new(
pub(crate) fn new(
var_origins: VarOrigins,
universal_regions: UniversalRegions<'tcx>,
mir: &Mir<'tcx>,
Expand Down Expand Up @@ -430,7 +432,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {

self.check_type_tests(infcx, mir, outlives_requirements.as_mut());

self.check_universal_regions(infcx, mir, outlives_requirements.as_mut());
self.check_universal_regions(infcx, mir, mir_def_id, outlives_requirements.as_mut());

let outlives_requirements = outlives_requirements.unwrap_or(vec![]);

Expand Down Expand Up @@ -807,6 +809,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self,
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
mir: &Mir<'tcx>,
mir_def_id: DefId,
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'gcx>>>,
) {
// The universal regions are always found in a prefix of the
Expand All @@ -819,7 +822,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// they did not grow too large, accumulating any requirements
// for our caller into the `outlives_requirements` vector.
for (fr, _) in universal_definitions {
self.check_universal_region(infcx, mir, fr, &mut propagated_outlives_requirements);
self.check_universal_region(
infcx,
mir,
mir_def_id,
fr,
&mut propagated_outlives_requirements,
);
}
}

Expand All @@ -835,6 +844,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self,
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
mir: &Mir<'tcx>,
mir_def_id: DefId,
longer_fr: RegionVid,
propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'gcx>>>,
) {
Expand Down Expand Up @@ -891,7 +901,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Note: in this case, we use the unapproximated regions
// to report the error. This gives better error messages
// in some cases.
self.report_error(infcx, mir, longer_fr, shorter_fr, blame_span);
self.report_error(infcx, mir, mir_def_id, longer_fr, shorter_fr, blame_span);
}
}

Expand All @@ -907,18 +917,30 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self,
infcx: &InferCtxt<'_, '_, 'tcx>,
mir: &Mir<'tcx>,
mir_def_id: DefId,
fr: RegionVid,
outlived_fr: RegionVid,
blame_span: Span,
) {
// Obviously uncool error reporting.

let fr_string = match self.definitions[fr].external_name {
let fr_name = self.definitions[fr].external_name;
let outlived_fr_name = self.definitions[outlived_fr].external_name;

if let (Some(f), Some(o)) = (fr_name, outlived_fr_name) {
let tables = infcx.tcx.typeck_tables_of(mir_def_id);
let nice = NiceRegionError::new(infcx.tcx, blame_span, o, f, Some(tables));
if let Some(ErrorReported) = nice.try_report() {
return;
}
}

let fr_string = match fr_name {
Some(r) => format!("free region `{}`", r),
None => format!("free region `{:?}`", fr),
};

let outlived_fr_string = match self.definitions[outlived_fr].external_name {
let outlived_fr_string = match outlived_fr_name {
Some(r) => format!("free region `{}`", r),
None => format!("free region `{:?}`", outlived_fr),
};
Expand Down
38 changes: 32 additions & 6 deletions src/librustc_mir/borrow_check/nll/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,20 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
let defining_ty = self.defining_ty();
debug!("build: defining_ty={:?}", defining_ty);

let indices = self.compute_indices(fr_static, defining_ty);
let mut indices = self.compute_indices(fr_static, defining_ty);
debug!("build: indices={:?}", indices);

let bound_inputs_and_output = self.compute_inputs_and_output(&indices, defining_ty);

// "Liberate" the late-bound regions. These correspond to
// "local" free regions.
let first_local_index = self.infcx.num_region_vars();
let inputs_and_output = self.infcx
.replace_bound_regions_with_nll_infer_vars(FR, &bound_inputs_and_output);
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
FR,
self.mir_def_id,
&bound_inputs_and_output,
&mut indices,
);
let fr_fn_body = self.infcx.next_nll_region_var(FR).to_region_vid();
let num_universals = self.infcx.num_region_vars();

Expand Down Expand Up @@ -717,7 +721,7 @@ impl UniversalRegionRelations {
}
}

pub(crate) trait InferCtxtExt<'tcx> {
trait InferCtxtExt<'tcx> {
fn replace_free_regions_with_nll_infer_vars<T>(
&self,
origin: NLLRegionVariableOrigin,
Expand All @@ -729,7 +733,9 @@ pub(crate) trait InferCtxtExt<'tcx> {
fn replace_bound_regions_with_nll_infer_vars<T>(
&self,
origin: NLLRegionVariableOrigin,
all_outlive_scope: DefId,
value: &ty::Binder<T>,
indices: &mut UniversalRegionIndices<'tcx>,
) -> T
where
T: TypeFoldable<'tcx>;
Expand All @@ -752,18 +758,38 @@ impl<'cx, 'gcx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'gcx, 'tcx> {
fn replace_bound_regions_with_nll_infer_vars<T>(
&self,
origin: NLLRegionVariableOrigin,
all_outlive_scope: DefId,
value: &ty::Binder<T>,
indices: &mut UniversalRegionIndices<'tcx>,
) -> T
where
T: TypeFoldable<'tcx>,
{
let (value, _map) = self.tcx
.replace_late_bound_regions(value, |_br| self.next_nll_region_var(origin));
let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
let liberated_region = self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
scope: all_outlive_scope,
bound_region: br,
}));
let region_vid = self.next_nll_region_var(origin);
indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid());
region_vid
});
value
}
}

impl<'tcx> UniversalRegionIndices<'tcx> {
/// Initially, the `UniversalRegionIndices` map contains only the
/// early-bound regions in scope. Once that is all setup, we come
/// in later and instantiate the late-bound regions, and then we
/// insert the `ReFree` version of those into the map as
/// well. These are used for error reporting.
fn insert_late_bound_region(&mut self, r: ty::Region<'tcx>,
vid: ty::RegionVid)
{
self.indices.insert(r, vid);
}

/// Converts `r` into a local inference variable: `r` can either
/// by a `ReVar` (i.e., already a reference to an inference
/// variable) or it can be `'static` or some early-bound
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mir_check_cast_reify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn bar<'a>(x: &'a u32) -> &'static u32 {
// as part of checking the `ReifyFnPointer`.
let f: fn(_) -> _ = foo;
//~^ WARNING not reporting region error due to -Znll
//~| ERROR free region `'_#1r` does not outlive free region `'static`
//~| ERROR free region `'a` does not outlive free region `'static`
f(x)
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mir_check_cast_unsafe_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
// in `g`. These are related via the `UnsafeFnPointer` cast.
let g: unsafe fn(_) -> _ = f;
//~^ WARNING not reporting region error due to -Znll
//~| ERROR free region `'_#1r` does not outlive free region `'static`
//~| ERROR free region `'a` does not outlive free region `'static`
unsafe { g(input) }
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/mir_check_cast_unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use std::fmt::Debug;

fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
//~^ ERROR free region `'_#1r` does not outlive free region `'static`
//~^ ERROR free region `'a` does not outlive free region `'static`
x
//~^ WARNING not reporting region error due to -Znll
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/nll/where_clauses_in_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where

fn bar<'a, 'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
foo(x, y)
//~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
//~^ ERROR lifetime mismatch [E0623]
//~| WARNING not reporting region error due to -Znll
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/nll/where_clauses_in_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Foo<'a: 'b, 'b> {

fn bar<'a, 'b>(x: Cell<&'a u32>, y: Cell<&'b u32>) {
Foo { x, y };
//~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
//~^ ERROR lifetime mismatch [E0623]
//~| WARNING not reporting region error due to -Znll
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-static-bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
fn error(u: &(), v: &()) {
static_id(&u); //[ll]~ ERROR cannot infer an appropriate lifetime
//[nll]~^ WARNING not reporting region error due to -Znll
//[nll]~| ERROR free region `'_#1r` does not outlive free region `'static`
//[nll]~| ERROR free region `` does not outlive free region `'static`
static_id_indirect(&v); //[ll]~ ERROR cannot infer an appropriate lifetime
//[nll]~^ WARNING not reporting region error due to -Znll
//[nll]~| ERROR free region `'_#2r` does not outlive free region `'static`
//[nll]~| ERROR free region `` does not outlive free region `'static`
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn test() {
{
let y = 22;
let mut closure = expect_sig(|p, y| *p = y);
//~^ ERROR free region `'_#4r` does not outlive free region `'_#3r`
//~^ ERROR does not outlive free region
//~| WARNING not reporting region error due to -Znll
closure(&mut p, &y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: not reporting region error due to -Znll
36 | let mut closure = expect_sig(|p, y| *p = y);
| ^

error: free region `'_#4r` does not outlive free region `'_#3r`
error: free region `ReFree(DefId(0/1:9 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]), BrAnon(3))` does not outlive free region `ReFree(DefId(0/1:9 ~ escape_argument_callee[317d]::test[0]::{{closure}}[0]), BrAnon(2))`
--> $DIR/escape-argument-callee.rs:36:45
|
36 | let mut closure = expect_sig(|p, y| *p = y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn supply<'a, 'b, 'c>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>, cell_c: Cell
// Only works if 'x: 'y:
let p = x.get();
//~^ WARN not reporting region error due to -Znll
//~| ERROR free region `'_#5r` does not outlive free region `'_#6r`
//~| ERROR does not outlive free region
demand_y(x, y, p)
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: not reporting region error due to -Znll
55 | let p = x.get();
| ^^^^^^^

error: free region `'_#5r` does not outlive free region `'_#6r`
error: free region `ReFree(DefId(0/1:20 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]), BrAnon(1))` does not outlive free region `ReFree(DefId(0/1:20 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]::{{closure}}[0]), BrAnon(2))`
--> $DIR/propagate-approximated-fail-no-postdom.rs:55:17
|
55 | let p = x.get();
Expand All @@ -17,7 +17,7 @@ note: No external requirements
54 | | // Only works if 'x: 'y:
55 | | let p = x.get();
56 | | //~^ WARN not reporting region error due to -Znll
57 | | //~| ERROR free region `'_#5r` does not outlive free region `'_#6r`
57 | | //~| ERROR does not outlive free region
58 | | demand_y(x, y, p)
59 | | },
| |_________^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
//~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
//~^ ERROR lifetime mismatch

// Only works if 'x: 'y:
demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ note: External requirements
|
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
54 | | //~^ ERROR lifetime mismatch
55 | |
56 | | // Only works if 'x: 'y:
57 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
Expand All @@ -23,18 +23,22 @@ note: External requirements
= note: number of external vids: 3
= note: where '_#1r: '_#2r

error: free region `'_#1r` does not outlive free region `'_#2r`
error[E0623]: lifetime mismatch
--> $DIR/propagate-approximated-ref.rs:53:29
|
52 | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| ------- -------
| |
| these two types are declared with different lifetimes...
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| ^^^^^^^
| ^^^^^^^ ...but data from `cell_a` flows into `cell_b` here

note: No external requirements
--> $DIR/propagate-approximated-ref.rs:52:1
|
52 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
53 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
54 | | //~^ ERROR lifetime mismatch
55 | |
... |
58 | | });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn case1() {
foo(cell, |cell_a, cell_x| {
//~^ WARNING not reporting region error due to -Znll
cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
//~^ ERROR free region `'_#2r` does not outlive free region `'_#1r`
//~^ ERROR does not outlive free region
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ warning: not reporting region error due to -Znll
31 | foo(cell, |cell_a, cell_x| {
| ^^^

error: free region `'_#2r` does not outlive free region `'_#1r`
error: free region `ReFree(DefId(0/1:12 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]::{{closure}}[0]), BrAnon(1))` does not outlive free region `'_#1r`
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:33:9
|
33 | cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
Expand All @@ -17,7 +17,7 @@ note: No external requirements
| _______________^
32 | | //~^ WARNING not reporting region error due to -Znll
33 | | cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
34 | | //~^ ERROR free region `'_#2r` does not outlive free region `'_#1r`
34 | | //~^ ERROR does not outlive free region
35 | | })
| |_____^
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
//~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
//~^ ERROR does not outlive free region

// Only works if 'x: 'y:
demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
Expand Down
Loading