diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-06 14:19:06 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-06 14:19:06 +0000 |
commit | a25e8cff6755c1a0c46ee3690dcd75b641c0b3e4 (patch) | |
tree | 891cf4be4893c79598800928e7c0b669d9d2a9c2 /crates/ra_hir_ty/src/tests | |
parent | d2b210a02e3e8ee1cf38909411fa8945aec99f4e (diff) | |
parent | f86fe3d891ab295e9e394a1338da86524a6205d3 (diff) |
Merge #2487
2487: Don't unify within a reference r=matklad a=flodiebold
If we are expecting a `&Foo` and get a `&something`, when checking the `something`, we are *expecting* a `Foo`, but we shouldn't try to unify whatever we get with that expectation, because it could actually be a `&Foo`, and `&&Foo` coerces to `&Foo`. So this fixes quite a few false type mismatches.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/coercion.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index 1530fcc63..58b22396f 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | use super::infer_with_mismatches; | ||
1 | use insta::assert_snapshot; | 2 | use insta::assert_snapshot; |
2 | use test_utils::covers; | 3 | use test_utils::covers; |
3 | 4 | ||
@@ -367,3 +368,38 @@ fn test() { | |||
367 | "### | 368 | "### |
368 | ); | 369 | ); |
369 | } | 370 | } |
371 | |||
372 | #[test] | ||
373 | fn coerce_autoderef() { | ||
374 | assert_snapshot!( | ||
375 | infer_with_mismatches(r#" | ||
376 | struct Foo; | ||
377 | fn takes_ref_foo(x: &Foo) {} | ||
378 | fn test() { | ||
379 | takes_ref_foo(&Foo); | ||
380 | takes_ref_foo(&&Foo); | ||
381 | takes_ref_foo(&&&Foo); | ||
382 | } | ||
383 | "#, true), | ||
384 | @r###" | ||
385 | [30; 31) 'x': &Foo | ||
386 | [39; 41) '{}': () | ||
387 | [52; 133) '{ ...oo); }': () | ||
388 | [58; 71) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> () | ||
389 | [58; 77) 'takes_...(&Foo)': () | ||
390 | [72; 76) '&Foo': &Foo | ||
391 | [73; 76) 'Foo': Foo | ||
392 | [83; 96) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> () | ||
393 | [83; 103) 'takes_...&&Foo)': () | ||
394 | [97; 102) '&&Foo': &&Foo | ||
395 | [98; 102) '&Foo': &Foo | ||
396 | [99; 102) 'Foo': Foo | ||
397 | [109; 122) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> () | ||
398 | [109; 130) 'takes_...&&Foo)': () | ||
399 | [123; 129) '&&&Foo': &&&Foo | ||
400 | [124; 129) '&&Foo': &&Foo | ||
401 | [125; 129) '&Foo': &Foo | ||
402 | [126; 129) 'Foo': Foo | ||
403 | "### | ||
404 | ); | ||
405 | } | ||