about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-12-29 11:22:16 -0500
committerNiko Matsakis <niko@alum.mit.edu>2014-12-30 09:36:23 -0500
commit05eb2eeb61985f481982285ae7714d5cc0d7bdb7 (patch)
tree1b77cdd4a3331cc22f92d34c0f37d53c6cac2893 /src/test
parentc197911c60ce7eaea53ecb357d0409d3e38ff914 (diff)
Adjust tests for inferenceGet more conservative about inference for now. Seems better to err on the side of being more correct rather than less. Fix a bug in typing index expressions that was exposed as a result, and add one type annotation that is not required. Delete some random tests that were relying on old behavior and don't seem to add anything anymore.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/associated-types-bound-failure.rs (renamed from src/test/run-pass/multidispatch-infer-from-single-impl.rs)35
-rw-r--r--src/test/compile-fail/issue-12028.rs (renamed from src/test/run-pass/issue-12028.rs)7
-rw-r--r--src/test/run-pass/associated-types-bound.rs53
3 files changed, 80 insertions, 15 deletions
diff --git a/src/test/run-pass/multidispatch-infer-from-single-impl.rs b/src/test/compile-fail/associated-types-bound-failure.rs
index f4ca67548fd..7981fe31827 100644
--- a/src/test/run-pass/multidispatch-infer-from-single-impl.rs
+++ b/src/test/compile-fail/associated-types-bound-failure.rs
@@ -8,25 +8,32 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// Test that we correctly infer that `E` must be `()` here.  This is
-// known because there is just one impl that could apply where
-// `Self=()`.
+// Test equality constraints on associated types in a where clause.
 
-pub trait FromError<E> {
-    fn from_error(err: E) -> Self;
+#![feature(associated_types)]
+
+pub trait ToInt {
+    fn to_int(&self) -> int;
+}
+
+pub trait GetToInt
+{
+    type R;
+
+    fn get(&self) -> <Self as GetToInt>::R;
 }
 
-impl<E> FromError<E> for E {
-    fn from_error(err: E) -> E {
-        err
-    }
+fn foo<G>(g: G) -> int
+    where G : GetToInt
+{
+    ToInt::to_int(&g.get()) //~ ERROR not implemented
 }
 
-fn test() -> Result<(), ()> {
-    Err(FromError::from_error(()))
+fn bar<G : GetToInt>(g: G) -> int
+    where G::R : ToInt
+{
+    ToInt::to_int(&g.get()) // OK
 }
 
-fn main() {
-    let result = (|| Err(FromError::from_error(())))();
-    let foo: () = result.unwrap_or(());
+pub fn main() {
 }
diff --git a/src/test/run-pass/issue-12028.rs b/src/test/compile-fail/issue-12028.rs
index dbfa330d33d..78502efdec5 100644
--- a/src/test/run-pass/issue-12028.rs
+++ b/src/test/compile-fail/issue-12028.rs
@@ -8,6 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// Test an example where we fail to infer the type parameter H. This
+// is because there is really nothing constraining it. At one time, we
+// would infer based on the where clauses in scope, but that no longer
+// works.
+
 trait Hash<H> {
     fn hash2(&self, hasher: &H) -> u64;
 }
@@ -30,7 +35,7 @@ trait StreamHash<S: Stream, H: StreamHasher<S>>: Hash<H> {
 impl<S: Stream, H: StreamHasher<S>> Hash<H> for u8 {
     fn hash2(&self, hasher: &H) -> u64 {
         let mut stream = hasher.stream();
-        self.input_stream(&mut stream);
+        self.input_stream(&mut stream); //~ ERROR type annotations required
         stream.result()
     }
 }
diff --git a/src/test/run-pass/associated-types-bound.rs b/src/test/run-pass/associated-types-bound.rs
new file mode 100644
index 00000000000..db5119132cc
--- /dev/null
+++ b/src/test/run-pass/associated-types-bound.rs
@@ -0,0 +1,53 @@
+// 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.
+
+// Test equality constraints on associated types in a where clause.
+
+#![feature(associated_types)]
+
+pub trait ToInt {
+    fn to_int(&self) -> int;
+}
+
+impl ToInt for int {
+    fn to_int(&self) -> int { *self }
+}
+
+impl ToInt for uint {
+    fn to_int(&self) -> int { *self as int }
+}
+
+pub trait GetToInt
+{
+    type R : ToInt;
+
+    fn get(&self) -> <Self as GetToInt>::R;
+}
+
+impl GetToInt for int {
+    type R = int;
+    fn get(&self) -> int { *self }
+}
+
+impl GetToInt for uint {
+    type R = uint;
+    fn get(&self) -> uint { *self }
+}
+
+fn foo<G>(g: G) -> int
+    where G : GetToInt
+{
+    ToInt::to_int(&g.get())
+}
+
+pub fn main() {
+    assert_eq!(foo(22i), 22i);
+    assert_eq!(foo(22u), 22i);
+}