Missing return type means unit, not unknown

This commit is contained in:
Florian Diebold 2018-12-29 12:08:57 +01:00
parent cfa1de72eb
commit b1590bdf6a
2 changed files with 7 additions and 3 deletions

View File

@ -381,7 +381,11 @@ pub fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
.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)))
}

View File

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