diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e6a09cc67..28727bb18 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -3181,6 +3181,55 @@ fn test<T: Trait>(t: T) { (*t)<|>; } | |||
3181 | assert_eq!(t, "i128"); | 3181 | assert_eq!(t, "i128"); |
3182 | } | 3182 | } |
3183 | 3183 | ||
3184 | #[test] | ||
3185 | fn associated_type_placeholder() { | ||
3186 | let t = type_at( | ||
3187 | r#" | ||
3188 | //- /main.rs | ||
3189 | pub trait ApplyL { | ||
3190 | type Out; | ||
3191 | } | ||
3192 | |||
3193 | pub struct RefMutL<T>; | ||
3194 | |||
3195 | impl<T> ApplyL for RefMutL<T> { | ||
3196 | type Out = <T as ApplyL>::Out; | ||
3197 | } | ||
3198 | |||
3199 | fn test<T: ApplyL>() { | ||
3200 | let y: <RefMutL<T> as ApplyL>::Out = no_matter; | ||
3201 | y<|>; | ||
3202 | } | ||
3203 | "#, | ||
3204 | ); | ||
3205 | // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out<T>` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types]. | ||
3206 | // FIXME: fix type parameter names going missing when going through Chalk | ||
3207 | assert_eq!(t, "ApplyL::Out<[missing name]>"); | ||
3208 | } | ||
3209 | |||
3210 | #[test] | ||
3211 | fn associated_type_placeholder_2() { | ||
3212 | let t = type_at( | ||
3213 | r#" | ||
3214 | //- /main.rs | ||
3215 | pub trait ApplyL { | ||
3216 | type Out; | ||
3217 | } | ||
3218 | fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out; | ||
3219 | |||
3220 | fn test<T: ApplyL>(t: T) { | ||
3221 | let y = foo(t); | ||
3222 | y<|>; | ||
3223 | } | ||
3224 | "#, | ||
3225 | ); | ||
3226 | // FIXME here Chalk doesn't normalize the type to a placeholder. I think we | ||
3227 | // need to add a rule like Normalize(<T as ApplyL>::Out -> ApplyL::Out<T>) | ||
3228 | // to the trait env ourselves here; probably Chalk can't do this by itself. | ||
3229 | // assert_eq!(t, "ApplyL::Out<[missing name]>"); | ||
3230 | assert_eq!(t, "{unknown}"); | ||
3231 | } | ||
3232 | |||
3184 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 3233 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
3185 | let file = db.parse(pos.file_id).ok().unwrap(); | 3234 | let file = db.parse(pos.file_id).ok().unwrap(); |
3186 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | 3235 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |