Skip to content

Commit 48d2acb

Browse files
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]>
2 parents a238cb5 + ec32b2e commit 48d2acb

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

crates/ra_hir/src/ty.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,9 +1588,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
15881588
_ => Ty::Unknown,
15891589
}
15901590
}
1591-
UnaryOp::Not if inner_ty == Ty::Bool => Ty::Bool,
1592-
// TODO: resolve ops::Not trait for inner_ty
1593-
UnaryOp::Not => Ty::Unknown,
1591+
UnaryOp::Not => {
1592+
match inner_ty {
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+
}
15941598
}
15951599
}
15961600
Expr::BinaryOp { lhs, rhs, op } => match op {
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
created: "2019-01-22T14:45:00.059676600+00:00"
3-
creator: insta@0.4.0
2+
created: "2019-01-28T14:51:16.185273502+00:00"
3+
creator: insta@0.5.2
44
expression: "&result"
5-
source: "crates\\ra_hir\\src\\ty\\tests.rs"
5+
source: crates/ra_hir/src/ty/tests.rs
66
---
77
[27; 28) 'x': SomeType
8-
[40; 197) '{ ...lo"; }': ()
8+
[40; 272) '{ ...lo"; }': ()
99
[50; 51) 'b': bool
1010
[54; 59) 'false': bool
1111
[69; 70) 'c': bool
@@ -24,12 +24,25 @@ source: "crates\\ra_hir\\src\\ty\\tests.rs"
2424
[147; 153) '!!true': bool
2525
[148; 153) '!true': bool
2626
[149; 153) 'true': bool
27-
[159; 164) '-3.14': f64
28-
[160; 164) '3.14': f64
29-
[170; 172) '-x': [unknown]
30-
[171; 172) 'x': SomeType
31-
[178; 180) '!x': [unknown]
32-
[179; 180) 'x': SomeType
33-
[186; 194) '-"hello"': [unknown]
34-
[187; 194) '"hello"': &str
27+
[163; 164) 'g': i32
28+
[167; 170) '!42': i32
29+
[168; 170) '42': i32
30+
[180; 181) 'h': u32
31+
[184; 190) '!10u32': u32
32+
[185; 190) '10u32': u32
33+
[200; 201) 'j': i128
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
3548

crates/ra_hir/src/ty/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,15 @@ fn test(x: SomeType) {
166166
let d: i128 = -a;
167167
let e = -100;
168168
let f = !!!true;
169+
let g = !42;
170+
let h = !10u32;
171+
let j = !a;
169172
-3.14;
173+
!3;
170174
-x;
171175
!x;
172176
-"hello";
177+
!"hello";
173178
}
174179
"#,
175180
);

0 commit comments

Comments
 (0)