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

Disable some nice region errors in NLL mode. #53115

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems strictly better


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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting that we highlight the comparison here -- seems like a problem, though obviously not from this change...maybe we should file a bug? Presumably the actual span we should highlight is the use of x...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mentioned on the .nll.stderr/.stderr comparison here.


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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should file a bug here -- I think it'd be nice to add another note here and use this as an opportunity to teach the elision rules. e.g.,

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 {
   |          --  -                     - defaults to `&'1 i32` per the elision rules
   |          |  |
   |          |  let's call the lifetime of this reference `'1`
   |          lifetime `'a` defined here
LL | 
LL |     x //~ ERROR lifetime mismatch
| ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here.


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