From b1590bdf6a88c03e2aeeedbe04f4dbc4203073db Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 29 Dec 2018 12:08:57 +0100 Subject: Missing return type means unit, not unknown --- crates/ra_hir/src/ty.rs | 6 +++++- crates/ra_hir/src/ty/tests/data/0006_backwards.txt | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 0592e4a63..4ebd44d27 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -381,7 +381,11 @@ pub fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable { .collect() }) .unwrap_or_else(|| Ok(Vec::new()))?; - let output = Ty::from_ast_opt(db, &module, node.ret_type().and_then(|rt| rt.type_ref()))?; + let output = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) { + Ty::from_ast(db, &module, type_ref)? + } else { + Ty::unit() + }; let sig = FnSig { input, output }; Ok(Ty::FnPtr(Arc::new(sig))) } diff --git a/crates/ra_hir/src/ty/tests/data/0006_backwards.txt b/crates/ra_hir/src/ty/tests/data/0006_backwards.txt index 3a12aeef4..120069401 100644 --- a/crates/ra_hir/src/ty/tests/data/0006_backwards.txt +++ b/crates/ra_hir/src/ty/tests/data/0006_backwards.txt @@ -11,10 +11,10 @@ [92; 110) 'unknow...tion()': u32 [142; 160) 'unknow...tion()': i32 [92; 108) 'unknow...nction': [unknown] -[116; 128) 'takes_u32(a)': [unknown] +[116; 128) 'takes_u32(a)': () [78; 231) '{ ...t &c }': &mut &f64 [227; 229) '&c': &f64 [88; 89) 'a': u32 [181; 182) 'b': i32 -[116; 125) 'takes_u32': fn(u32,) -> [unknown] +[116; 125) 'takes_u32': fn(u32,) -> () [138; 139) 'b': i32 -- cgit v1.2.3