From e51d44a2de36fd6e451a3aaf96c7526c589c2c42 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Mon, 7 Jan 2019 20:43:41 +0100 Subject: Process explicit type hints for str, bool and char --- crates/ra_hir/src/name.rs | 7 +++++++ crates/ra_hir/src/ty.rs | 8 +++++++- crates/ra_hir/src/ty/tests/data/basics.txt | 4 ++-- crates/ra_hir/src/ty/tests/data/binary_op.txt | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir/src') 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 { "u128" => KnownName::U128, "f32" => KnownName::F32, "f64" => KnownName::F64, + "bool" => KnownName::Bool, + "char" => KnownName::Char, + "str" => KnownName::Str, "Self" => KnownName::SelfType, "self" => KnownName::SelfParam, _ => return None, @@ -113,6 +116,10 @@ pub(crate) enum KnownName { F32, F64, + Bool, + Char, + Str, + SelfType, SelfParam, } 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 { path: &Path, ) -> Cancelable { if let Some(name) = path.as_ident() { - if let Some(int_ty) = primitive::IntTy::from_name(name) { + if let Some(KnownName::Bool) = name.as_known_name() { + return Ok(Ty::Bool); + } else if let Some(KnownName::Char) = name.as_known_name() { + return Ok(Ty::Char); + } else if let Some(KnownName::Str) = name.as_known_name() { + return Ok(Ty::Str); + } else if let Some(int_ty) = primitive::IntTy::from_name(name) { return Ok(Ty::Int(int_ty)); } else if let Some(uint_ty) = primitive::UintTy::from_name(name) { 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 @@ [9; 10) 'a': u32 [17; 18) 'b': isize [27; 28) 'c': ! -[33; 34) 'd': &[unknown] +[33; 34) 'd': &str [42; 121) '{ ...f32; }': () [48; 49) 'a': u32 [55; 56) 'b': isize [62; 63) 'c': ! -[69; 70) 'd': &[unknown] +[69; 70) 'd': &str [76; 82) '1usize': [unknown] [88; 94) '1isize': [unknown] [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 @@ -[6; 7) 'x': [unknown] +[6; 7) 'x': bool [22; 34) '{ 0i32 }': i32 [28; 32) '0i32': i32 [46; 342) '{ ... < 3 }': bool @@ -22,7 +22,7 @@ [166; 188) 'minus_...ONST_2': bool [181; 188) 'CONST_2': isize [198; 199) 'c': i32 -[202; 203) 'f': fn([unknown],) -> i32 +[202; 203) 'f': fn(bool,) -> i32 [202; 211) 'f(z || y)': i32 [202; 215) 'f(z || y) + 5': i32 [204; 205) 'z': bool -- cgit v1.2.3