diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 65 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 41 |
2 files changed, 106 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 42814941f..32457bbf7 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -484,6 +484,51 @@ fn bar() -> u32 {0} | |||
484 | } | 484 | } |
485 | 485 | ||
486 | #[test] | 486 | #[test] |
487 | fn infer_builtin_macros_include_concat_with_bad_env_should_failed() { | ||
488 | let (db, pos) = TestDB::with_position( | ||
489 | r#" | ||
490 | //- /main.rs | ||
491 | #[rustc_builtin_macro] | ||
492 | macro_rules! include {() => {}} | ||
493 | |||
494 | #[rustc_builtin_macro] | ||
495 | macro_rules! concat {() => {}} | ||
496 | |||
497 | #[rustc_builtin_macro] | ||
498 | macro_rules! env {() => {}} | ||
499 | |||
500 | include!(concat!(env!("OUT_DIR"), "/foo.rs")); | ||
501 | |||
502 | fn main() { | ||
503 | bar()<|>; | ||
504 | } | ||
505 | |||
506 | //- /foo.rs | ||
507 | fn bar() -> u32 {0} | ||
508 | "#, | ||
509 | ); | ||
510 | assert_eq!("{unknown}", type_at_pos(&db, pos)); | ||
511 | } | ||
512 | |||
513 | #[test] | ||
514 | fn infer_builtin_macros_include_itself_should_failed() { | ||
515 | let (db, pos) = TestDB::with_position( | ||
516 | r#" | ||
517 | //- /main.rs | ||
518 | #[rustc_builtin_macro] | ||
519 | macro_rules! include {() => {}} | ||
520 | |||
521 | include!("main.rs"); | ||
522 | |||
523 | fn main() { | ||
524 | 0<|> | ||
525 | } | ||
526 | "#, | ||
527 | ); | ||
528 | assert_eq!("i32", type_at_pos(&db, pos)); | ||
529 | } | ||
530 | |||
531 | #[test] | ||
487 | fn infer_builtin_macros_concat_with_lazy() { | 532 | fn infer_builtin_macros_concat_with_lazy() { |
488 | assert_snapshot!( | 533 | assert_snapshot!( |
489 | infer(r#" | 534 | infer(r#" |
@@ -505,6 +550,26 @@ fn main() { | |||
505 | } | 550 | } |
506 | 551 | ||
507 | #[test] | 552 | #[test] |
553 | fn infer_builtin_macros_env() { | ||
554 | assert_snapshot!( | ||
555 | infer(r#" | ||
556 | //- /main.rs env:foo=bar | ||
557 | #[rustc_builtin_macro] | ||
558 | macro_rules! env {() => {}} | ||
559 | |||
560 | fn main() { | ||
561 | let x = env!("foo"); | ||
562 | } | ||
563 | "#), | ||
564 | @r###" | ||
565 | ![0; 5) '"bar"': &str | ||
566 | [88; 116) '{ ...o"); }': () | ||
567 | [98; 99) 'x': &str | ||
568 | "### | ||
569 | ); | ||
570 | } | ||
571 | |||
572 | #[test] | ||
508 | fn infer_derive_clone_simple() { | 573 | fn infer_derive_clone_simple() { |
509 | let (db, pos) = TestDB::with_position( | 574 | let (db, pos) = TestDB::with_position( |
510 | r#" | 575 | r#" |
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 547010b35..f009a708c 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -1803,6 +1803,47 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | |||
1803 | } | 1803 | } |
1804 | 1804 | ||
1805 | #[test] | 1805 | #[test] |
1806 | fn unselected_projection_on_trait_self() { | ||
1807 | assert_snapshot!(infer( | ||
1808 | r#" | ||
1809 | //- /main.rs | ||
1810 | trait Trait { | ||
1811 | type Item; | ||
1812 | |||
1813 | fn f(&self, x: Self::Item); | ||
1814 | } | ||
1815 | |||
1816 | struct S; | ||
1817 | |||
1818 | impl Trait for S { | ||
1819 | type Item = u32; | ||
1820 | fn f(&self, x: Self::Item) { let y = x; } | ||
1821 | } | ||
1822 | |||
1823 | struct S2; | ||
1824 | |||
1825 | impl Trait for S2 { | ||
1826 | type Item = i32; | ||
1827 | fn f(&self, x: <Self>::Item) { let y = x; } | ||
1828 | } | ||
1829 | "#, | ||
1830 | ), @r###" | ||
1831 | [54; 58) 'self': &Self | ||
1832 | [60; 61) 'x': {unknown} | ||
1833 | [140; 144) 'self': &S | ||
1834 | [146; 147) 'x': u32 | ||
1835 | [161; 175) '{ let y = x; }': () | ||
1836 | [167; 168) 'y': u32 | ||
1837 | [171; 172) 'x': u32 | ||
1838 | [242; 246) 'self': &S2 | ||
1839 | [248; 249) 'x': i32 | ||
1840 | [265; 279) '{ let y = x; }': () | ||
1841 | [271; 272) 'y': i32 | ||
1842 | [275; 276) 'x': i32 | ||
1843 | "###); | ||
1844 | } | ||
1845 | |||
1846 | #[test] | ||
1806 | fn trait_impl_self_ty() { | 1847 | fn trait_impl_self_ty() { |
1807 | let t = type_at( | 1848 | let t = type_at( |
1808 | r#" | 1849 | r#" |