From a2b6d3da30020421c97100d7c8699a3b4f8cd6fb Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Mon, 14 Jan 2019 23:15:16 +0100 Subject: Implement rudimentary type inference for unary operators --- crates/ra_hir/src/ty/tests.rs | 23 +++++++++++++++++++++++ crates/ra_hir/src/ty/tests/data/unary_op.txt | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 crates/ra_hir/src/ty/tests/data/unary_op.txt (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 929fee04c..5d7bc25cc 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -158,6 +158,29 @@ fn test() { ); } +#[test] +fn infer_unary_op() { + check_inference( + r#" +enum SomeType {} + +fn test(x: SomeType) { + let b = false; + let c = !b; + let a = 100; + let d: i128 = -a; + let e = -100; + let f = !!!true; + -3.14; + -x; + !x; + -"hello"; +} +"#, + "unary_op.txt", + ); +} + #[test] fn infer_backwards() { check_inference( diff --git a/crates/ra_hir/src/ty/tests/data/unary_op.txt b/crates/ra_hir/src/ty/tests/data/unary_op.txt new file mode 100644 index 000000000..203022e82 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/unary_op.txt @@ -0,0 +1,28 @@ +[27; 28) 'x': SomeType +[40; 197) '{ ...lo"; }': () +[50; 51) 'b': bool +[54; 59) 'false': bool +[69; 70) 'c': bool +[73; 75) '!b': bool +[74; 75) 'b': bool +[85; 86) 'a': i128 +[89; 92) '100': i128 +[102; 103) 'd': i128 +[112; 114) '-a': i128 +[113; 114) 'a': i128 +[124; 125) 'e': i32 +[128; 132) '-100': i32 +[129; 132) '100': i32 +[142; 143) 'f': bool +[146; 153) '!!!true': bool +[147; 153) '!!true': bool +[148; 153) '!true': bool +[149; 153) 'true': bool +[159; 164) '-3.14': f64 +[160; 164) '3.14': f64 +[170; 172) '-x': [unknown] +[171; 172) 'x': SomeType +[178; 180) '!x': [unknown] +[179; 180) 'x': SomeType +[186; 194) '-"hello"': [unknown] +[187; 194) '"hello"': &str -- cgit v1.2.3