about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2021-04-10 17:52:24 +0200
committerLukas Wirth <lukastw97@gmail.com>2021-04-10 17:52:24 +0200
commita15b8136ee3cac8426fa12934f725b161668e9e8 (patch)
tree3107026b9a4b50b0fca68db691c23c25fc7e8aa6
parentd9554c258b9c1cc2a328572e5671bc2a87729b18 (diff)
downloadrust-a15b8136ee3cac8426fa12934f725b161668e9e8.tar.gz
rust-a15b8136ee3cac8426fa12934f725b161668e9e8.zip
Add test for binary op return ty with adt
-rw-r--r--crates/hir_ty/src/tests/traits.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index c93ff91ee13..1879dbc783f 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -3469,3 +3469,50 @@ pub trait Deserialize {
     "#,
     );
 }
+
+#[test]
+fn bin_op_adt_with_rhs_primitive() {
+    check_infer_with_mismatches(
+        r#"
+#[lang = "add"]
+pub trait Add<Rhs = Self> {
+    type Output;
+    fn add(self, rhs: Rhs) -> Self::Output;
+}
+
+struct Wrapper(u32);
+impl Add<u32> for Wrapper {
+    type Output = Self;
+    fn add(self, rhs: u32) -> Wrapper {
+        Wrapper(rhs)
+    }
+}
+fn main(){
+    let wrapped = Wrapper(10);
+    let num: u32 = 2;
+    let res = wrapped + num;
+
+}"#,
+        expect![[r#"
+            72..76 'self': Self
+            78..81 'rhs': Rhs
+            192..196 'self': Wrapper
+            198..201 'rhs': u32
+            219..247 '{     ...     }': Wrapper
+            229..236 'Wrapper': Wrapper(u32) -> Wrapper
+            229..241 'Wrapper(rhs)': Wrapper
+            237..240 'rhs': u32
+            259..345 '{     ...um;  }': ()
+            269..276 'wrapped': Wrapper
+            279..286 'Wrapper': Wrapper(u32) -> Wrapper
+            279..290 'Wrapper(10)': Wrapper
+            287..289 '10': u32
+            300..303 'num': u32
+            311..312 '2': u32
+            322..325 'res': Wrapper
+            328..335 'wrapped': Wrapper
+            328..341 'wrapped + num': Wrapper
+            338..341 'num': u32
+        "#]],
+    )
+}