From c8b2ec8c20be44ae19d15e90ff812745f029899e Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 12 Apr 2020 12:28:24 +0200 Subject: 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.) --- crates/ra_hir_ty/src/tests/traits.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') 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 @@ -2022,6 +2022,33 @@ fn main() { ); } +#[test] +fn associated_type_bound() { + let t = type_at( + r#" +//- /main.rs +pub trait Trait { + type Item: OtherTrait; +} +pub trait OtherTrait { + fn foo(&self) -> T; +} + +// this is just a workaround for chalk#234 +pub struct S; +impl Trait for S { + type Item = ::Item; +} + +fn test() { + let y: as Trait>::Item = no_matter; + y.foo()<|>; +} +"#, + ); + assert_eq!(t, "u32"); +} + #[test] fn dyn_trait_through_chalk() { let t = type_at( -- cgit v1.2.3