diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-14 12:20:42 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-14 12:20:42 +0100 |
commit | f1587ac26332c3378c41d3cc552b270ee6a45cc4 (patch) | |
tree | a3a0d688da9315f72cad557af7598779e3937f19 /crates/ra_assists/src/handlers | |
parent | 5148d6dc66d80b375a98143dfbb556ec675bbffc (diff) | |
parent | ccd526837459724211c8281926aa86522b2506d5 (diff) |
Merge #4445
4445: Correctly fill default type parameters r=flodiebold a=montekki
Fixes #3877
So, basically even if the parameters are omitted from the `impl` block, check the parameters in `trait` if they have a default type, and if they do go from `hir` to `ast::TypeArg`. I've added a helper for that but I am not sure that it's a proper way to go from `hir` to `ast` here.
Co-authored-by: Fedor Sakharov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r-- | crates/ra_assists/src/handlers/add_missing_impl_members.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index c1ce87914..22e1156d2 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -618,4 +618,54 @@ impl Foo for S { | |||
618 | }"#, | 618 | }"#, |
619 | ) | 619 | ) |
620 | } | 620 | } |
621 | |||
622 | #[test] | ||
623 | fn test_generic_single_default_parameter() { | ||
624 | check_assist( | ||
625 | add_missing_impl_members, | ||
626 | r#" | ||
627 | trait Foo<T = Self> { | ||
628 | fn bar(&self, other: &T); | ||
629 | } | ||
630 | |||
631 | struct S; | ||
632 | impl Foo for S { <|> }"#, | ||
633 | r#" | ||
634 | trait Foo<T = Self> { | ||
635 | fn bar(&self, other: &T); | ||
636 | } | ||
637 | |||
638 | struct S; | ||
639 | impl Foo for S { | ||
640 | <|>fn bar(&self, other: &Self) { | ||
641 | todo!() | ||
642 | } | ||
643 | }"#, | ||
644 | ) | ||
645 | } | ||
646 | |||
647 | #[test] | ||
648 | fn test_generic_default_parameter_is_second() { | ||
649 | check_assist( | ||
650 | add_missing_impl_members, | ||
651 | r#" | ||
652 | trait Foo<T1, T2 = Self> { | ||
653 | fn bar(&self, this: &T1, that: &T2); | ||
654 | } | ||
655 | |||
656 | struct S<T>; | ||
657 | impl Foo<T> for S<T> { <|> }"#, | ||
658 | r#" | ||
659 | trait Foo<T1, T2 = Self> { | ||
660 | fn bar(&self, this: &T1, that: &T2); | ||
661 | } | ||
662 | |||
663 | struct S<T>; | ||
664 | impl Foo<T> for S<T> { | ||
665 | <|>fn bar(&self, this: &T, that: &Self) { | ||
666 | todo!() | ||
667 | } | ||
668 | }"#, | ||
669 | ) | ||
670 | } | ||
621 | } | 671 | } |