diff options
author | Florian Diebold <[email protected]> | 2018-12-23 11:59:38 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2018-12-23 12:48:04 +0000 |
commit | 5d609370900402db84beb3d7e28487256c6042c2 (patch) | |
tree | adcb5a083155e8230955f6784fb0929626e32509 /crates/ra_hir/src | |
parent | b4139d54fc68240aa8e4e221841298115d8fb00f (diff) |
Remove unwraps
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 1d5473d17..eb5fea153 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -479,17 +479,30 @@ impl InferenceContext { | |||
479 | pub fn infer(_db: &impl HirDatabase, node: ast::FnDef, scopes: Arc<FnScopes>) -> InferenceResult { | 479 | pub fn infer(_db: &impl HirDatabase, node: ast::FnDef, scopes: Arc<FnScopes>) -> InferenceResult { |
480 | let mut ctx = InferenceContext::new(scopes); | 480 | let mut ctx = InferenceContext::new(scopes); |
481 | 481 | ||
482 | for param in node.param_list().unwrap().params() { | 482 | if let Some(param_list) = node.param_list() { |
483 | let pat = param.pat().unwrap(); | 483 | for param in param_list.params() { |
484 | let type_ref = param.type_ref().unwrap(); | 484 | let pat = if let Some(pat) = param.pat() { |
485 | let ty = Ty::new(type_ref); | 485 | pat |
486 | ctx.type_for.insert(LocalSyntaxPtr::new(pat.syntax()), ty); | 486 | } else { |
487 | continue; | ||
488 | }; | ||
489 | if let Some(type_ref) = param.type_ref() { | ||
490 | let ty = Ty::new(type_ref); | ||
491 | ctx.type_for.insert(LocalSyntaxPtr::new(pat.syntax()), ty); | ||
492 | } else { | ||
493 | // TODO self param | ||
494 | ctx.type_for | ||
495 | .insert(LocalSyntaxPtr::new(pat.syntax()), Ty::Unknown); | ||
496 | }; | ||
497 | } | ||
487 | } | 498 | } |
488 | 499 | ||
489 | // TODO get Ty for node.ret_type() and pass that to infer_block as expectation | 500 | // TODO get Ty for node.ret_type() and pass that to infer_block as expectation |
490 | // (see Expectation in rustc_typeck) | 501 | // (see Expectation in rustc_typeck) |
491 | 502 | ||
492 | ctx.infer_block(node.body().unwrap()); | 503 | if let Some(block) = node.body() { |
504 | ctx.infer_block(block); | ||
505 | } | ||
493 | 506 | ||
494 | // TODO 'resolve' the types: replace inference variables by their inferred results | 507 | // TODO 'resolve' the types: replace inference variables by their inferred results |
495 | 508 | ||