aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r--crates/ra_hir_ty/src/tests/macros.rs12
-rw-r--r--crates/ra_hir_ty/src/tests/method_resolution.rs18
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs28
3 files changed, 52 insertions, 6 deletions
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs
index 652420ea8..53cd81d46 100644
--- a/crates/ra_hir_ty/src/tests/macros.rs
+++ b/crates/ra_hir_ty/src/tests/macros.rs
@@ -4,7 +4,7 @@ use insta::assert_snapshot;
4use ra_db::fixture::WithFixture; 4use ra_db::fixture::WithFixture;
5 5
6#[test] 6#[test]
7fn cfg_impl_block() { 7fn cfg_impl_def() {
8 let (db, pos) = TestDB::with_position( 8 let (db, pos) = TestDB::with_position(
9 r#" 9 r#"
10//- /main.rs crate:main deps:foo cfg:test 10//- /main.rs crate:main deps:foo cfg:test
@@ -347,17 +347,17 @@ mod m {
347m::foo!(foo); 347m::foo!(foo);
348use foo as bar; 348use foo as bar;
349fn f() -> bar { 0 } 349fn f() -> bar { 0 }
350fn main() { 350fn main() {
351 let _a = f(); 351 let _a = f();
352} 352}
353"#), 353"#),
354 @r###" 354 @r###"
355 [159; 164) '{ 0 }': u64 355 [159; 164) '{ 0 }': u64
356 [161; 162) '0': u64 356 [161; 162) '0': u64
357 [175; 199) '{ ...f(); }': () 357 [175; 197) '{ ...f(); }': ()
358 [187; 189) '_a': u64 358 [185; 187) '_a': u64
359 [193; 194) 'f': fn f() -> u64 359 [191; 192) 'f': fn f() -> u64
360 [193; 196) 'f()': u64 360 [191; 194) 'f()': u64
361 "### 361 "###
362 ); 362 );
363} 363}
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs
index 644d59e17..f9b394f05 100644
--- a/crates/ra_hir_ty/src/tests/method_resolution.rs
+++ b/crates/ra_hir_ty/src/tests/method_resolution.rs
@@ -839,6 +839,24 @@ fn test() { (&S).foo()<|>; }
839} 839}
840 840
841#[test] 841#[test]
842fn method_resolution_unsize_array() {
843 let t = type_at(
844 r#"
845//- /main.rs
846#[lang = "slice"]
847impl<T> [T] {
848 fn len(&self) -> usize { loop {} }
849}
850fn test() {
851 let a = [1, 2, 3];
852 a.len()<|>;
853}
854"#,
855 );
856 assert_eq!(t, "usize");
857}
858
859#[test]
842fn method_resolution_trait_from_prelude() { 860fn method_resolution_trait_from_prelude() {
843 let (db, pos) = TestDB::with_position( 861 let (db, pos) = TestDB::with_position(
844 r#" 862 r#"
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index 7d796d0b9..547010b35 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -568,6 +568,34 @@ mod ops {
568} 568}
569 569
570#[test] 570#[test]
571fn infer_ops_index_autoderef() {
572 let (db, pos) = TestDB::with_position(
573 r#"
574//- /main.rs crate:main deps:std
575fn test() {
576 let a = &[1u32, 2, 3];
577 let b = a[1];
578 b<|>;
579}
580
581//- /std.rs crate:std
582impl<T> ops::Index<u32> for [T] {
583 type Output = T;
584}
585
586#[prelude_import] use ops::*;
587mod ops {
588 #[lang = "index"]
589 pub trait Index<Idx> {
590 type Output;
591 }
592}
593"#,
594 );
595 assert_eq!("u32", type_at_pos(&db, pos));
596}
597
598#[test]
571fn deref_trait() { 599fn deref_trait() {
572 let t = type_at( 600 let t = type_at(
573 r#" 601 r#"