diff options
author | Benjamin Coenen <[email protected]> | 2020-05-02 11:25:04 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-05-02 11:25:04 +0100 |
commit | 0b40876b993ab30421624b831cb03b4042eb0142 (patch) | |
tree | 85abb233dd8645480d61ab857a2b46c1209b142a /crates/ra_hir_ty/src/tests | |
parent | eea21738ab9e0b7438d03f7b2efc18c15cc30cf2 (diff) | |
parent | 75bc0249463b72971200e482d69dad88d4e76ae3 (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 40 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 32 |
2 files changed, 72 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 5ddecbdc6..1f796876d 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -339,6 +339,46 @@ pub fn baz() -> usize { 31usize } | |||
339 | } | 339 | } |
340 | 340 | ||
341 | #[test] | 341 | #[test] |
342 | fn infer_macro_with_dollar_crate_is_correct_in_trait_associate_type() { | ||
343 | let (db, pos) = TestDB::with_position( | ||
344 | r#" | ||
345 | //- /main.rs crate:main deps:foo | ||
346 | use foo::Trait; | ||
347 | |||
348 | fn test() { | ||
349 | let msg = foo::Message(foo::MessageRef); | ||
350 | let r = msg.deref(); | ||
351 | r<|>; | ||
352 | } | ||
353 | |||
354 | //- /lib.rs crate:foo | ||
355 | pub struct MessageRef; | ||
356 | pub struct Message(MessageRef); | ||
357 | |||
358 | pub trait Trait { | ||
359 | type Target; | ||
360 | fn deref(&self) -> &Self::Target; | ||
361 | } | ||
362 | |||
363 | #[macro_export] | ||
364 | macro_rules! expand { | ||
365 | () => { | ||
366 | impl Trait for Message { | ||
367 | type Target = $crate::MessageRef; | ||
368 | fn deref(&self) -> &Self::Target { | ||
369 | &self.0 | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | |||
375 | expand!(); | ||
376 | "#, | ||
377 | ); | ||
378 | assert_eq!("&MessageRef", type_at_pos(&db, pos)); | ||
379 | } | ||
380 | |||
381 | #[test] | ||
342 | fn infer_type_value_non_legacy_macro_use_as() { | 382 | fn infer_type_value_non_legacy_macro_use_as() { |
343 | assert_snapshot!( | 383 | assert_snapshot!( |
344 | infer(r#" | 384 | 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 | } | ||