mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 05:57:03 +03:00
Type the return values of call expressions
This commit is contained in:
+11
-3
@@ -211,7 +211,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
}
|
||||
|
||||
pub fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
|
||||
eprintln!("type_for_fn {:?}", f.fn_id);
|
||||
let syntax = f.syntax(db);
|
||||
let node = syntax.borrowed();
|
||||
// TODO we ignore type parameters for now
|
||||
@@ -397,7 +396,7 @@ fn infer_expr(&mut self, expr: ast::Expr) -> Cancelable<Ty> {
|
||||
Ty::Unknown
|
||||
}
|
||||
ast::Expr::CallExpr(e) => {
|
||||
let _callee_ty = if let Some(e) = e.expr() {
|
||||
let callee_ty = if let Some(e) = e.expr() {
|
||||
self.infer_expr(e)?
|
||||
} else {
|
||||
Ty::Unknown
|
||||
@@ -408,7 +407,16 @@ fn infer_expr(&mut self, expr: ast::Expr) -> Cancelable<Ty> {
|
||||
self.infer_expr(arg)?;
|
||||
}
|
||||
}
|
||||
Ty::Unknown
|
||||
match callee_ty {
|
||||
Ty::FnPtr(sig) => {
|
||||
sig.output.clone()
|
||||
}
|
||||
_ => {
|
||||
// not callable
|
||||
// TODO report an error?
|
||||
Ty::Unknown
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::Expr::MethodCallExpr(e) => {
|
||||
let _receiver_ty = if let Some(e) = e.expr() {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
[14; 19) '{ 1 }': [unknown]
|
||||
[47; 52) '{ 1 }': [unknown]
|
||||
[49; 50) '1': [unknown]
|
||||
[81; 87) 'b::c()': [unknown]
|
||||
[81; 87) 'b::c()': u32
|
||||
[66; 90) '{ ...c(); }': ()
|
||||
[72; 73) 'a': fn() -> u32
|
||||
[72; 75) 'a()': [unknown]
|
||||
[72; 75) 'a()': u32
|
||||
[81; 85) 'b::c': fn() -> u32
|
||||
|
||||
Reference in New Issue
Block a user