]> git.lizzy.rs Git - rust.git/commitdiff
Remove unwraps
authorFlorian Diebold <flodiebold@gmail.com>
Sun, 23 Dec 2018 11:59:38 +0000 (12:59 +0100)
committerFlorian Diebold <flodiebold@gmail.com>
Sun, 23 Dec 2018 12:48:04 +0000 (13:48 +0100)
crates/ra_hir/src/ty.rs

index 1d5473d17aeda28b9fee16f482229e18924525c7..eb5fea1532480bf0e2821678ac570c8b9532232c 100644 (file)
@@ -479,17 +479,30 @@ fn infer_block(&mut self, node: ast::Block) -> Ty {
 pub fn infer(_db: &impl HirDatabase, node: ast::FnDef, scopes: Arc<FnScopes>) -> InferenceResult {
     let mut ctx = InferenceContext::new(scopes);
 
-    for param in node.param_list().unwrap().params() {
-        let pat = param.pat().unwrap();
-        let type_ref = param.type_ref().unwrap();
-        let ty = Ty::new(type_ref);
-        ctx.type_for.insert(LocalSyntaxPtr::new(pat.syntax()), ty);
+    if let Some(param_list) = node.param_list() {
+        for param in param_list.params() {
+            let pat = if let Some(pat) = param.pat() {
+                pat
+            } else {
+                continue;
+            };
+            if let Some(type_ref) = param.type_ref() {
+                let ty = Ty::new(type_ref);
+                ctx.type_for.insert(LocalSyntaxPtr::new(pat.syntax()), ty);
+            } else {
+                // TODO self param
+                ctx.type_for
+                    .insert(LocalSyntaxPtr::new(pat.syntax()), Ty::Unknown);
+            };
+        }
     }
 
     // TODO get Ty for node.ret_type() and pass that to infer_block as expectation
     // (see Expectation in rustc_typeck)
 
-    ctx.infer_block(node.body().unwrap());
+    if let Some(block) = node.body() {
+        ctx.infer_block(block);
+    }
 
     // TODO 'resolve' the types: replace inference variables by their inferred results