about summary refs log tree commit diff
path: root/src/test/compile-fail
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-06-30 22:44:43 +0200
committerGitHub <noreply@github.com>2017-06-30 22:44:43 +0200
commitfc0fb0328b8d38e7e6d7f719555c990e0842820d (patch)
tree2e09a2cf1abe76f311aa9056714e3c1e58c739a7 /src/test/compile-fail
parente72580cf091190c6258648e4cfbca083f20ece3d (diff)
parent37a88f478dd80404b7b8c3890db96f5850ecd7bf (diff)
downloadrust-fc0fb0328b8d38e7e6d7f719555c990e0842820d.tar.gz
rust-fc0fb0328b8d38e7e6d7f719555c990e0842820d.zip
Rollup merge of #42669 - gaurikholkar:master, r=nikomatsakis
Adding diagnostic code 0611 for lifetime errors with one named, one anonymous lifetime parameter

This is a fix for #42517
Note that this only handles the above case for **function declarations** and **traits**.
`impl items` and `closures` will be handled in a later PR.
Example
```
fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
    if x > y { x } else { y }
}
```
now displays the following error message. ui tests have been added for the same.
```
error[E0611]: explicit lifetime required in the type of `x`
11 | fn foo<'a>(x: &i32, y: &'a i32) -> &'a i32 {
   |                     ^ consider changing the type of `x` to `&'a i32`
12 |     if x > y { x } else { y }
   |                  - lifetime `'a` required
```
#42516
r? @nikomatsakis
Diffstat (limited to 'src/test/compile-fail')
-rw-r--r--src/test/compile-fail/E0621-does-not-trigger-for-closures.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/compile-fail/E0621-does-not-trigger-for-closures.rs b/src/test/compile-fail/E0621-does-not-trigger-for-closures.rs
new file mode 100644
index 00000000000..980461bedae
--- /dev/null
+++ b/src/test/compile-fail/E0621-does-not-trigger-for-closures.rs
@@ -0,0 +1,28 @@
+// 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.
+
+// Test that we give the generic E0495 when one of the free regions is
+// bound in a closure (rather than suggesting a change to the signature
+// of the closure, which is not specified in `foo` but rather in `invoke`).
+
+// FIXME - This might be better as a UI test, but the finer details
+// of the error seem to vary on different machines.
+fn invoke<'a, F>(x: &'a i32, f: F) -> &'a i32
+where F: FnOnce(&'a i32, &i32) -> &'a i32
+{
+    let y = 22;
+    f(x, &y)
+}
+
+fn foo<'a>(x: &'a i32) {
+    invoke(&x, |a, b| if a > b { a } else { b }); //~ ERROR E0495
+}
+
+fn main() {}