about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorKiet Tran <ktt3ja@gmail.com>2014-03-24 19:11:44 -0400
committerKiet Tran <ktt3ja@gmail.com>2014-03-26 19:13:30 -0400
commit1d99d37f87d4cc46d285e883c2fc28b3e4e5c405 (patch)
tree80bdc950d8f57422c05d90088169079de1607deb /src/test
parent533a5263279d177127607f1883b9a85824d5ef52 (diff)
downloadrust-1d99d37f87d4cc46d285e883c2fc28b3e4e5c405.tar.gz
rust-1d99d37f87d4cc46d285e883c2fc28b3e4e5c405.zip
Visit type parameter in lifetime suggestion
Previously, Rebuilder did not visit type parameters when rebuilding
generics and path, so in some cases the suggestion turns out to be
erroneous.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs36
-rw-r--r--src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs11
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs
new file mode 100644
index 00000000000..a6bf5a4b653
--- /dev/null
+++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-2.rs
@@ -0,0 +1,36 @@
+// Copyright 2014 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
+
+use std::iter::{Range,range};
+
+trait Itble<'r, T, I: Iterator<T>> { fn iter(&'r self) -> I; }
+
+impl<'r> Itble<'r, uint, Range<uint>> for (uint, uint) {
+    fn iter(&'r self) -> Range<uint> {
+        let &(min, max) = self;
+        range(min, max)
+    }
+}
+
+fn check<'r, I: Iterator<uint>, T: Itble<'r, uint, I>>(cont: &T) -> bool {
+//~^ NOTE: consider using an explicit lifetime parameter as shown: fn check<'a, I: Iterator<uint>, T: Itble<'a, uint, I>>(cont: &'a T) -> bool
+    let cont_iter = cont.iter(); //~ ERROR: cannot infer
+    let result = cont_iter.fold(Some(0u16), |state, val| {
+        state.map_or(None, |mask| {
+            let bit = 1 << val;
+            if mask & bit == 0 {Some(mask|bit)} else {None}
+        })
+    });
+    result.is_some()
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs
index 709f15d3552..33b849f346a 100644
--- a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs
+++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs
@@ -54,5 +54,16 @@ fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&int, &int, &int) {
     //~^^ ERROR: cannot infer
 }
 
+struct Cat<'x, T> { cat: &'x int, t: T }
+struct Dog<'y> { dog: &'y int }
+fn cat<'x>(x: Cat<'x, Dog>) -> &int {
+//~^ NOTE: consider using an explicit lifetime parameter as shown: fn cat<'a, 'x>(x: Cat<'x, Dog<'a>>) -> &'a int
+    x.t.dog //~ ERROR: mismatched types
+}
+
+fn cat2<'x, 'y>(x: Cat<'x, Dog<'y>>) -> &int {
+//~^ NOTE: consider using an explicit lifetime parameter as shown: fn cat2<'a, 'x>(x: Cat<'x, Dog<'a>>) -> &'a int
+    x.t.dog //~ ERROR: mismatched types
+}
 
 fn main() {}