diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r-- | crates/hir_ty/src/tests/simple.rs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index 5b07948f3..a3ae304a1 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs | |||
@@ -2225,3 +2225,89 @@ fn generic_default_depending_on_other_type_arg_forward() { | |||
2225 | "#]], | 2225 | "#]], |
2226 | ); | 2226 | ); |
2227 | } | 2227 | } |
2228 | |||
2229 | #[test] | ||
2230 | fn infer_operator_overload() { | ||
2231 | check_infer( | ||
2232 | r#" | ||
2233 | struct V2([f32; 2]); | ||
2234 | |||
2235 | #[lang = "add"] | ||
2236 | pub trait Add<Rhs = Self> { | ||
2237 | /// The resulting type after applying the `+` operator. | ||
2238 | type Output; | ||
2239 | |||
2240 | /// Performs the `+` operation. | ||
2241 | #[must_use] | ||
2242 | fn add(self, rhs: Rhs) -> Self::Output; | ||
2243 | } | ||
2244 | |||
2245 | impl Add<V2> for V2 { | ||
2246 | type Output = V2; | ||
2247 | |||
2248 | fn add(self, rhs: V2) -> V2 { | ||
2249 | let x = self.0[0] + rhs.0[0]; | ||
2250 | let y = self.0[1] + rhs.0[1]; | ||
2251 | V2([x, y]) | ||
2252 | } | ||
2253 | } | ||
2254 | |||
2255 | fn test() { | ||
2256 | let va = V2([0.0, 1.0]); | ||
2257 | let vb = V2([0.0, 1.0]); | ||
2258 | |||
2259 | let r = va + vb; | ||
2260 | } | ||
2261 | |||
2262 | "#, | ||
2263 | expect![[r#" | ||
2264 | 207..211 'self': Self | ||
2265 | 213..216 'rhs': Rhs | ||
2266 | 299..303 'self': V2 | ||
2267 | 305..308 'rhs': V2 | ||
2268 | 320..422 '{ ... }': V2 | ||
2269 | 334..335 'x': f32 | ||
2270 | 338..342 'self': V2 | ||
2271 | 338..344 'self.0': [f32; _] | ||
2272 | 338..347 'self.0[0]': {unknown} | ||
2273 | 338..358 'self.0...s.0[0]': f32 | ||
2274 | 345..346 '0': i32 | ||
2275 | 350..353 'rhs': V2 | ||
2276 | 350..355 'rhs.0': [f32; _] | ||
2277 | 350..358 'rhs.0[0]': {unknown} | ||
2278 | 356..357 '0': i32 | ||
2279 | 372..373 'y': f32 | ||
2280 | 376..380 'self': V2 | ||
2281 | 376..382 'self.0': [f32; _] | ||
2282 | 376..385 'self.0[1]': {unknown} | ||
2283 | 376..396 'self.0...s.0[1]': f32 | ||
2284 | 383..384 '1': i32 | ||
2285 | 388..391 'rhs': V2 | ||
2286 | 388..393 'rhs.0': [f32; _] | ||
2287 | 388..396 'rhs.0[1]': {unknown} | ||
2288 | 394..395 '1': i32 | ||
2289 | 406..408 'V2': V2([f32; _]) -> V2 | ||
2290 | 406..416 'V2([x, y])': V2 | ||
2291 | 409..415 '[x, y]': [f32; _] | ||
2292 | 410..411 'x': f32 | ||
2293 | 413..414 'y': f32 | ||
2294 | 436..519 '{ ... vb; }': () | ||
2295 | 446..448 'va': V2 | ||
2296 | 451..453 'V2': V2([f32; _]) -> V2 | ||
2297 | 451..465 'V2([0.0, 1.0])': V2 | ||
2298 | 454..464 '[0.0, 1.0]': [f32; _] | ||
2299 | 455..458 '0.0': f32 | ||
2300 | 460..463 '1.0': f32 | ||
2301 | 475..477 'vb': V2 | ||
2302 | 480..482 'V2': V2([f32; _]) -> V2 | ||
2303 | 480..494 'V2([0.0, 1.0])': V2 | ||
2304 | 483..493 '[0.0, 1.0]': [f32; _] | ||
2305 | 484..487 '0.0': f32 | ||
2306 | 489..492 '1.0': f32 | ||
2307 | 505..506 'r': V2 | ||
2308 | 509..511 'va': V2 | ||
2309 | 509..516 'va + vb': V2 | ||
2310 | 514..516 'vb': V2 | ||
2311 | "#]], | ||
2312 | ); | ||
2313 | } | ||