aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-03 12:58:44 +0000
committerGitHub <[email protected]>2019-12-03 12:58:44 +0000
commitc5be0cedf3a9d56c17d988ce6354599b85198fb8 (patch)
tree70e3d0e36efa9568fb7f510f44bd65ff675122a2 /crates/ra_hir_ty/src/tests.rs
parent3376c08052a563a5d2db487c458972378edebf44 (diff)
parent18f25acb89304b2eb0a822b7b49b5e66a439ada7 (diff)
Merge #2463
2463: More correct method resolution r=flodiebold a=flodiebold This should fix the order in which candidates for method resolution are considered, i.e. `(&Foo).clone()` should now be of type `Foo` instead of `&Foo`. It also checks for inherent candidates that the self type unifies properly with the self type in the impl (i.e. `impl Foo<u32>` methods will only be considered for `Foo<u32>`). To be able to get the correct receiver type to check in the method resolution, I needed the unification logic, so I extracted it to the `unify.rs` module. Should fix #2435. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r--crates/ra_hir_ty/src/tests.rs31
1 files changed, 29 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index a3cc5cf95..d5b8d10e2 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -3433,7 +3433,20 @@ pub fn baz() -> usize { 31usize }
3433 assert_eq!("(i32, usize)", type_at_pos(&db, pos)); 3433 assert_eq!("(i32, usize)", type_at_pos(&db, pos));
3434} 3434}
3435 3435
3436#[ignore] 3436#[test]
3437fn method_resolution_unify_impl_self_type() {
3438 let t = type_at(
3439 r#"
3440//- /main.rs
3441struct S<T>;
3442impl S<u32> { fn foo(&self) -> u8 {} }
3443impl S<i32> { fn foo(&self) -> i8 {} }
3444fn test() { (S::<u32>.foo(), S::<i32>.foo())<|>; }
3445"#,
3446 );
3447 assert_eq!(t, "(u8, i8)");
3448}
3449
3437#[test] 3450#[test]
3438fn method_resolution_trait_before_autoref() { 3451fn method_resolution_trait_before_autoref() {
3439 let t = type_at( 3452 let t = type_at(
@@ -3449,7 +3462,6 @@ fn test() { S.foo()<|>; }
3449 assert_eq!(t, "u128"); 3462 assert_eq!(t, "u128");
3450} 3463}
3451 3464
3452#[ignore]
3453#[test] 3465#[test]
3454fn method_resolution_by_value_before_autoref() { 3466fn method_resolution_by_value_before_autoref() {
3455 let t = type_at( 3467 let t = type_at(
@@ -3496,6 +3508,21 @@ fn test() { S.foo()<|>; }
3496} 3508}
3497 3509
3498#[test] 3510#[test]
3511fn method_resolution_impl_ref_before_trait() {
3512 let t = type_at(
3513 r#"
3514//- /main.rs
3515trait Trait { fn foo(self) -> u128; }
3516struct S;
3517impl S { fn foo(&self) -> i8 { 0 } }
3518impl Trait for &S { fn foo(self) -> u128 { 0 } }
3519fn test() { S.foo()<|>; }
3520"#,
3521 );
3522 assert_eq!(t, "i8");
3523}
3524
3525#[test]
3499fn method_resolution_trait_autoderef() { 3526fn method_resolution_trait_autoderef() {
3500 let t = type_at( 3527 let t = type_at(
3501 r#" 3528 r#"