remove unnecessary `blame_span` from `report_region_errors`

This commit is contained in:
Niko Matsakis 2018-07-23 19:46:42 +03:00
parent 52c94e9dec
commit 4fce59f0fd
22 changed files with 76 additions and 61 deletions

View File

@ -199,19 +199,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir_def_id: DefId,
fr: RegionVid,
outlived_fr: RegionVid,
blame_span: Span,
errors_buffer: &mut Vec<Diagnostic>,
) {
debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
let tables = infcx.tcx.typeck_tables_of(mir_def_id);
let nice = NiceRegionError::new_from_span(infcx.tcx, blame_span, o, f, Some(tables));
if let Some(_error_reported) = nice.try_report() {
return;
}
}
// Find all paths
let constraint_paths = self.find_constraint_paths_between_regions(fr, |r| r == outlived_fr);
debug!("report_error: constraint_paths={:#?}", constraint_paths);
@ -233,6 +224,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Get a span
let (category, span) = categorized_path.first().unwrap();
// Check if we can use one of the "nice region errors".
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
let tables = infcx.tcx.typeck_tables_of(mir_def_id);
let nice = NiceRegionError::new_from_span(infcx.tcx, *span, o, f, Some(tables));
if let Some(_error_reported) = nice.try_report() {
return;
}
}
let category = match (
category,
self.universal_regions.is_local_free_region(fr),

View File

@ -921,7 +921,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// to report the error. This gives better error messages
// in some cases.
self.report_error(
mir, infcx, mir_def_id, longer_fr, shorter_fr, blame_span, errors_buffer);
mir, infcx, mir_def_id, longer_fr, shorter_fr, errors_buffer);
}
}
}

View File

@ -35,20 +35,22 @@ LL | let mut out = Struct { head: x, _tail: [()] };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:14:9
--> $DIR/issue-40288-2.rs:16:31
|
LL | fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| - consider changing the type of `y` to `&'a T`
LL | let mut out = [x];
| ^^^^^^^ lifetime `'a` required
...
LL | let slice: &mut [_] = &mut out;
| ^^^^^^^^ lifetime `'a` required
error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/issue-40288-2.rs:29:9
--> $DIR/issue-40288-2.rs:31:41
|
LL | fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
| - consider changing the type of `y` to `&'a T`
LL | let mut out = Struct { head: x, _tail: [()] };
| ^^^^^^^ lifetime `'a` required
...
LL | let dst: &mut Struct<_, [()]> = &mut out;
| ^^^^^^^^ lifetime `'a` required
error: aborting due to 2 previous errors

View File

@ -5,12 +5,12 @@ LL | if x > y { x } else { y } //~ ERROR explicit lifetime
| ^
error[E0621]: explicit lifetime required in parameter type
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:11:13
--> $DIR/ex1-return-one-existing-name-if-else-3.rs:11:16
|
LL | fn foo<'a>((x, y): (&'a i32, &i32)) -> &'a i32 {
| -^----
| ||
| |lifetime `'a` required
| ----^-
| | |
| | lifetime `'a` required
| consider changing type to `(&'a i32, &'a i32)`
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0621]: explicit lifetime required in the type of `x`
LL | fn foo<'a>(x: Ref<i32>, y: &mut Vec<Ref<'a, i32>>) {
| - consider changing the type of `x` to `Ref<'a, i32>`
LL | y.push(x); //~ ERROR explicit lifetime
| ^ lifetime `'a` required
| ^^^^^^^^^ lifetime `'a` required
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0621]: explicit lifetime required in the type of `y`
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
| - consider changing the type of `y` to `Ref<'a, i32>`
LL | x.push(y); //~ ERROR explicit lifetime
| ^ lifetime `'a` required
| ^^^^^^^^^ lifetime `'a` required
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
| -------- -------- these two types are declared with different lifetimes...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -5,12 +5,13 @@ LL | let z = Ref { data: y.data };
| ^^^
error[E0623]: lifetime mismatch
--> $DIR/ex2c-push-inference-variable.rs:16:9
--> $DIR/ex2c-push-inference-variable.rs:17:5
|
LL | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
| ------------ ------------ these two types are declared with different lifetimes...
LL | let z = Ref { data: y.data };
| ^ ...but data from `y` flows into `x` here
LL | x.push(z); //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -5,12 +5,13 @@ LL | let b = Ref { data: y.data };
| ^^^
error[E0623]: lifetime mismatch
--> $DIR/ex2d-push-inference-variable-2.rs:16:9
--> $DIR/ex2d-push-inference-variable-2.rs:18:5
|
LL | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
| ------------ ------------ these two types are declared with different lifetimes...
LL | let a: &mut Vec<Ref<i32>> = x; //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
...
LL | a.push(b);
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -5,12 +5,13 @@ LL | let b = Ref { data: y.data };
| ^^^
error[E0623]: lifetime mismatch
--> $DIR/ex2e-push-inference-variable-3.rs:16:9
--> $DIR/ex2e-push-inference-variable-3.rs:18:5
|
LL | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
| ------------ ------------ these two types are declared with different lifetimes...
LL | let a: &mut Vec<Ref<i32>> = x; //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
...
LL | Vec::push(a, b);
| ^^^^^^^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -5,12 +5,12 @@ LL | *v = x; //~ ERROR lifetime mismatch
| ^
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-2.rs:11:14
--> $DIR/ex3-both-anon-regions-2.rs:12:5
|
LL | fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) {
| ^^^^^^^^^ --- --- these two types are declared with different lifetimes...
| |
| ...but data from `x` flows here
| --- --- these two types are declared with different lifetimes...
LL | *v = x; //~ ERROR lifetime mismatch
| ^^^^^^ ...but data from `x` flows here
error: aborting due to previous error

View File

@ -19,12 +19,12 @@ LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| ...but data flows into `z` here
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-3.rs:11:33
--> $DIR/ex3-both-anon-regions-3.rs:11:36
|
LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| --- ^ --- these two types are declared with different lifetimes...
| |
| ...but data flows into `z` here
| --- ^ --- these two types are declared with different lifetimes...
| |
| ...but data flows into `z` here
error: aborting due to 2 previous errors

View File

@ -11,7 +11,7 @@ LL | fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>)
| ------- ------- these two types are declared with different lifetimes...
...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>) {
| ------- ------- these two types are declared with different lifetimes...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo(mut x: Vec<Ref>, y: Ref) {
| --- --- these two types are declared with different lifetimes...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo<'a,'b>(x: &mut Vec<&'a u8>, y: &'b u8) {
| ------ ------ these two types are declared with different lifetimes...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo(x:fn(&u8, &u8), y: Vec<&u8>, z: &u8) {
| --- --- these two types are declared with different lifetimes...
LL | y.push(z); //~ ERROR lifetime mismatch
| ^ ...but data from `z` flows into `y` here
| ^^^^^^^^^ ...but data from `z` flows into `y` here
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
--> $DIR/ex3-both-anon-regions-using-fn-items.rs:11:3

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo(x: &mut Vec<&u8>, y: &u8) {
| --- --- these two types are declared with different lifetimes...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo(x:Box<Fn(&u8, &u8)> , y: Vec<&u8>, z: &u8) {
| --- --- these two types are declared with different lifetimes...
LL | y.push(z); //~ ERROR lifetime mismatch
| ^ ...but data from `z` flows into `y` here
| ^^^^^^^^^ ...but data from `z` flows into `y` here
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
--> $DIR/ex3-both-anon-regions-using-trait-objects.rs:11:3

View File

@ -10,7 +10,7 @@ error[E0623]: lifetime mismatch
LL | fn foo(x: &mut Vec<&u8>, y: &u8) {
| --- --- these two types are declared with different lifetimes...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ ...but data from `y` flows into `x` here
error: aborting due to previous error

View File

@ -24,14 +24,19 @@ LL | | });
= note: where '_#1r: '_#2r
error[E0623]: lifetime mismatch
--> $DIR/propagate-approximated-ref.rs:53:29
--> $DIR/propagate-approximated-ref.rs:53:5
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| ------- -------
| |
| these two types are declared with different lifetimes...
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| ^^^^^^^ ...but data from `cell_a` flows into `cell_b` here
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| ------- -------
| |
| these two types are declared with different lifetimes...
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
LL | | //~^ ERROR lifetime mismatch
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to nll
LL | | });
| |______^ ...but data from `cell_a` flows into `cell_b` here
note: No external requirements
--> $DIR/propagate-approximated-ref.rs:52:1

View File

@ -24,14 +24,19 @@ LL | | });
= note: where '_#1r: '_#2r
error[E0623]: lifetime mismatch
--> $DIR/propagate-approximated-val.rs:46:29
--> $DIR/propagate-approximated-val.rs:46:5
|
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| ------- -------
| |
| these two types are declared with different lifetimes...
LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
| ^^^^^^ ...but data from `cell_a` flows into `cell_b` here
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| ------- -------
| |
| these two types are declared with different lifetimes...
LL | / establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
LL | | //~^ ERROR lifetime mismatch
LL | |
LL | | // Only works if 'x: 'y:
LL | | demand_y(outlives1, outlives2, x.get()) //~ WARNING not reporting region error due to nll
LL | | });
| |______^ ...but data from `cell_a` flows into `cell_b` here
note: No external requirements
--> $DIR/propagate-approximated-val.rs:45:1