From 18b0bd9bffeeeaf664f4a21894d5bfff51e82b32 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Mon, 25 Feb 2019 09:27:47 +0200 Subject: Add const type inference --- crates/ra_hir/src/ty/tests.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'crates/ra_hir/src/ty/tests.rs') 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 { assert_eq!("i128", type_at_pos(&db, pos)); } +#[test] +fn infer_const() { + check_inference( + "infer_const", + r#" +struct Foo; +impl Foo { const ASSOC_CONST: u32 = 0; } +const GLOBAL_CONST: u32 = 101; +fn test() { + const LOCAL_CONST: u32 = 99; + let x = LOCAL_CONST; + let z = GLOBAL_CONST; + let id = Foo::ASSOC_CONST; +} +"#, + ); +} + +#[test] +fn infer_static() { + check_inference( + "infer_static", + r#" +static GLOBAL_STATIC: u32 = 101; +static mut GLOBAL_STATIC_MUT: u32 = 101; +fn test() { + static LOCAL_STATIC: u32 = 99; + static mut LOCAL_STATIC_MUT: u32 = 99; + let x = LOCAL_STATIC; + let y = LOCAL_STATIC_MUT; + let z = GLOBAL_STATIC; + let w = GLOBAL_STATIC_MUT; +} +"#, + ); +} + fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { let func = source_binder::function_from_position(db, pos).unwrap(); let body_syntax_mapping = func.body_syntax_mapping(db); -- cgit v1.2.3