diff options
author | Ville Penttinen <[email protected]> | 2019-02-25 07:27:47 +0000 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-02-25 08:51:46 +0000 |
commit | 18b0bd9bffeeeaf664f4a21894d5bfff51e82b32 (patch) | |
tree | de8c51b51b8324d6566143e7b73997c4c61a3f70 /crates/ra_hir/src/ty/tests.rs | |
parent | 7ffff9c74caae108db53366e3b90857b7c405c6c (diff) |
Add const type inference
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 642259225..8de46a29e 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -1006,6 +1006,43 @@ mod foo { | |||
1006 | assert_eq!("i128", type_at_pos(&db, pos)); | 1006 | assert_eq!("i128", type_at_pos(&db, pos)); |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | #[test] | ||
1010 | fn infer_const() { | ||
1011 | check_inference( | ||
1012 | "infer_const", | ||
1013 | r#" | ||
1014 | struct Foo; | ||
1015 | impl Foo { const ASSOC_CONST: u32 = 0; } | ||
1016 | const GLOBAL_CONST: u32 = 101; | ||
1017 | fn test() { | ||
1018 | const LOCAL_CONST: u32 = 99; | ||
1019 | let x = LOCAL_CONST; | ||
1020 | let z = GLOBAL_CONST; | ||
1021 | let id = Foo::ASSOC_CONST; | ||
1022 | } | ||
1023 | "#, | ||
1024 | ); | ||
1025 | } | ||
1026 | |||
1027 | #[test] | ||
1028 | fn infer_static() { | ||
1029 | check_inference( | ||
1030 | "infer_static", | ||
1031 | r#" | ||
1032 | static GLOBAL_STATIC: u32 = 101; | ||
1033 | static mut GLOBAL_STATIC_MUT: u32 = 101; | ||
1034 | fn test() { | ||
1035 | static LOCAL_STATIC: u32 = 99; | ||
1036 | static mut LOCAL_STATIC_MUT: u32 = 99; | ||
1037 | let x = LOCAL_STATIC; | ||
1038 | let y = LOCAL_STATIC_MUT; | ||
1039 | let z = GLOBAL_STATIC; | ||
1040 | let w = GLOBAL_STATIC_MUT; | ||
1041 | } | ||
1042 | "#, | ||
1043 | ); | ||
1044 | } | ||
1045 | |||
1009 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | 1046 | fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { |
1010 | let func = source_binder::function_from_position(db, pos).unwrap(); | 1047 | let func = source_binder::function_from_position(db, pos).unwrap(); |
1011 | let body_syntax_mapping = func.body_syntax_mapping(db); | 1048 | let body_syntax_mapping = func.body_syntax_mapping(db); |