diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-28 20:43:13 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-28 20:43:13 +0000 |
commit | 48d2acb297459fb06cbb49bdce2eccb4c2591714 (patch) | |
tree | 8f447c656a44f77a512f8b02d505619895b79bfc /crates/ra_hir | |
parent | a238cb519a96642ab03ff989783bbee5149f9334 (diff) | |
parent | ec32b2e39cb95fc1a9015379de6fe71f230c873d (diff) |
Merge #698
698: Added support for primitive types type inference with std::ops::Not r=flodiebold a=WizardOfMenlo
On the guideline of #544 , this allows for type inference for all primitive types implementing [std::ops::Not](https://doc.rust-lang.org/beta/std/ops/trait.Not.html). I think this should be relevant #394 as well?
Co-authored-by: WizardOfMenlo <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap | 37 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 5 |
3 files changed, 37 insertions, 15 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 37715a903..7a5485698 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -1588,9 +1588,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1588 | _ => Ty::Unknown, | 1588 | _ => Ty::Unknown, |
1589 | } | 1589 | } |
1590 | } | 1590 | } |
1591 | UnaryOp::Not if inner_ty == Ty::Bool => Ty::Bool, | 1591 | UnaryOp::Not => { |
1592 | // TODO: resolve ops::Not trait for inner_ty | 1592 | match inner_ty { |
1593 | UnaryOp::Not => Ty::Unknown, | 1593 | Ty::Bool | Ty::Int(_) | Ty::Infer(InferTy::IntVar(..)) => inner_ty, |
1594 | // TODO: resolve ops::Not trait for inner_ty | ||
1595 | _ => Ty::Unknown, | ||
1596 | } | ||
1597 | } | ||
1594 | } | 1598 | } |
1595 | } | 1599 | } |
1596 | Expr::BinaryOp { lhs, rhs, op } => match op { | 1600 | Expr::BinaryOp { lhs, rhs, op } => match op { |
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap index 10aa61954..5021d0eeb 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_unary_op.snap | |||
@@ -1,11 +1,11 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-22T14:45:00.059676600+00:00" | 2 | created: "2019-01-28T14:51:16.185273502+00:00" |
3 | creator: insta@0.4.0 | 3 | creator: insta@0.5.2 |
4 | expression: "&result" | 4 | expression: "&result" |
5 | source: "crates\\ra_hir\\src\\ty\\tests.rs" | 5 | source: crates/ra_hir/src/ty/tests.rs |
6 | --- | 6 | --- |
7 | [27; 28) 'x': SomeType | 7 | [27; 28) 'x': SomeType |
8 | [40; 197) '{ ...lo"; }': () | 8 | [40; 272) '{ ...lo"; }': () |
9 | [50; 51) 'b': bool | 9 | [50; 51) 'b': bool |
10 | [54; 59) 'false': bool | 10 | [54; 59) 'false': bool |
11 | [69; 70) 'c': bool | 11 | [69; 70) 'c': bool |
@@ -24,12 +24,25 @@ source: "crates\\ra_hir\\src\\ty\\tests.rs" | |||
24 | [147; 153) '!!true': bool | 24 | [147; 153) '!!true': bool |
25 | [148; 153) '!true': bool | 25 | [148; 153) '!true': bool |
26 | [149; 153) 'true': bool | 26 | [149; 153) 'true': bool |
27 | [159; 164) '-3.14': f64 | 27 | [163; 164) 'g': i32 |
28 | [160; 164) '3.14': f64 | 28 | [167; 170) '!42': i32 |
29 | [170; 172) '-x': [unknown] | 29 | [168; 170) '42': i32 |
30 | [171; 172) 'x': SomeType | 30 | [180; 181) 'h': u32 |
31 | [178; 180) '!x': [unknown] | 31 | [184; 190) '!10u32': u32 |
32 | [179; 180) 'x': SomeType | 32 | [185; 190) '10u32': u32 |
33 | [186; 194) '-"hello"': [unknown] | 33 | [200; 201) 'j': i128 |
34 | [187; 194) '"hello"': &str | 34 | [204; 206) '!a': i128 |
35 | [205; 206) 'a': i128 | ||
36 | [212; 217) '-3.14': f64 | ||
37 | [213; 217) '3.14': f64 | ||
38 | [223; 225) '!3': i32 | ||
39 | [224; 225) '3': i32 | ||
40 | [231; 233) '-x': [unknown] | ||
41 | [232; 233) 'x': SomeType | ||
42 | [239; 241) '!x': [unknown] | ||
43 | [240; 241) 'x': SomeType | ||
44 | [247; 255) '-"hello"': [unknown] | ||
45 | [248; 255) '"hello"': &str | ||
46 | [261; 269) '!"hello"': [unknown] | ||
47 | [262; 269) '"hello"': &str | ||
35 | 48 | ||
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index ac12d974b..b36e6ec47 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -166,10 +166,15 @@ fn test(x: SomeType) { | |||
166 | let d: i128 = -a; | 166 | let d: i128 = -a; |
167 | let e = -100; | 167 | let e = -100; |
168 | let f = !!!true; | 168 | let f = !!!true; |
169 | let g = !42; | ||
170 | let h = !10u32; | ||
171 | let j = !a; | ||
169 | -3.14; | 172 | -3.14; |
173 | !3; | ||
170 | -x; | 174 | -x; |
171 | !x; | 175 | !x; |
172 | -"hello"; | 176 | -"hello"; |
177 | !"hello"; | ||
173 | } | 178 | } |
174 | "#, | 179 | "#, |
175 | ); | 180 | ); |