diff options
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 32 |
3 files changed, 63 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index efc60986b..83f946eee 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -73,6 +73,11 @@ impl<'a> InferenceContext<'a> { | |||
73 | self.coerce_merge_branch(&then_ty, &else_ty) | 73 | self.coerce_merge_branch(&then_ty, &else_ty) |
74 | } | 74 | } |
75 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), | 75 | Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), |
76 | Expr::TryBlock { body } => { | ||
77 | let _inner = self.infer_expr(*body, expected); | ||
78 | // FIXME should be std::result::Result<{inner}, _> | ||
79 | Ty::Unknown | ||
80 | } | ||
76 | Expr::Loop { body } => { | 81 | Expr::Loop { body } => { |
77 | self.infer_expr(*body, &Expectation::has_type(Ty::unit())); | 82 | self.infer_expr(*body, &Expectation::has_type(Ty::unit())); |
78 | // FIXME handle break with value | 83 | // FIXME handle break with value |
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 1f796876d..29e38a06c 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -428,6 +428,32 @@ fn main() { | |||
428 | } | 428 | } |
429 | 429 | ||
430 | #[test] | 430 | #[test] |
431 | fn infer_local_inner_macros() { | ||
432 | let (db, pos) = TestDB::with_position( | ||
433 | r#" | ||
434 | //- /main.rs crate:main deps:foo | ||
435 | fn test() { | ||
436 | let x = foo::foo!(1); | ||
437 | x<|>; | ||
438 | } | ||
439 | |||
440 | //- /lib.rs crate:foo | ||
441 | #[macro_export(local_inner_macros)] | ||
442 | macro_rules! foo { | ||
443 | (1) => { bar!() }; | ||
444 | } | ||
445 | |||
446 | #[macro_export] | ||
447 | macro_rules! bar { | ||
448 | () => { 42 } | ||
449 | } | ||
450 | |||
451 | "#, | ||
452 | ); | ||
453 | assert_eq!("i32", type_at_pos(&db, pos)); | ||
454 | } | ||
455 | |||
456 | #[test] | ||
431 | fn infer_builtin_macros_line() { | 457 | fn infer_builtin_macros_line() { |
432 | assert_snapshot!( | 458 | assert_snapshot!( |
433 | infer(r#" | 459 | infer(r#" |
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 56abc65b8..3d3088965 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs | |||
@@ -1755,3 +1755,35 @@ fn main() { | |||
1755 | "### | 1755 | "### |
1756 | ); | 1756 | ); |
1757 | } | 1757 | } |
1758 | |||
1759 | #[test] | ||
1760 | fn effects_smoke_test() { | ||
1761 | assert_snapshot!( | ||
1762 | infer(r#" | ||
1763 | fn main() { | ||
1764 | let x = unsafe { 92 }; | ||
1765 | let y = async { async { () }.await }; | ||
1766 | let z = try { () }; | ||
1767 | let t = 'a: { 92 }; | ||
1768 | } | ||
1769 | "#), | ||
1770 | @r###" | ||
1771 | 11..131 '{ ...2 }; }': () | ||
1772 | 21..22 'x': i32 | ||
1773 | 32..38 '{ 92 }': i32 | ||
1774 | 34..36 '92': i32 | ||
1775 | 48..49 'y': {unknown} | ||
1776 | 58..80 '{ asyn...wait }': {unknown} | ||
1777 | 60..78 'async ....await': {unknown} | ||
1778 | 66..72 '{ () }': () | ||
1779 | 68..70 '()': () | ||
1780 | 90..91 'z': {unknown} | ||
1781 | 94..104 'try { () }': {unknown} | ||
1782 | 98..104 '{ () }': () | ||
1783 | 100..102 '()': () | ||
1784 | 114..115 't': i32 | ||
1785 | 122..128 '{ 92 }': i32 | ||
1786 | 124..126 '92': i32 | ||
1787 | "### | ||
1788 | ) | ||
1789 | } | ||