aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-02-29 14:31:07 +0000
committerFlorian Diebold <[email protected]>2020-02-29 14:31:07 +0000
commit5fe220b9873d587188adae63fa205481a9aae9ce (patch)
tree51599b3664e16cd5f0ef288dac924330c5cd0af0 /crates/ra_hir_ty/src/tests
parent0ec7f760fcd8bb9c2273e004468faa2a8cbeb29d (diff)
Fix a common false-positive type mismatch
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.
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/coercion.rs31
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]
461fn coerce_autoderef_block() {
462 assert_snapshot!(
463 infer_with_mismatches(r#"
464struct String {}
465#[lang = "deref"]
466trait Deref { type Target; }
467impl Deref for String { type Target = str; }
468fn takes_ref_str(x: &str) {}
469fn returns_string() -> String { loop {} }
470fn 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]
461fn closure_return_coerce() { 492fn closure_return_coerce() {
462 assert_snapshot!( 493 assert_snapshot!(
463 infer_with_mismatches(r#" 494 infer_with_mismatches(r#"