Skip to content

Commit

Permalink
Disable some nice region errors in NLL mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtwco committed Aug 6, 2018
1 parent 4b8089d commit 37ba9ca
Show file tree
Hide file tree
Showing 39 changed files with 205 additions and 187 deletions.
6 changes: 6 additions & 0 deletions src/librustc/infer/error_reporting/nice_region_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
Self { tcx, error: None, regions: Some((span, sub, sup)), tables }
}

pub fn try_report_from_nll(&self) -> Option<ErrorReported> {
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
// the nice region errors are required when running under the MIR borrow checker.
self.try_report_named_anon_conflict()
}

pub fn try_report(&self) -> Option<ErrorReported> {
self.try_report_named_anon_conflict()
.or_else(|| self.try_report_anon_anon_conflict())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
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() {
if let Some(_error_reported) = nice.try_report_from_nll() {
return;
}
}
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 lifetime mismatch [E0623]
//~^ ERROR unsatisfied lifetime constraints
//~| WARNING not reporting region error due to nll
}

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 lifetime mismatch [E0623]
//~^ ERROR unsatisfied lifetime constraints
//~| WARNING not reporting region error due to nll
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/in-band-lifetimes/mismatched.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ LL | fn foo(x: &'a u32, y: &u32) -> &'a u32 { y } //~ ERROR explicit lifetime re
| |
| consider changing the type of `y` to `&'a u32`

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/mismatched.rs:16:46
|
LL | fn foo2(x: &'a u32, y: &'b u32) -> &'a u32 { y } //~ ERROR lifetime mismatch
| ------- ------- ^ ...but data from `y` is returned here
| |
| this parameter and the return type are declared with different lifetimes...
| -- -- ^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
| | |
| | lifetime `'b` defined here
| lifetime `'a` defined here

error: aborting due to 2 previous errors

Some errors occurred: E0621, E0623.
For more information about an error, try `rustc --explain E0621`.
For more information about this error, try `rustc --explain E0621`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ warning: not reporting region error due to nll
LL | if x > y { x } else { y } //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex1-return-one-existing-name-if-else-using-impl.rs:21:12
|
LL | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
| ---- -------
| |
| this parameter and the return type are declared with different lifetimes...
| -- - let's call the lifetime of this reference `'1`
| |
| lifetime `'a` defined here
LL |
LL | if x > y { x } else { y } //~ ERROR lifetime mismatch
| ^^^^^ ...but data from `x` is returned here
| ^^^^^ requires that `'1` must outlive `'a`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ warning: not reporting region error due to nll
LL | x //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex1-return-one-existing-name-return-type-is-anon.rs:18:5
|
LL | fn foo<'a>(&self, x: &'a i32) -> &i32 {
| ------- ----
| |
| this parameter and the return type are declared with different lifetimes...
| -- - let's call the lifetime of this reference `'1`
| |
| lifetime `'a` defined here
LL |
LL | x //~ ERROR lifetime mismatch
| ^ ...but data from `x` is returned here
| ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ warning: not reporting region error due to nll
LL | if true { x } else { self } //~ ERROR lifetime mismatch
| ^^^^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex1-return-one-existing-name-self-is-anon.rs:18:9
|
LL | fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
| ----- -------
| |
| this parameter and the return type are declared with different lifetimes...
| -- - let's call the lifetime of this reference `'1`
| |
| lifetime `'a` defined here
LL |
LL | if true { x } else { self } //~ ERROR lifetime mismatch
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...but data from `self` is returned here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'1` must outlive `'a`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ warning: not reporting region error due to nll
LL | x.push(y); //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex2b-push-no-existing-names.rs:16:5
|
LL | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
| -------- -------- these two types are declared with different lifetimes...
| -------- -------- lifetime `'1` appears in this type
| |
| lifetime `'2` appears in this type
LL | x.push(y); //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ warning: not reporting region error due to nll
LL | let z = Ref { data: y.data };
| ^^^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $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...
| -- -- lifetime `'c` defined here
| |
| lifetime `'b` defined here
LL | let z = Ref { data: y.data };
LL | x.push(z); //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ argument requires that `'c` must outlive `'b`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ warning: not reporting region error due to nll
LL | let b = Ref { data: y.data };
| ^^^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $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...
| -- -- lifetime `'c` defined here
| |
| lifetime `'b` defined here
...
LL | a.push(b);
| ^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ argument requires that `'c` must outlive `'b`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ warning: not reporting region error due to nll
LL | let b = Ref { data: y.data };
| ^^^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $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...
| -- -- lifetime `'c` defined here
| |
| lifetime `'b` defined here
...
LL | Vec::push(a, b);
| ^^^^^^^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^^^^^^^ argument requires that `'c` must outlive `'b`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ warning: not reporting region error due to nll
LL | *v = x; //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $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...
| - - let's call the lifetime of this reference `'1`
| |
| let's call the lifetime of this reference `'2`
LL | *v = x; //~ ERROR lifetime mismatch
| ^^^^^^ ...but data from `x` flows here
| ^^^^^^ requires that `'1` must outlive `'2`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
17 changes: 10 additions & 7 deletions src/test/ui/lifetime-errors/ex3-both-anon-regions-3.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ warning: not reporting region error due to nll
LL | z.push((x,y)); //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-3.rs:12:5
|
LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| --- --- these two types are declared with different lifetimes...
| - - let's call the lifetime of this reference `'1`
| |
| let's call the lifetime of this reference `'2`
LL | z.push((x,y)); //~ ERROR lifetime mismatch
| ^^^^^^^^^^^^^ ...but data flows into `z` here
| ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-3.rs:12:5
|
LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
| --- --- these two types are declared with different lifetimes...
| - - let's call the lifetime of this reference `'1`
| |
| let's call the lifetime of this reference `'2`
LL | z.push((x,y)); //~ ERROR lifetime mismatch
| ^^^^^^^^^^^^^ ...but data flows into `z` here
| ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ warning: not reporting region error due to nll
LL | x.b = y.b; //~ ERROR lifetime mismatch
| ^^^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:16:5
|
LL | fn foo(mut x: Ref, y: Ref) {
| --- --- these two types are declared with different lifetimes...
| --- --- lifetime `'1` appears in this type
| |
| lifetime `'2` appears in this type
LL | x.b = y.b; //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ requires that `'1` must outlive `'2`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ warning: not reporting region error due to nll
LL | x.a = x.b; //~ ERROR lifetime mismatch
| ^^^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-both-are-structs-3.rs:16:5
|
LL | fn foo(mut x: Ref) {
| ---
| |
| this type is declared with multiple lifetimes...
| lifetime `'1` appears in this type
| lifetime `'2` appears in this type
LL | x.a = x.b; //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data with one lifetime flows into the other here
| ^^^^^^^^^ requires that `'1` must outlive `'2`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ warning: not reporting region error due to nll
LL | x.a = x.b; //~ ERROR lifetime mismatch
| ^^^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-both-are-structs-4.rs:16:5
|
LL | fn foo(mut x: Ref) {
| ---
| |
| this type is declared with multiple lifetimes...
| lifetime `'1` appears in this type
| lifetime `'2` appears in this type
LL | x.a = x.b; //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data with one lifetime flows into the other here
| ^^^^^^^^^ requires that `'1` must outlive `'2`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ warning: not reporting region error due to nll
LL | x.push(y); //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-both-are-structs-earlybound-regions.rs:18:5
|
LL | fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>)
| ------- ------- these two types are declared with different lifetimes...
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | x.push(y); //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ warning: not reporting region error due to nll
LL | x.push(y); //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-both-are-structs-latebound-regions.rs:15:5
|
LL | fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>) {
| ------- ------- these two types are declared with different lifetimes...
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | x.push(y); //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ warning: not reporting region error due to nll
LL | x.push(y); //~ ERROR lifetime mismatch
| ^

error[E0623]: lifetime mismatch
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-both-are-structs.rs:15:5
|
LL | fn foo(mut x: Vec<Ref>, y: Ref) {
| --- --- these two types are declared with different lifetimes...
| --- --- lifetime `'1` appears in this type
| |
| lifetime `'2` appears in this type
LL | x.push(y); //~ ERROR lifetime mismatch
| ^^^^^^^^^ ...but data from `y` flows into `x` here
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0623`.
Loading

0 comments on commit 37ba9ca

Please sign in to comment.