452: Process explicit type hints for str, bool and char r=flodiebold a=marcusklaas



Co-authored-by: Marcus Klaas de Vries <mail@marcusklaas.nl>
This commit is contained in:
bors[bot] 2019-01-07 21:00:19 +00:00
commit 4e444d2bc2
4 changed files with 18 additions and 5 deletions

View File

@ -59,6 +59,9 @@ pub(crate) fn as_known_name(&self) -> Option<KnownName> {
"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,
}

View File

@ -308,7 +308,13 @@ pub(crate) fn from_hir_path(
path: &Path,
) -> Cancelable<Self> {
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));

View File

@ -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]

View File

@ -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