Auto merge of #50070 - toidiu:ak-2093-outlives, r=nikomatsakis

2093 infer outlives requirements

Tracking issue:  #44493
RFC: https://github.com/rust-lang/rfcs/pull/2093

- [x] add `rustc_attrs` flag
- [x] use `RequirePredicates` type
- [x]  handle explicit predicates on `dyn` Trait
- [x] handle explicit predicates on projections
- [x] more tests
- [x]  remove `unused`, `dead_code` and etc..
- [x]  documentation
This commit is contained in:
bors 2018-05-26 01:09:02 +00:00
commit 49a97ef010
45 changed files with 675 additions and 724 deletions

View file

@ -8,12 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Needs an explicit where clause stating outlives condition. (RFC 2093)
#![feature(dyn_trait)]
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Lifetime 'b needs to outlive lifetime 'a
struct Foo<'a,'b,T> {
x: &'a &'b T //~ ERROR reference has a longer lifetime than the data it references [E0491]
trait Trait<'x, T> where T: 'x {
}
#[rustc_outlives]
struct Foo<'a, A> //~ ERROR 19:1: 22:2: rustc_outlives
{
foo: Box<dyn Trait<'a, A>>
}
fn main() {}

View file

@ -0,0 +1,13 @@
error: rustc_outlives
--> $DIR/explicit-dyn.rs:19:1
|
LL | / struct Foo<'a, A> //~ ERROR 19:1: 22:2: rustc_outlives
LL | | {
LL | | foo: Box<dyn Trait<'a, A>>
LL | | }
| |_^
|
= note: A : 'a
error: aborting due to previous error

View file

@ -8,16 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Outlives requirementes are inferred (RFC 2093)
// projections: infer <Iterator>::Item: 'a
struct ProjFoo<'a, T: Iterator> {
bar: &'a T::Item
#[rustc_outlives]
enum Foo<'a, U> { //~ ERROR 15:1: 17:2: rustc_outlives
One(Bar<'a, U>)
}
struct Bar<'x, T> where T: 'x {
x: &'x (),
y: T,
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: rustc_outlives
--> $DIR/explicit-enum.rs:15:1
|
LL | / enum Foo<'a, U> { //~ ERROR 15:1: 17:2: rustc_outlives
LL | | One(Bar<'a, U>)
LL | | }
| |_^
|
= note: U : 'a
error: aborting due to previous error

View file

@ -1,30 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-test
// compile-pass
#![feature(infer_outlives_requirements)]
// Outlives requirementes are inferred (RFC 2093)
trait MakeRef<'a>: 'a {
type Type;
}
impl<'a, T> MakeRef<'a> for Vec<T>
where T: 'a,
{
type Type = &'a T;
}
// explicit-impl: T: 'a
struct Foo<'a, T> {
foo: <Vec<T> as MakeRef<'a>>::Type,
}
fn main() {}

View file

@ -1,30 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-test
// compile-pass
#![feature(infer_outlives_requirements)]
// Outlives requirementes are inferred (RFC 2093)
trait MakeRef<'a> {
type Type;
}
impl<'a, T> MakeRef<'a> for Vec<T>
where T: 'a,
{
type Type = &'a T;
}
// explicit-impl: T: 'a
struct Foo<'a, T> {
foo: <Vec<T> as MakeRef<'a>>::Type,
}
fn main() {}

View file

@ -1,30 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
// Needs an explicit where clause stating outlives condition. (RFC 2093)
trait MakeRef<'a> {
type Type;
}
impl<'a, T> MakeRef<'a> for Vec<T>
where T: 'a
{
type Type = &'a T;
}
// Type T needs to outlive lifetime 'a, as stated in impl.
struct Foo<'a, T> {
foo: <Vec<T> as MakeRef<'a>>::Type //~ Error the parameter type `T` may not live long enough [E0309]
}
fn main() { }

View file

@ -1,17 +0,0 @@
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/explicit-impl.rs:27:5
|
LL | struct Foo<'a, T> {
| - help: consider adding an explicit lifetime bound `T: 'a`...
LL | foo: <Vec<T> as MakeRef<'a>>::Type //~ Error the parameter type `T` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...so that the type `T` will meet its required lifetime bounds
--> $DIR/explicit-impl.rs:27:5
|
LL | foo: <Vec<T> as MakeRef<'a>>::Type //~ Error the parameter type `T` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0309`.

View file

@ -0,0 +1,24 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
trait Trait<'x, T> where T: 'x {
type Type;
}
#[rustc_outlives]
struct Foo<'a, A, B> where A: Trait<'a, B> //~ ERROR rustc_outlives
{
foo: <A as Trait<'a, B>>::Type
}
fn main() {}

View file

@ -0,0 +1,13 @@
error: rustc_outlives
--> $DIR/explicit-projection.rs:19:1
|
LL | / struct Foo<'a, A, B> where A: Trait<'a, B> //~ ERROR rustc_outlives
LL | | {
LL | | foo: <A as Trait<'a, B>>::Type
LL | | }
| |_^
|
= note: B : 'a
error: aborting due to previous error

View file

@ -8,20 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Outlives requirementes are inferred (RFC 2093)
// explicit-where: infer U: 'b
struct ExFoo<'b, U> {
bar: ExBar<'b, U>
#[rustc_outlives]
struct Foo<'b, U> { //~ ERROR 15:1: 17:2: rustc_outlives
bar: Bar<'b, U>
}
struct ExBar<'a, T> where T: 'a {
struct Bar<'a, T> where T: 'a {
x: &'a (),
y: T,
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: rustc_outlives
--> $DIR/explicit-struct.rs:15:1
|
LL | / struct Foo<'b, U> { //~ ERROR 15:1: 17:2: rustc_outlives
LL | | bar: Bar<'b, U>
LL | | }
| |_^
|
= note: U : 'b
error: aborting due to previous error

View file

@ -8,17 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Outlives requirementes are inferred (RFC 2093)
#![feature(untagged_unions)]
#![allow(unions_with_drop_fields)]
// nested-structs: infer U: 'b and therefore T: 'a
struct NestFoo<'a, T> {
field1: NestBar<'a, T>
#[rustc_outlives]
union Foo<'b, U> { //~ ERROR 18:1: 20:2: rustc_outlives
bar: Bar<'b, U>
}
struct NestBar<'b, U> {
field2: &'b U
union Bar<'a, T> where T: 'a {
x: &'a (),
y: T,
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: rustc_outlives
--> $DIR/explicit-union.rs:18:1
|
LL | / union Foo<'b, U> { //~ ERROR 18:1: 20:2: rustc_outlives
LL | | bar: Bar<'b, U>
LL | | }
| |_^
|
= note: U : 'b
error: aborting due to previous error

View file

@ -1,23 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Needs an explicit where clause stating outlives condition. (RFC 2093)
// Type U needs to outlive lifetime 'b.
struct Foo<'b, U> {
bar: Bar<'b, U> //~ Error the parameter type `U` may not live long enough [E0309]
}
struct Bar<'a, T> where T: 'a {
x: &'a (),
y: T,
}
fn main() { }

View file

@ -1,17 +0,0 @@
error[E0309]: the parameter type `U` may not live long enough
--> $DIR/explicit-where.rs:15:5
|
LL | struct Foo<'b, U> {
| - help: consider adding an explicit lifetime bound `U: 'b`...
LL | bar: Bar<'b, U> //~ Error the parameter type `U` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^
|
note: ...so that the type `U` will meet its required lifetime bounds
--> $DIR/explicit-where.rs:15:5
|
LL | bar: Bar<'b, U> //~ Error the parameter type `U` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0309`.

View file

@ -1,20 +0,0 @@
error[E0491]: in type `&'a &'b T`, reference has a longer lifetime than the data it references
--> $DIR/multiple-regions.rs:15:5
|
LL | x: &'a &'b T //~ ERROR reference has a longer lifetime than the data it references [E0491]
| ^^^^^^^^^^^^
|
note: the pointer is valid for the lifetime 'a as defined on the struct at 14:1
--> $DIR/multiple-regions.rs:14:1
|
LL | struct Foo<'a,'b,T> {
| ^^^^^^^^^^^^^^^^^^^
note: but the referenced data is only valid for the lifetime 'b as defined on the struct at 14:1
--> $DIR/multiple-regions.rs:14:1
|
LL | struct Foo<'a,'b,T> {
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0491`.

View file

@ -8,31 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Type T needs to outlive lifetime 'a.
enum Foo<'a, T> {
#[rustc_outlives]
enum Foo<'a, T> { //~ ERROR 16:1: 19:2: rustc_outlives
One(Bar<'a, T>)
}
// Type U needs to outlive lifetime 'b
struct Bar<'b, U> {
field2: &'b U
}
// Type K needs to outlive lifetime 'c.
enum Ying<'c, K> {
One(&'c Yang<K>)
}
struct Yang<V> {
field2: V
}
fn main() {}

View file

@ -0,0 +1,13 @@
error: rustc_outlives
--> $DIR/nested-enum.rs:16:1
|
LL | / enum Foo<'a, T> { //~ ERROR 16:1: 19:2: rustc_outlives
LL | |
LL | | One(Bar<'a, T>)
LL | | }
| |_^
|
= note: T : 'a
error: aborting due to previous error

View file

@ -8,15 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Outlives requirementes are inferred (RFC 2093)
// multiple-regions: infer 'b: 'a
struct MultiFoo<'a, 'b, T> {
#[rustc_outlives]
struct Foo<'a, 'b, T> { //~ ERROR 15:1: 17:2: rustc_outlives
x: &'a &'b T
}
fn main() {}

View file

@ -0,0 +1,14 @@
error: rustc_outlives
--> $DIR/nested-regions.rs:15:1
|
LL | / struct Foo<'a, 'b, T> { //~ ERROR 15:1: 17:2: rustc_outlives
LL | | x: &'a &'b T
LL | | }
| |_^
|
= note: 'b : 'a
= note: T : 'a
= note: T : 'b
error: aborting due to previous error

View file

@ -1,4 +1,4 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -8,19 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Needs an explicit where clause stating outlives condition. (RFC 2093)
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Type T needs to outlive lifetime 'a. This is not reported due to
// a compilation error in Bar.
struct Foo<'a, T> {
#[rustc_outlives]
struct Foo<'a, T> { //~ ERROR 15:1: 17:2: rustc_outlives
field1: Bar<'a, T>
}
// Type U needs to outlive lifetime 'b
struct Bar<'b, U> {
field2: &'b U //~ ERROR the parameter type `U` may not live long enough [E0309]
field2: &'b U
}
fn main() {}

View file

@ -1,17 +1,12 @@
error[E0309]: the parameter type `U` may not live long enough
--> $DIR/nested-structs.rs:22:5
error: rustc_outlives
--> $DIR/nested-structs.rs:15:1
|
LL | struct Bar<'b, U> {
| - help: consider adding an explicit lifetime bound `U: 'b`...
LL | field2: &'b U //~ ERROR the parameter type `U` may not live long enough [E0309]
| ^^^^^^^^^^^^^
LL | / struct Foo<'a, T> { //~ ERROR 15:1: 17:2: rustc_outlives
LL | | field1: Bar<'a, T>
LL | | }
| |_^
|
note: ...so that the reference type `&'b U` does not outlive the data it points at
--> $DIR/nested-structs.rs:22:5
|
LL | field2: &'b U //~ ERROR the parameter type `U` may not live long enough [E0309]
| ^^^^^^^^^^^^^
= note: T : 'a
error: aborting due to previous error
For more information about this error, try `rustc --explain E0309`.

View file

@ -8,15 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
#![feature(untagged_unions)]
#![allow(unions_with_drop_fields)]
// Type T needs to outlive lifetime 'a. This is not reported due to
// a compilation error in Bar.
union Foo<'a, T> {
#[rustc_outlives]
union Foo<'a, T> { //~ ERROR 18:1: 20:2: rustc_outlives
field1: Bar<'a, T>
}
@ -25,15 +24,4 @@ union Bar<'b, U> {
field2: &'b U
}
// Type K needs to outlive lifetime 'c.
union Ying<'c, K> {
field1: &'c Yang<K>
}
union Yang<V> {
field2: V
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: rustc_outlives
--> $DIR/nested-union.rs:18:1
|
LL | / union Foo<'a, T> { //~ ERROR 18:1: 20:2: rustc_outlives
LL | | field1: Bar<'a, T>
LL | | }
| |_^
|
= note: T : 'a
error: aborting due to previous error

View file

@ -8,16 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Outlives requirementes are inferred (RFC 2093)
// reference: infer T: 'a
struct RefFoo<'a, T> {
bar: &'a [T]
#[rustc_outlives]
struct Foo<'a, T: Iterator> { //~ ERROR rustc_outlives
bar: &'a T::Item
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: rustc_outlives
--> $DIR/projection.rs:15:1
|
LL | / struct Foo<'a, T: Iterator> { //~ ERROR rustc_outlives
LL | | bar: &'a T::Item
LL | | }
| |_^
|
= note: <T as std::iter::Iterator>::Item : 'a
error: aborting due to previous error

View file

@ -1,20 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
// Needs an explicit where clause stating outlives condition. RFC 2093
// Associated type <Iterator>::Item needs to outlives lifetime 'a.
struct Foo<'a, T: Iterator> {
bar: &'a T::Item //~ Error the associated type `<T as std::iter::Iterator>::Item` may not live long enough [E0309]
}
fn main() { }

View file

@ -1,16 +0,0 @@
error[E0309]: the associated type `<T as std::iter::Iterator>::Item` may not live long enough
--> $DIR/projections.rs:17:5
|
LL | bar: &'a T::Item //~ Error the associated type `<T as std::iter::Iterator>::Item` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<T as std::iter::Iterator>::Item: 'a`...
note: ...so that the reference type `&'a <T as std::iter::Iterator>::Item` does not outlive the data it points at
--> $DIR/projections.rs:17:5
|
LL | bar: &'a T::Item //~ Error the associated type `<T as std::iter::Iterator>::Item` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0309`.

View file

@ -1,4 +1,4 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Needs an explicit where clause stating outlives condition. (RFC 2093)
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
// Type T needs to outlive lifetime 'a.
struct Foo<'a, T> {
bar: &'a [T] //~ ERROR the parameter type `T` may not live long enough [E0309]
#[rustc_outlives]
struct Foo<'a, T> { //~ ERROR rustc_outlives
bar: &'a T,
}
fn main() { }
fn main() {}

View file

@ -1,17 +1,12 @@
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/reference.rs:15:5
error: rustc_outlives
--> $DIR/reference.rs:15:1
|
LL | struct Foo<'a, T> {
| - help: consider adding an explicit lifetime bound `T: 'a`...
LL | bar: &'a [T] //~ ERROR the parameter type `T` may not live long enough [E0309]
| ^^^^^^^^^^^^
LL | / struct Foo<'a, T> { //~ ERROR rustc_outlives
LL | | bar: &'a T,
LL | | }
| |_^
|
note: ...so that the reference type `&'a [T]` does not outlive the data it points at
--> $DIR/reference.rs:15:5
|
LL | bar: &'a [T] //~ ERROR the parameter type `T` may not live long enough [E0309]
| ^^^^^^^^^^^^
= note: T : 'a
error: aborting due to previous error
For more information about this error, try `rustc --explain E0309`.

View file

@ -0,0 +1,25 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(dyn_trait)]
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
trait Trait<'x, 's, T> where T: 'x,
's: {
}
#[rustc_outlives]
struct Foo<'a, 'b, A> //~ ERROR 20:1: 23:2: rustc_outlives
{
foo: Box<dyn Trait<'a, 'b, A>>
}
fn main() {}

View file

@ -0,0 +1,13 @@
error: rustc_outlives
--> $DIR/self-dyn.rs:20:1
|
LL | / struct Foo<'a, 'b, A> //~ ERROR 20:1: 23:2: rustc_outlives
LL | | {
LL | | foo: Box<dyn Trait<'a, 'b, A>>
LL | | }
| |_^
|
= note: A : 'a
error: aborting due to previous error

View file

@ -0,0 +1,24 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]
#![feature(infer_outlives_requirements)]
#[rustc_outlives]
struct Foo<'a, 'b, T> { //~ ERROR 15:1: 17:2: rustc_outlives
field1: Bar<'a, 'b, T>
}
trait Bar<'x, 's, U>
where U: 'x,
Self:'s
{}
fn main() {}

View file

@ -0,0 +1,12 @@
error: rustc_outlives
--> $DIR/self-structs.rs:15:1
|
LL | / struct Foo<'a, 'b, T> { //~ ERROR 15:1: 17:2: rustc_outlives
LL | | field1: Bar<'a, 'b, T>
LL | | }
| |_^
|
= note: T : 'a
error: aborting due to previous error

View file

@ -1,40 +0,0 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
// Needs an explicit where clause stating outlives condition. (RFC 2093)
#![feature(untagged_unions)]
// Type T needs to outlive lifetime 'a. This is not reported due to
// a compilation error in Bar.
union Foo<'a, T> {
field1: Bar<'a, T>
}
// Type U needs to outlive lifetime 'b
union Bar<'b, U> {
field2: &'b U //~ ERROR 25:5: 25:18: the parameter type `U` may not live long enough [E0309]
}
// Type K needs to outlive lifetime 'c.
union Ying<'c, K> {
field1: &'c Yang<K> //~ ERROR 31:5: 31:24: the parameter type `K` may not live long enough [E0309]
}
union Yang<V> {
field2: V
}
fn main() {}

View file

@ -1,31 +0,0 @@
error[E0309]: the parameter type `U` may not live long enough
--> $DIR/union.rs:25:5
|
LL | union Bar<'b, U> {
| - help: consider adding an explicit lifetime bound `U: 'b`...
LL | field2: &'b U //~ ERROR 25:5: 25:18: the parameter type `U` may not live long enough [E0309]
| ^^^^^^^^^^^^^
|
note: ...so that the reference type `&'b U` does not outlive the data it points at
--> $DIR/union.rs:25:5
|
LL | field2: &'b U //~ ERROR 25:5: 25:18: the parameter type `U` may not live long enough [E0309]
| ^^^^^^^^^^^^^
error[E0309]: the parameter type `K` may not live long enough
--> $DIR/union.rs:31:5
|
LL | union Ying<'c, K> {
| - help: consider adding an explicit lifetime bound `K: 'c`...
LL | field1: &'c Yang<K> //~ ERROR 31:5: 31:24: the parameter type `K` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^^^^^
|
note: ...so that the reference type `&'c Yang<K>` does not outlive the data it points at
--> $DIR/union.rs:31:5
|
LL | field1: &'c Yang<K> //~ ERROR 31:5: 31:24: the parameter type `K` may not live long enough [E0309]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0309`.