about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-02-25 11:42:30 +0100
committerGitHub <noreply@github.com>2019-02-25 11:42:30 +0100
commite53fbf8bf21a250ae1dcf39629edb9eaaea066eb (patch)
tree498050d9f7bf0a06cf74dd5d3cab174e3a97ce2b /src
parent3f6d65ac7a876e4f1e2cd42531863542e0b60600 (diff)
parent70290947355188be67db4f721be636b0695a4c80 (diff)
downloadrust-e53fbf8bf21a250ae1dcf39629edb9eaaea066eb.tar.gz
rust-e53fbf8bf21a250ae1dcf39629edb9eaaea066eb.zip
Rollup merge of #58725 - jamwt:fix-27949, r=Centril
Test that binop subtyping in rustc_typeck fixes #27949
Diffstat (limited to 'src')
-rw-r--r--src/test/run-pass/issues/issue-27949.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/run-pass/issues/issue-27949.rs b/src/test/run-pass/issues/issue-27949.rs
new file mode 100644
index 00000000000..e905da72aad
--- /dev/null
+++ b/src/test/run-pass/issues/issue-27949.rs
@@ -0,0 +1,41 @@
+// run-pass
+//
+// At one time, the `==` operator (and other binary operators) did not
+// support subtyping during type checking, and would therefore require
+// LHS and RHS to be exactly identical--i.e. to have the same lifetimes.
+//
+// This was fixed in 1a7fb7dc78439a704f024609ce3dc0beb1386552.
+
+#[derive(Copy, Clone)]
+struct Input<'a> {
+    foo: &'a u32
+}
+
+impl <'a> std::cmp::PartialEq<Input<'a>> for Input<'a> {
+    fn eq(&self, other: &Input<'a>) -> bool {
+        self.foo == other.foo
+    }
+
+    fn ne(&self, other: &Input<'a>) -> bool {
+        self.foo != other.foo
+    }
+}
+
+
+fn check_equal<'a, 'b>(x: Input<'a>, y: Input<'b>) -> bool {
+    // Type checking error due to 'a != 'b prior to 1a7fb7dc78
+    x == y
+}
+
+fn main() {
+    let i = 1u32;
+    let j = 1u32;
+    let k = 2u32;
+
+    let input_i = Input { foo: &i };
+    let input_j = Input { foo: &j };
+    let input_k = Input { foo: &k };
+    assert!(check_equal(input_i, input_i));
+    assert!(check_equal(input_i, input_j));
+    assert!(!check_equal(input_i, input_k));
+}