From a15b8136ee3cac8426fa12934f725b161668e9e8 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 10 Apr 2021 17:52:24 +0200 Subject: Add test for binary op return ty with adt --- crates/hir_ty/src/tests/traits.rs | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index c93ff91ee..1879dbc78 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 { + type Output; + fn add(self, rhs: Rhs) -> Self::Output; +} + +struct Wrapper(u32); +impl Add 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 + "#]], + ) +} -- cgit v1.2.3