aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs60
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]
2954fn generic_param_env_1() {
2955 let t = type_at(
2956 r#"
2957//- /main.rs
2958trait Clone {}
2959trait Trait { fn foo(self) -> u128; }
2960struct S;
2961impl Clone for S {}
2962impl<T> Trait for T where T: Clone {}
2963fn test<T: Clone>(t: T) { t.foo()<|>; }
2964"#,
2965 );
2966 assert_eq!(t, "u128");
2967}
2968
2969#[test]
2970fn generic_param_env_1_not_met() {
2971 let t = type_at(
2972 r#"
2973//- /main.rs
2974trait Clone {}
2975trait Trait { fn foo(self) -> u128; }
2976struct S;
2977impl Clone for S {}
2978impl<T> Trait for T where T: Clone {}
2979fn test<T>(t: T) { t.foo()<|>; }
2980"#,
2981 );
2982 assert_eq!(t, "{unknown}");
2983}
2984
2985#[test]
2986fn generic_param_env_2() {
2987 let t = type_at(
2988 r#"
2989//- /main.rs
2990trait Trait { fn foo(self) -> u128; }
2991struct S;
2992impl Trait for S {}
2993fn test<T: Trait>(t: T) { t.foo()<|>; }
2994"#,
2995 );
2996 assert_eq!(t, "u128");
2997}
2998
2999#[test]
3000fn generic_param_env_2_not_met() {
3001 let t = type_at(
3002 r#"
3003//- /main.rs
3004trait Trait { fn foo(self) -> u128; }
3005struct S;
3006impl Trait for S {}
3007fn test<T>(t: T) { t.foo()<|>; }
3008"#,
3009 );
3010 assert_eq!(t, "{unknown}");
3011}
3012
2953fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 3013fn 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();