diff options
author | Florian Diebold <[email protected]> | 2020-04-12 11:28:24 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-04-13 14:57:28 +0100 |
commit | c8b2ec8c20be44ae19d15e90ff812745f029899e (patch) | |
tree | 98ed585238a37d722159a489db24e0514ae562ce /crates/ra_hir_ty/src/tests | |
parent | c388130f5ffbcbe7d3131213a24d12d02f769b87 (diff) |
Add support for bounds on associated types in trait definitions
E.g.
```
trait Trait {
type Item: SomeOtherTrait;
}
```
Note that these don't simply desugar to where clauses; as I understand it, where
clauses have to be proved by the *user* of the trait, but these bounds are proved
by the *implementor*. (Also, where clauses on associated types are unstable.)
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 22ae6ca90..af8c63d64 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -2023,6 +2023,33 @@ fn main() { | |||
2023 | } | 2023 | } |
2024 | 2024 | ||
2025 | #[test] | 2025 | #[test] |
2026 | fn associated_type_bound() { | ||
2027 | let t = type_at( | ||
2028 | r#" | ||
2029 | //- /main.rs | ||
2030 | pub trait Trait { | ||
2031 | type Item: OtherTrait<u32>; | ||
2032 | } | ||
2033 | pub trait OtherTrait<T> { | ||
2034 | fn foo(&self) -> T; | ||
2035 | } | ||
2036 | |||
2037 | // this is just a workaround for chalk#234 | ||
2038 | pub struct S<T>; | ||
2039 | impl<T: Trait> Trait for S<T> { | ||
2040 | type Item = <T as Trait>::Item; | ||
2041 | } | ||
2042 | |||
2043 | fn test<T: Trait>() { | ||
2044 | let y: <S<T> as Trait>::Item = no_matter; | ||
2045 | y.foo()<|>; | ||
2046 | } | ||
2047 | "#, | ||
2048 | ); | ||
2049 | assert_eq!(t, "u32"); | ||
2050 | } | ||
2051 | |||
2052 | #[test] | ||
2026 | fn dyn_trait_through_chalk() { | 2053 | fn dyn_trait_through_chalk() { |
2027 | let t = type_at( | 2054 | let t = type_at( |
2028 | r#" | 2055 | r#" |