aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-07 21:00:19 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-07 21:00:19 +0000
commit4e444d2bc24d16284401444fd2154f63e0f96070 (patch)
tree969f3cb2b0eb5cb62f384fd85a5422d894d4e978 /crates/ra_hir
parent812e47785b4f14a961f97414d0ca69d8c9bf5c9c (diff)
parente51d44a2de36fd6e451a3aaf96c7526c589c2c42 (diff)
Merge #452
452: Process explicit type hints for str, bool and char r=flodiebold a=marcusklaas Co-authored-by: Marcus Klaas de Vries <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/name.rs7
-rw-r--r--crates/ra_hir/src/ty.rs8
-rw-r--r--crates/ra_hir/src/ty/tests/data/basics.txt4
-rw-r--r--crates/ra_hir/src/ty/tests/data/binary_op.txt4
4 files changed, 18 insertions, 5 deletions
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs
index 90229bc54..599285346 100644
--- a/crates/ra_hir/src/name.rs
+++ b/crates/ra_hir/src/name.rs
@@ -59,6 +59,9 @@ impl Name {
59 "u128" => KnownName::U128, 59 "u128" => KnownName::U128,
60 "f32" => KnownName::F32, 60 "f32" => KnownName::F32,
61 "f64" => KnownName::F64, 61 "f64" => KnownName::F64,
62 "bool" => KnownName::Bool,
63 "char" => KnownName::Char,
64 "str" => KnownName::Str,
62 "Self" => KnownName::SelfType, 65 "Self" => KnownName::SelfType,
63 "self" => KnownName::SelfParam, 66 "self" => KnownName::SelfParam,
64 _ => return None, 67 _ => return None,
@@ -113,6 +116,10 @@ pub(crate) enum KnownName {
113 F32, 116 F32,
114 F64, 117 F64,
115 118
119 Bool,
120 Char,
121 Str,
122
116 SelfType, 123 SelfType,
117 SelfParam, 124 SelfParam,
118} 125}
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 7827e82c4..8adeedddb 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -308,7 +308,13 @@ impl Ty {
308 path: &Path, 308 path: &Path,
309 ) -> Cancelable<Self> { 309 ) -> Cancelable<Self> {
310 if let Some(name) = path.as_ident() { 310 if let Some(name) = path.as_ident() {
311 if let Some(int_ty) = primitive::IntTy::from_name(name) { 311 if let Some(KnownName::Bool) = name.as_known_name() {
312 return Ok(Ty::Bool);
313 } else if let Some(KnownName::Char) = name.as_known_name() {
314 return Ok(Ty::Char);
315 } else if let Some(KnownName::Str) = name.as_known_name() {
316 return Ok(Ty::Str);
317 } else if let Some(int_ty) = primitive::IntTy::from_name(name) {
312 return Ok(Ty::Int(int_ty)); 318 return Ok(Ty::Int(int_ty));
313 } else if let Some(uint_ty) = primitive::UintTy::from_name(name) { 319 } else if let Some(uint_ty) = primitive::UintTy::from_name(name) {
314 return Ok(Ty::Uint(uint_ty)); 320 return Ok(Ty::Uint(uint_ty));
diff --git a/crates/ra_hir/src/ty/tests/data/basics.txt b/crates/ra_hir/src/ty/tests/data/basics.txt
index 8ea244ba8..ac7faae0a 100644
--- a/crates/ra_hir/src/ty/tests/data/basics.txt
+++ b/crates/ra_hir/src/ty/tests/data/basics.txt
@@ -1,12 +1,12 @@
1[9; 10) 'a': u32 1[9; 10) 'a': u32
2[17; 18) 'b': isize 2[17; 18) 'b': isize
3[27; 28) 'c': ! 3[27; 28) 'c': !
4[33; 34) 'd': &[unknown] 4[33; 34) 'd': &str
5[42; 121) '{ ...f32; }': () 5[42; 121) '{ ...f32; }': ()
6[48; 49) 'a': u32 6[48; 49) 'a': u32
7[55; 56) 'b': isize 7[55; 56) 'b': isize
8[62; 63) 'c': ! 8[62; 63) 'c': !
9[69; 70) 'd': &[unknown] 9[69; 70) 'd': &str
10[76; 82) '1usize': [unknown] 10[76; 82) '1usize': [unknown]
11[88; 94) '1isize': [unknown] 11[88; 94) '1isize': [unknown]
12[100; 106) '"test"': [unknown] 12[100; 106) '"test"': [unknown]
diff --git a/crates/ra_hir/src/ty/tests/data/binary_op.txt b/crates/ra_hir/src/ty/tests/data/binary_op.txt
index 59c07ff43..0fb9dc097 100644
--- a/crates/ra_hir/src/ty/tests/data/binary_op.txt
+++ b/crates/ra_hir/src/ty/tests/data/binary_op.txt
@@ -1,4 +1,4 @@
1[6; 7) 'x': [unknown] 1[6; 7) 'x': bool
2[22; 34) '{ 0i32 }': i32 2[22; 34) '{ 0i32 }': i32
3[28; 32) '0i32': i32 3[28; 32) '0i32': i32
4[46; 342) '{ ... < 3 }': bool 4[46; 342) '{ ... < 3 }': bool
@@ -22,7 +22,7 @@
22[166; 188) 'minus_...ONST_2': bool 22[166; 188) 'minus_...ONST_2': bool
23[181; 188) 'CONST_2': isize 23[181; 188) 'CONST_2': isize
24[198; 199) 'c': i32 24[198; 199) 'c': i32
25[202; 203) 'f': fn([unknown],) -> i32 25[202; 203) 'f': fn(bool,) -> i32
26[202; 211) 'f(z || y)': i32 26[202; 211) 'f(z || y)': i32
27[202; 215) 'f(z || y) + 5': i32 27[202; 215) 'f(z || y) + 5': i32
28[204; 205) 'z': bool 28[204; 205) 'z': bool