--- /dev/null
+// Copyright 2016 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.
+
+fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
+ if x > y { x } else { y }
+}
+
+fn main() { }
--- /dev/null
+error[E0312]: lifetime of reference outlives lifetime of borrowed content...
+ --> $DIR/ex1-return-one-existing-name-if-else.rs:12:27
+ |
+12 | if x > y { x } else { y }
+ | ^
+ |
+note: ...the reference is valid for the lifetime 'a as defined on the body at 11:43...
+ --> $DIR/ex1-return-one-existing-name-if-else.rs:11:44
+ |
+11 | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
+ | ____________________________________________^ starting here...
+12 | | if x > y { x } else { y }
+13 | | }
+ | |_^ ...ending here
+note: ...but the borrowed content is only valid for the anonymous lifetime #1 defined on the body at 11:43
+ --> $DIR/ex1-return-one-existing-name-if-else.rs:11:44
+ |
+11 | fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
+ | ____________________________________________^ starting here...
+12 | | if x > y { x } else { y }
+13 | | }
+ | |_^ ...ending here
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+fn foo(x: &i32, y: &i32) -> &i32 {
+ if x > y { x } else { y }
+}
+
+fn main() { }
--- /dev/null
+error[E0106]: missing lifetime specifier
+ --> $DIR/ex1b-return-no-names-if-else.rs:11:29
+ |
+11 | fn foo(x: &i32, y: &i32) -> &i32 {
+ | ^ expected lifetime parameter
+ |
+ = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y`
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+struct Ref<'a, T: 'a> {
+ data: &'a T
+}
+
+fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
+ x.push(y);
+}
+
+fn main() { }
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/ex2a-push-one-existing-name.rs:16:12
+ |
+16 | x.push(y);
+ | ^ lifetime mismatch
+ |
+ = note: expected type `Ref<'a, i32>`
+ found type `Ref<'_, i32>`
+note: the anonymous lifetime #2 defined on the body at 15:51...
+ --> $DIR/ex2a-push-one-existing-name.rs:15:52
+ |
+15 | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
+ | ____________________________________________________^ starting here...
+16 | | x.push(y);
+17 | | }
+ | |_^ ...ending here
+note: ...does not necessarily outlive the lifetime 'a as defined on the body at 15:51
+ --> $DIR/ex2a-push-one-existing-name.rs:15:52
+ |
+15 | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<i32>) {
+ | ____________________________________________________^ starting here...
+16 | | x.push(y);
+17 | | }
+ | |_^ ...ending here
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+struct Ref<'a, T: 'a> {
+ data: &'a T
+}
+
+fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
+ x.push(y);
+}
+
+fn main() { }
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/ex2b-push-no-existing-names.rs:16:12
+ |
+16 | x.push(y);
+ | ^ lifetime mismatch
+ |
+ = note: expected type `Ref<'_, i32>`
+ found type `Ref<'_, i32>`
+note: the anonymous lifetime #3 defined on the body at 15:43...
+ --> $DIR/ex2b-push-no-existing-names.rs:15:44
+ |
+15 | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
+ | ____________________________________________^ starting here...
+16 | | x.push(y);
+17 | | }
+ | |_^ ...ending here
+note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 15:43
+ --> $DIR/ex2b-push-no-existing-names.rs:15:44
+ |
+15 | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
+ | ____________________________________________^ starting here...
+16 | | x.push(y);
+17 | | }
+ | |_^ ...ending here
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+struct Ref<'a, T: 'a> {
+ data: &'a T
+}
+
+fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
+ let z = Ref { data: y.data };
+ x.push(z);
+}
+
+fn main() { }
--- /dev/null
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+ --> $DIR/ex2c-push-inference-variable.rs:16:13
+ |
+16 | let z = Ref { data: y.data };
+ | ^^^
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+struct Ref<'a, T: 'a> {
+ data: &'a T
+}
+
+fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
+ let a: &mut Vec<Ref<i32>> = x;
+ let b = Ref { data: y.data };
+ a.push(b);
+}
+
+fn main() { }
--- /dev/null
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+ --> $DIR/ex2d-push-inference-variable-2.rs:17:13
+ |
+17 | let b = Ref { data: y.data };
+ | ^^^
+
+error: aborting due to previous error
+
--- /dev/null
+// Copyright 2016 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.
+
+struct Ref<'a, T: 'a> {
+ data: &'a T
+}
+
+fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
+ let a: &mut Vec<Ref<i32>> = x;
+ let b = Ref { data: y.data };
+ Vec::push(a, b);
+}
+
+fn main() { }
--- /dev/null
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+ --> $DIR/ex2e-push-inference-variable-3.rs:17:13
+ |
+17 | let b = Ref { data: y.data };
+ | ^^^
+
+error: aborting due to previous error
+