add pattern type ascriptions for tuple/brace structs/enums

This commit is contained in:
Niko Matsakis 2018-10-08 19:03:24 -04:00
parent a609384561
commit 40ab41fd18
11 changed files with 246 additions and 8 deletions

View file

@ -0,0 +1,24 @@
#![feature(nll)]
enum Foo<'a> {
Bar { field: &'a u32 }
}
fn in_let() {
let y = 22;
let foo = Foo::Bar { field: &y };
//~^ ERROR `y` does not live long enough
let Foo::Bar::<'static> { field: _z } = foo;
}
fn in_match() {
let y = 22;
let foo = Foo::Bar { field: &y };
//~^ ERROR `y` does not live long enough
match foo {
Foo::Bar::<'static> { field: _z } => {
}
}
}
fn main() { }

View file

@ -0,0 +1,25 @@
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_brace_enum_variant.rs:9:33
|
LL | let foo = Foo::Bar { field: &y };
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_brace_enum_variant.rs:16:33
|
LL | let foo = Foo::Bar { field: &y };
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,22 @@
#![feature(nll)]
struct Foo<'a> { field: &'a u32 }
fn in_let() {
let y = 22;
let foo = Foo { field: &y };
//~^ ERROR `y` does not live long enough
let Foo::<'static> { field: _z } = foo;
}
fn in_main() {
let y = 22;
let foo = Foo { field: &y };
//~^ ERROR `y` does not live long enough
match foo {
Foo::<'static> { field: _z } => {
}
}
}
fn main() { }

View file

@ -0,0 +1,25 @@
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_brace_struct.rs:7:28
|
LL | let foo = Foo { field: &y };
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_brace_struct.rs:14:28
|
LL | let foo = Foo { field: &y };
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,24 @@
#![feature(nll)]
enum Foo<'a> {
Bar(&'a u32)
}
fn in_let() {
let y = 22;
let foo = Foo::Bar(&y);
//~^ ERROR `y` does not live long enough
let Foo::Bar::<'static>(_z) = foo;
}
fn in_match() {
let y = 22;
let foo = Foo::Bar(&y);
//~^ ERROR `y` does not live long enough
match foo {
Foo::Bar::<'static>(_z) => {
}
}
}
fn main() { }

View file

@ -0,0 +1,25 @@
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_tuple_enum_variant.rs:9:24
|
LL | let foo = Foo::Bar(&y);
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_tuple_enum_variant.rs:16:24
|
LL | let foo = Foo::Bar(&y);
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,22 @@
#![feature(nll)]
struct Foo<'a>(&'a u32);
fn in_let() {
let y = 22;
let foo = Foo(&y);
//~^ ERROR `y` does not live long enough
let Foo::<'static>(_z) = foo;
}
fn in_match() {
let y = 22;
let foo = Foo(&y);
//~^ ERROR `y` does not live long enough
match foo {
Foo::<'static>(_z) => {
}
}
}
fn main() { }

View file

@ -0,0 +1,25 @@
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_tuple_struct.rs:7:19
|
LL | let foo = Foo(&y);
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error[E0597]: `y` does not live long enough
--> $DIR/pattern_substs_on_tuple_struct.rs:14:19
|
LL | let foo = Foo(&y);
| ^^ borrowed value does not live long enough
...
LL | }
| - `y` dropped here while still borrowed
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.