diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index fe5e89f2d..594e82af2 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2950,6 +2950,66 @@ fn test(o: O<S>) { | |||
2950 | assert_eq!(t, "&str"); | 2950 | assert_eq!(t, "&str"); |
2951 | } | 2951 | } |
2952 | 2952 | ||
2953 | #[test] | ||
2954 | fn generic_param_env_1() { | ||
2955 | let t = type_at( | ||
2956 | r#" | ||
2957 | //- /main.rs | ||
2958 | trait Clone {} | ||
2959 | trait Trait { fn foo(self) -> u128; } | ||
2960 | struct S; | ||
2961 | impl Clone for S {} | ||
2962 | impl<T> Trait for T where T: Clone {} | ||
2963 | fn test<T: Clone>(t: T) { t.foo()<|>; } | ||
2964 | "#, | ||
2965 | ); | ||
2966 | assert_eq!(t, "u128"); | ||
2967 | } | ||
2968 | |||
2969 | #[test] | ||
2970 | fn generic_param_env_1_not_met() { | ||
2971 | let t = type_at( | ||
2972 | r#" | ||
2973 | //- /main.rs | ||
2974 | trait Clone {} | ||
2975 | trait Trait { fn foo(self) -> u128; } | ||
2976 | struct S; | ||
2977 | impl Clone for S {} | ||
2978 | impl<T> Trait for T where T: Clone {} | ||
2979 | fn test<T>(t: T) { t.foo()<|>; } | ||
2980 | "#, | ||
2981 | ); | ||
2982 | assert_eq!(t, "{unknown}"); | ||
2983 | } | ||
2984 | |||
2985 | #[test] | ||
2986 | fn generic_param_env_2() { | ||
2987 | let t = type_at( | ||
2988 | r#" | ||
2989 | //- /main.rs | ||
2990 | trait Trait { fn foo(self) -> u128; } | ||
2991 | struct S; | ||
2992 | impl Trait for S {} | ||
2993 | fn test<T: Trait>(t: T) { t.foo()<|>; } | ||
2994 | "#, | ||
2995 | ); | ||
2996 | assert_eq!(t, "u128"); | ||
2997 | } | ||
2998 | |||
2999 | #[test] | ||
3000 | fn generic_param_env_2_not_met() { | ||
3001 | let t = type_at( | ||
3002 | r#" | ||
3003 | //- /main.rs | ||
3004 | trait Trait { fn foo(self) -> u128; } | ||
3005 | struct S; | ||
3006 | impl Trait for S {} | ||
3007 | fn test<T>(t: T) { t.foo()<|>; } | ||
3008 | "#, | ||
3009 | ); | ||
3010 | assert_eq!(t, "{unknown}"); | ||
3011 | } | ||
3012 | |||
2953 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 3013 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
2954 | let file = db.parse(pos.file_id).ok().unwrap(); | 3014 | let file = db.parse(pos.file_id).ok().unwrap(); |
2955 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); | 3015 | let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); |