diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 103 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 29 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 32 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 68 |
4 files changed, 208 insertions, 24 deletions
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 6b5267232..07398ddcc 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -269,7 +269,7 @@ fn test() { S.foo()<|>; } | |||
269 | } | 269 | } |
270 | 270 | ||
271 | #[test] | 271 | #[test] |
272 | fn infer_impl_items_generated_by_macros() { | 272 | fn infer_assoc_items_generated_by_macros() { |
273 | let t = type_at( | 273 | let t = type_at( |
274 | r#" | 274 | r#" |
275 | //- /main.rs | 275 | //- /main.rs |
@@ -288,7 +288,7 @@ fn test() { S.foo()<|>; } | |||
288 | } | 288 | } |
289 | 289 | ||
290 | #[test] | 290 | #[test] |
291 | fn infer_impl_items_generated_by_macros_chain() { | 291 | fn infer_assoc_items_generated_by_macros_chain() { |
292 | let t = type_at( | 292 | let t = type_at( |
293 | r#" | 293 | r#" |
294 | //- /main.rs | 294 | //- /main.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#" |
@@ -388,6 +428,32 @@ fn main() { | |||
388 | } | 428 | } |
389 | 429 | ||
390 | #[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] | ||
391 | fn infer_builtin_macros_line() { | 457 | fn infer_builtin_macros_line() { |
392 | assert_snapshot!( | 458 | assert_snapshot!( |
393 | infer(r#" | 459 | infer(r#" |
@@ -622,14 +688,31 @@ fn main() { | |||
622 | fn infer_derive_clone_simple() { | 688 | fn infer_derive_clone_simple() { |
623 | let (db, pos) = TestDB::with_position( | 689 | let (db, pos) = TestDB::with_position( |
624 | r#" | 690 | r#" |
625 | //- /main.rs crate:main deps:std | 691 | //- /main.rs crate:main deps:core |
626 | #[derive(Clone)] | 692 | #[derive(Clone)] |
627 | struct S; | 693 | struct S; |
628 | fn test() { | 694 | fn test() { |
629 | S.clone()<|>; | 695 | S.clone()<|>; |
630 | } | 696 | } |
631 | 697 | ||
632 | //- /lib.rs crate:std | 698 | //- /lib.rs crate:core |
699 | #[prelude_import] | ||
700 | use clone::*; | ||
701 | mod clone { | ||
702 | trait Clone { | ||
703 | fn clone(&self) -> Self; | ||
704 | } | ||
705 | } | ||
706 | "#, | ||
707 | ); | ||
708 | assert_eq!("S", type_at_pos(&db, pos)); | ||
709 | } | ||
710 | |||
711 | #[test] | ||
712 | fn infer_derive_clone_in_core() { | ||
713 | let (db, pos) = TestDB::with_position( | ||
714 | r#" | ||
715 | //- /lib.rs crate:core | ||
633 | #[prelude_import] | 716 | #[prelude_import] |
634 | use clone::*; | 717 | use clone::*; |
635 | mod clone { | 718 | mod clone { |
@@ -637,6 +720,14 @@ mod clone { | |||
637 | fn clone(&self) -> Self; | 720 | fn clone(&self) -> Self; |
638 | } | 721 | } |
639 | } | 722 | } |
723 | #[derive(Clone)] | ||
724 | pub struct S; | ||
725 | |||
726 | //- /main.rs crate:main deps:core | ||
727 | use core::S; | ||
728 | fn test() { | ||
729 | S.clone()<|>; | ||
730 | } | ||
640 | "#, | 731 | "#, |
641 | ); | 732 | ); |
642 | assert_eq!("S", type_at_pos(&db, pos)); | 733 | assert_eq!("S", type_at_pos(&db, pos)); |
@@ -646,7 +737,7 @@ mod clone { | |||
646 | fn infer_derive_clone_with_params() { | 737 | fn infer_derive_clone_with_params() { |
647 | let (db, pos) = TestDB::with_position( | 738 | let (db, pos) = TestDB::with_position( |
648 | r#" | 739 | r#" |
649 | //- /main.rs crate:main deps:std | 740 | //- /main.rs crate:main deps:core |
650 | #[derive(Clone)] | 741 | #[derive(Clone)] |
651 | struct S; | 742 | struct S; |
652 | #[derive(Clone)] | 743 | #[derive(Clone)] |
@@ -656,7 +747,7 @@ fn test() { | |||
656 | (Wrapper(S).clone(), Wrapper(NonClone).clone())<|>; | 747 | (Wrapper(S).clone(), Wrapper(NonClone).clone())<|>; |
657 | } | 748 | } |
658 | 749 | ||
659 | //- /lib.rs crate:std | 750 | //- /lib.rs crate:core |
660 | #[prelude_import] | 751 | #[prelude_import] |
661 | use clone::*; | 752 | use clone::*; |
662 | mod clone { | 753 | mod clone { |
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 8a1292c7a..115ad8328 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -535,6 +535,35 @@ fn foo(b: Bar) { | |||
535 | } | 535 | } |
536 | 536 | ||
537 | #[test] | 537 | #[test] |
538 | fn issue_4235_name_conflicts() { | ||
539 | assert_snapshot!( | ||
540 | infer(r#" | ||
541 | struct FOO {} | ||
542 | static FOO:FOO = FOO {}; | ||
543 | |||
544 | impl FOO { | ||
545 | fn foo(&self) {} | ||
546 | } | ||
547 | |||
548 | fn main() { | ||
549 | let a = &FOO; | ||
550 | a.foo(); | ||
551 | } | ||
552 | "#), @r###" | ||
553 | 32..38 'FOO {}': FOO | ||
554 | 64..68 'self': &FOO | ||
555 | 70..72 '{}': () | ||
556 | 86..120 '{ ...o(); }': () | ||
557 | 96..97 'a': &FOO | ||
558 | 100..104 '&FOO': &FOO | ||
559 | 101..104 'FOO': FOO | ||
560 | 110..111 'a': &FOO | ||
561 | 110..117 'a.foo()': () | ||
562 | "### | ||
563 | ); | ||
564 | } | ||
565 | |||
566 | #[test] | ||
538 | fn issue_4053_diesel_where_clauses() { | 567 | fn issue_4053_diesel_where_clauses() { |
539 | assert_snapshot!( | 568 | assert_snapshot!( |
540 | infer(r#" | 569 | 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 | } | ||
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index f51cdd496..9d32cbc7a 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1898,6 +1898,36 @@ fn test() { | |||
1898 | } | 1898 | } |
1899 | 1899 | ||
1900 | #[test] | 1900 | #[test] |
1901 | fn unselected_projection_chalk_fold() { | ||
1902 | let t = type_at( | ||
1903 | r#" | ||
1904 | //- /main.rs | ||
1905 | trait Interner {} | ||
1906 | trait Fold<I: Interner, TI = I> { | ||
1907 | type Result; | ||
1908 | } | ||
1909 | |||
1910 | struct Ty<I: Interner> {} | ||
1911 | impl<I: Interner, TI: Interner> Fold<I, TI> for Ty<I> { | ||
1912 | type Result = Ty<TI>; | ||
1913 | } | ||
1914 | |||
1915 | fn fold<I: Interner, T>(interner: &I, t: T) -> T::Result | ||
1916 | where | ||
1917 | T: Fold<I, I>, | ||
1918 | { | ||
1919 | loop {} | ||
1920 | } | ||
1921 | |||
1922 | fn foo<I: Interner>(interner: &I, t: Ty<I>) { | ||
1923 | fold(interner, t)<|>; | ||
1924 | } | ||
1925 | "#, | ||
1926 | ); | ||
1927 | assert_eq!(t, "Ty<I>"); | ||
1928 | } | ||
1929 | |||
1930 | #[test] | ||
1901 | fn trait_impl_self_ty() { | 1931 | fn trait_impl_self_ty() { |
1902 | let t = type_at( | 1932 | let t = type_at( |
1903 | r#" | 1933 | r#" |
@@ -2025,7 +2055,7 @@ fn test<I: Iterator<Item: Iterator<Item = u32>>>() { | |||
2025 | #[test] | 2055 | #[test] |
2026 | fn proc_macro_server_types() { | 2056 | fn proc_macro_server_types() { |
2027 | assert_snapshot!( | 2057 | assert_snapshot!( |
2028 | infer_with_mismatches(r#" | 2058 | infer(r#" |
2029 | macro_rules! with_api { | 2059 | macro_rules! with_api { |
2030 | ($S:ident, $self:ident, $m:ident) => { | 2060 | ($S:ident, $self:ident, $m:ident) => { |
2031 | $m! { | 2061 | $m! { |
@@ -2039,9 +2069,9 @@ macro_rules! with_api { | |||
2039 | } | 2069 | } |
2040 | macro_rules! associated_item { | 2070 | macro_rules! associated_item { |
2041 | (type TokenStream) => | 2071 | (type TokenStream) => |
2042 | (type TokenStream: 'static + Clone;); | 2072 | (type TokenStream: 'static;); |
2043 | (type Group) => | 2073 | (type Group) => |
2044 | (type Group: 'static + Clone;); | 2074 | (type Group: 'static;); |
2045 | ($($item:tt)*) => ($($item)*;) | 2075 | ($($item:tt)*) => ($($item)*;) |
2046 | } | 2076 | } |
2047 | macro_rules! declare_server_traits { | 2077 | macro_rules! declare_server_traits { |
@@ -2053,21 +2083,23 @@ macro_rules! declare_server_traits { | |||
2053 | } | 2083 | } |
2054 | 2084 | ||
2055 | $(pub trait $name: Types { | 2085 | $(pub trait $name: Types { |
2056 | $(associated_item!(fn $method(&mut self, $($arg: $arg_ty),*) $(-> $ret_ty)?);)* | 2086 | $(associated_item!(fn $method($($arg: $arg_ty),*) $(-> $ret_ty)?);)* |
2057 | })* | 2087 | })* |
2058 | 2088 | ||
2059 | pub trait Server: Types $(+ $name)* {} | 2089 | pub trait Server: Types $(+ $name)* {} |
2060 | impl<S: Types $(+ $name)*> Server for S {} | 2090 | impl<S: Types $(+ $name)*> Server for S {} |
2061 | } | 2091 | } |
2062 | } | 2092 | } |
2093 | |||
2063 | with_api!(Self, self_, declare_server_traits); | 2094 | with_api!(Self, self_, declare_server_traits); |
2064 | struct Group {} | 2095 | struct G {} |
2065 | struct TokenStream {} | 2096 | struct T {} |
2066 | struct Rustc; | 2097 | struct Rustc; |
2067 | impl Types for Rustc { | 2098 | impl Types for Rustc { |
2068 | type TokenStream = TokenStream; | 2099 | type TokenStream = T; |
2069 | type Group = Group; | 2100 | type Group = G; |
2070 | } | 2101 | } |
2102 | |||
2071 | fn make<T>() -> T { loop {} } | 2103 | fn make<T>() -> T { loop {} } |
2072 | impl TokenStream for Rustc { | 2104 | impl TokenStream for Rustc { |
2073 | fn new() -> Self::TokenStream { | 2105 | fn new() -> Self::TokenStream { |
@@ -2075,17 +2107,17 @@ impl TokenStream for Rustc { | |||
2075 | make() | 2107 | make() |
2076 | } | 2108 | } |
2077 | } | 2109 | } |
2078 | "#, true), | 2110 | "#), |
2079 | @r###" | 2111 | @r###" |
2080 | 1115..1126 '{ loop {} }': T | 2112 | 1062..1073 '{ loop {} }': T |
2081 | 1117..1124 'loop {}': ! | 2113 | 1064..1071 'loop {}': ! |
2082 | 1122..1124 '{}': () | 2114 | 1069..1071 '{}': () |
2083 | 1190..1253 '{ ... }': {unknown} | 2115 | 1137..1200 '{ ... }': T |
2084 | 1204..1209 'group': {unknown} | 2116 | 1151..1156 'group': G |
2085 | 1225..1229 'make': fn make<{unknown}>() -> {unknown} | 2117 | 1172..1176 'make': fn make<G>() -> G |
2086 | 1225..1231 'make()': {unknown} | 2118 | 1172..1178 'make()': G |
2087 | 1241..1245 'make': fn make<{unknown}>() -> {unknown} | 2119 | 1188..1192 'make': fn make<T>() -> T |
2088 | 1241..1247 'make()': {unknown} | 2120 | 1188..1194 'make()': T |
2089 | "### | 2121 | "### |
2090 | ); | 2122 | ); |
2091 | } | 2123 | } |