diff options
Diffstat (limited to 'src/test')
28 files changed, 674 insertions, 1 deletions
diff --git a/src/test/compile-fail/outlives-associated-types.rs b/src/test/compile-fail/outlives-associated-types.rs index 778394c9fc8..5c392223f88 100644 --- a/src/test/compile-fail/outlives-associated-types.rs +++ b/src/test/compile-fail/outlives-associated-types.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-tidy-linelength + // Test that the outlives computation runs for now... #![feature(rustc_attrs)] @@ -16,7 +18,7 @@ // https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md#example-1-a-reference #[rustc_outlives] -struct Direct<'a, T> { //~ ERROR 19:1: 21:2: [] [E0640] +struct Direct<'a, T> { //~ ERROR 21:1: 23:2: [Binder(OutlivesPredicate(T, ReEarlyBound(0, 'a)))] [E0640] field: &'a T } diff --git a/src/test/ui/feature-gate-infer_outlives_requirements.rs b/src/test/ui/feature-gate-infer_outlives_requirements.rs new file mode 100644 index 00000000000..01ccc50a130 --- /dev/null +++ b/src/test/ui/feature-gate-infer_outlives_requirements.rs @@ -0,0 +1,18 @@ +// 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 T needs to outlive lifetime 'a. +struct Foo<'a, T> { + bar: &'a [T] //~ ERROR the parameter type `T` may not live long enough [E0309] +} + +fn main() { } diff --git a/src/test/ui/feature-gate-infer_outlives_requirements.stderr b/src/test/ui/feature-gate-infer_outlives_requirements.stderr new file mode 100644 index 00000000000..560e494b582 --- /dev/null +++ b/src/test/ui/feature-gate-infer_outlives_requirements.stderr @@ -0,0 +1,17 @@ +error[E0309]: the parameter type `T` may not live long enough + --> $DIR/feature-gate-infer_outlives_requirements.rs:15:5 + | +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] + | ^^^^^^^^^^^^ + | +note: ...so that the reference type `&'a [T]` does not outlive the data it points at + --> $DIR/feature-gate-infer_outlives_requirements.rs:15:5 + | +LL | bar: &'a [T] //~ 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`. diff --git a/src/test/ui/rfc-2093-infer-outlives/enum-pass.rs b/src/test/ui/rfc-2093-infer-outlives/enum-pass.rs new file mode 100644 index 00000000000..8c7275bb1a7 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/enum-pass.rs @@ -0,0 +1,38 @@ +// 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. + +// must-compile-successfully + +#![feature(infer_outlives_requirements)] + +// Type T needs to outlive lifetime 'a. +enum Foo<'a, T> { + + 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() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/enum.rs b/src/test/ui/rfc-2093-infer-outlives/enum.rs new file mode 100644 index 00000000000..7d0427adb9f --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/enum.rs @@ -0,0 +1,37 @@ +// 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) + +// Type T needs to outlive lifetime 'a. +enum Foo<'a, T> { + + One(Bar<'a, T>) +} + +// Type U needs to outlive lifetime 'b +struct Bar<'b, U> { + field2: &'b U //~ ERROR 23:5: 23:18: the parameter type `U` may not live long enough [E0309] +} + + + +// Type K needs to outlive lifetime 'c. +enum Ying<'c, K> { + One(&'c Yang<K>) //~ ERROR 30:9: 30:21: the parameter type `K` may not live long enough [E0309] +} + +struct Yang<V> { + field2: V +} + +fn main() {} diff --git a/src/test/ui/rfc-2093-infer-outlives/enum.stderr b/src/test/ui/rfc-2093-infer-outlives/enum.stderr new file mode 100644 index 00000000000..e6eaf9b4754 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/enum.stderr @@ -0,0 +1,31 @@ +error[E0309]: the parameter type `U` may not live long enough + --> $DIR/enum.rs:23:5 + | +LL | struct Bar<'b, U> { + | - help: consider adding an explicit lifetime bound `U: 'b`... +LL | field2: &'b U //~ ERROR 23:5: 23: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/enum.rs:23:5 + | +LL | field2: &'b U //~ ERROR 23:5: 23:18: the parameter type `U` may not live long enough [E0309] + | ^^^^^^^^^^^^^ + +error[E0309]: the parameter type `K` may not live long enough + --> $DIR/enum.rs:30:9 + | +LL | enum Ying<'c, K> { + | - help: consider adding an explicit lifetime bound `K: 'c`... +LL | One(&'c Yang<K>) //~ ERROR 30:9: 30:21: 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/enum.rs:30:9 + | +LL | One(&'c Yang<K>) //~ ERROR 30:9: 30:21: 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`. diff --git a/src/test/ui/rfc-2093-infer-outlives/explicit-impl-lifetime-pass.rs b/src/test/ui/rfc-2093-infer-outlives/explicit-impl-lifetime-pass.rs new file mode 100644 index 00000000000..da578386adb --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/explicit-impl-lifetime-pass.rs @@ -0,0 +1,30 @@ +// 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 +// must-compile-successfully + +#![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() {} diff --git a/src/test/ui/rfc-2093-infer-outlives/explicit-impl-pass.rs b/src/test/ui/rfc-2093-infer-outlives/explicit-impl-pass.rs new file mode 100644 index 00000000000..fd74fe30bb6 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/explicit-impl-pass.rs @@ -0,0 +1,30 @@ +// 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 +// must-compile-successfully + +#![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() {} diff --git a/src/test/ui/rfc-2093-infer-outlives/explicit-impl.rs b/src/test/ui/rfc-2093-infer-outlives/explicit-impl.rs new file mode 100644 index 00000000000..3a10087551c --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/explicit-impl.rs @@ -0,0 +1,30 @@ +// 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() { } diff --git a/src/test/ui/rfc-2093-infer-outlives/explicit-impl.stderr b/src/test/ui/rfc-2093-infer-outlives/explicit-impl.stderr new file mode 100644 index 00000000000..498d66ef9a5 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/explicit-impl.stderr @@ -0,0 +1,17 @@ +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`. diff --git a/src/test/ui/rfc-2093-infer-outlives/explicit-where-pass.rs b/src/test/ui/rfc-2093-infer-outlives/explicit-where-pass.rs new file mode 100644 index 00000000000..e51b5a16b45 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/explicit-where-pass.rs @@ -0,0 +1,27 @@ +// 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. + +// must-compile-successfully + +#![feature(infer_outlives_requirements)] +// Outlives requirementes are inferred (RFC 2093) + +// explicit-where: infer U: 'b +struct ExFoo<'b, U> { + bar: ExBar<'b, U> +} +struct ExBar<'a, T> where T: 'a { + x: &'a (), + y: T, +} + + +fn main() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/explicit-where.rs b/src/test/ui/rfc-2093-infer-outlives/explicit-where.rs new file mode 100644 index 00000000000..81734bf514e --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/explicit-where.rs @@ -0,0 +1,23 @@ +// 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() { } diff --git a/src/test/ui/rfc-2093-infer-outlives/explicit-where.stderr b/src/test/ui/rfc-2093-infer-outlives/explicit-where.stderr new file mode 100644 index 00000000000..436754c7dc1 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/explicit-where.stderr @@ -0,0 +1,17 @@ +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`. diff --git a/src/test/ui/rfc-2093-infer-outlives/multiple-regions-pass.rs b/src/test/ui/rfc-2093-infer-outlives/multiple-regions-pass.rs new file mode 100644 index 00000000000..be686a80048 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/multiple-regions-pass.rs @@ -0,0 +1,22 @@ +// 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. + +// must-compile-successfully + +#![feature(infer_outlives_requirements)] +// Outlives requirementes are inferred (RFC 2093) + +// multiple-regions: infer 'b: 'a +struct MultiFoo<'a, 'b, T> { + x: &'a &'b T +} + +fn main() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/multiple-regions.rs b/src/test/ui/rfc-2093-infer-outlives/multiple-regions.rs new file mode 100644 index 00000000000..7ea1ce2d3dc --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/multiple-regions.rs @@ -0,0 +1,19 @@ +// 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. + +// Needs an explicit where clause stating outlives condition. (RFC 2093) + +// 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] +} + +fn main() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/multiple-regions.stderr b/src/test/ui/rfc-2093-infer-outlives/multiple-regions.stderr new file mode 100644 index 00000000000..3722abd5ad6 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/multiple-regions.stderr @@ -0,0 +1,20 @@ +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`. diff --git a/src/test/ui/rfc-2093-infer-outlives/nested-structs-pass.rs b/src/test/ui/rfc-2093-infer-outlives/nested-structs-pass.rs new file mode 100644 index 00000000000..02581457fcc --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/nested-structs-pass.rs @@ -0,0 +1,25 @@ +// 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. + +// must-compile-successfully + +#![feature(infer_outlives_requirements)] +// Outlives requirementes are inferred (RFC 2093) + +// nested-structs: infer U: 'b and therefore T: 'a +struct NestFoo<'a, T> { + field1: NestBar<'a, T> +} +struct NestBar<'b, U> { + field2: &'b U +} + +fn main() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/nested-structs.rs b/src/test/ui/rfc-2093-infer-outlives/nested-structs.rs new file mode 100644 index 00000000000..7c444dbd3b0 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/nested-structs.rs @@ -0,0 +1,26 @@ +// 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. + +// Needs an explicit where clause stating outlives condition. (RFC 2093) + + +// Type T needs to outlive lifetime 'a. This is not reported due to +// a compilation error in Bar. +struct Foo<'a, T> { + 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] +} + +fn main() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/nested-structs.stderr b/src/test/ui/rfc-2093-infer-outlives/nested-structs.stderr new file mode 100644 index 00000000000..94d6cbdb5fe --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/nested-structs.stderr @@ -0,0 +1,17 @@ +error[E0309]: the parameter type `U` may not live long enough + --> $DIR/nested-structs.rs:22:5 + | +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] + | ^^^^^^^^^^^^^ + | +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] + | ^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0309`. diff --git a/src/test/ui/rfc-2093-infer-outlives/projections-pass.rs b/src/test/ui/rfc-2093-infer-outlives/projections-pass.rs new file mode 100644 index 00000000000..1234e27b866 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/projections-pass.rs @@ -0,0 +1,23 @@ +// 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. + +// must-compile-successfully + +#![feature(infer_outlives_requirements)] +// Outlives requirementes are inferred (RFC 2093) + +// projections: infer <Iterator>::Item: 'a +struct ProjFoo<'a, T: Iterator> { + bar: &'a T::Item +} + + +fn main() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/projections.rs b/src/test/ui/rfc-2093-infer-outlives/projections.rs new file mode 100644 index 00000000000..f6a557c174c --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/projections.rs @@ -0,0 +1,20 @@ +// 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() { } diff --git a/src/test/ui/rfc-2093-infer-outlives/projections.stderr b/src/test/ui/rfc-2093-infer-outlives/projections.stderr new file mode 100644 index 00000000000..9969cf48ecd --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/projections.stderr @@ -0,0 +1,16 @@ +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`. diff --git a/src/test/ui/rfc-2093-infer-outlives/reference-pass.rs b/src/test/ui/rfc-2093-infer-outlives/reference-pass.rs new file mode 100644 index 00000000000..f357685e139 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/reference-pass.rs @@ -0,0 +1,23 @@ +// 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. + +// must-compile-successfully + +#![feature(infer_outlives_requirements)] +// Outlives requirementes are inferred (RFC 2093) + +// reference: infer T: 'a +struct RefFoo<'a, T> { + bar: &'a [T] +} + + +fn main() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/reference.rs b/src/test/ui/rfc-2093-infer-outlives/reference.rs new file mode 100644 index 00000000000..01ccc50a130 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/reference.rs @@ -0,0 +1,18 @@ +// 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 T needs to outlive lifetime 'a. +struct Foo<'a, T> { + bar: &'a [T] //~ ERROR the parameter type `T` may not live long enough [E0309] +} + +fn main() { } diff --git a/src/test/ui/rfc-2093-infer-outlives/reference.stderr b/src/test/ui/rfc-2093-infer-outlives/reference.stderr new file mode 100644 index 00000000000..7236bd535c9 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/reference.stderr @@ -0,0 +1,17 @@ +error[E0309]: the parameter type `T` may not live long enough + --> $DIR/reference.rs:15:5 + | +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] + | ^^^^^^^^^^^^ + | +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] + | ^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0309`. diff --git a/src/test/ui/rfc-2093-infer-outlives/union-pass.rs b/src/test/ui/rfc-2093-infer-outlives/union-pass.rs new file mode 100644 index 00000000000..b4a61346b01 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/union-pass.rs @@ -0,0 +1,39 @@ +// 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. + +// must-compile-successfully + +#![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> { + field1: Bar<'a, T> +} + +// Type U needs to outlive lifetime 'b +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() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/union.rs b/src/test/ui/rfc-2093-infer-outlives/union.rs new file mode 100644 index 00000000000..36b1dccb13e --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/union.rs @@ -0,0 +1,40 @@ +// 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() {} + diff --git a/src/test/ui/rfc-2093-infer-outlives/union.stderr b/src/test/ui/rfc-2093-infer-outlives/union.stderr new file mode 100644 index 00000000000..cd13c423293 --- /dev/null +++ b/src/test/ui/rfc-2093-infer-outlives/union.stderr @@ -0,0 +1,31 @@ +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`. |
