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/method_resolution.rs18
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs28
2 files changed, 46 insertions, 0 deletions
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#"