diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-29 15:27:53 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-29 15:27:53 +0000 |
commit | 0ae7054210b0bbc48ea51c3672be640d3096cfdd (patch) | |
tree | 51599b3664e16cd5f0ef288dac924330c5cd0af0 /crates/ra_hir_ty/src/tests | |
parent | 0ec7f760fcd8bb9c2273e004468faa2a8cbeb29d (diff) | |
parent | 5fe220b9873d587188adae63fa205481a9aae9ce (diff) |
Merge #3376
3376: Fix a common false-positive type mismatch r=matklad a=flodiebold
E.g. for `&{ some_string() }` in a context where a `&str` is expected, we
reported a mismatch inside the block. The problem is that we're passing an
expectation of `str` down, but the expectation is more of a hint in this case.
There's a long comment in rustc about this, which I just copied.
Also, fix reported location for type mismatches in macros.
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 | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index 60ad6e9be..1e303f5ce 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs | |||
@@ -458,6 +458,37 @@ fn test() { | |||
458 | } | 458 | } |
459 | 459 | ||
460 | #[test] | 460 | #[test] |
461 | fn coerce_autoderef_block() { | ||
462 | assert_snapshot!( | ||
463 | infer_with_mismatches(r#" | ||
464 | struct String {} | ||
465 | #[lang = "deref"] | ||
466 | trait Deref { type Target; } | ||
467 | impl Deref for String { type Target = str; } | ||
468 | fn takes_ref_str(x: &str) {} | ||
469 | fn returns_string() -> String { loop {} } | ||
470 | fn test() { | ||
471 | takes_ref_str(&{ returns_string() }); | ||
472 | } | ||
473 | "#, true), | ||
474 | @r###" | ||
475 | [127; 128) 'x': &str | ||
476 | [136; 138) '{}': () | ||
477 | [169; 180) '{ loop {} }': String | ||
478 | [171; 178) 'loop {}': ! | ||
479 | [176; 178) '{}': () | ||
480 | [191; 236) '{ ... }); }': () | ||
481 | [197; 210) 'takes_ref_str': fn takes_ref_str(&str) -> () | ||
482 | [197; 233) 'takes_...g() })': () | ||
483 | [211; 232) '&{ ret...ng() }': &String | ||
484 | [212; 232) '{ retu...ng() }': String | ||
485 | [214; 228) 'returns_string': fn returns_string() -> String | ||
486 | [214; 230) 'return...ring()': String | ||
487 | "### | ||
488 | ); | ||
489 | } | ||
490 | |||
491 | #[test] | ||
461 | fn closure_return_coerce() { | 492 | fn closure_return_coerce() { |
462 | assert_snapshot!( | 493 | assert_snapshot!( |
463 | infer_with_mismatches(r#" | 494 | infer_with_mismatches(r#" |