diff options
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/add_explicit_type.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/crates/ra_assists/src/add_explicit_type.rs b/crates/ra_assists/src/add_explicit_type.rs index dec4f68ee..1dc59bb87 100644 --- a/crates/ra_assists/src/add_explicit_type.rs +++ b/crates/ra_assists/src/add_explicit_type.rs | |||
@@ -18,9 +18,7 @@ pub(crate) fn add_explicit_type(mut ctx: AssistCtx<impl HirDatabase>) -> Option< | |||
18 | // Must be a binding | 18 | // Must be a binding |
19 | let pat = match pat.kind() { | 19 | let pat = match pat.kind() { |
20 | PatKind::BindPat(bind_pat) => bind_pat, | 20 | PatKind::BindPat(bind_pat) => bind_pat, |
21 | _ => { | 21 | _ => return None, |
22 | return None; | ||
23 | } | ||
24 | }; | 22 | }; |
25 | let pat_range = pat.syntax().range(); | 23 | let pat_range = pat.syntax().range(); |
26 | // The binding must have a name | 24 | // The binding must have a name |
@@ -31,20 +29,20 @@ pub(crate) fn add_explicit_type(mut ctx: AssistCtx<impl HirDatabase>) -> Option< | |||
31 | return None; | 29 | return None; |
32 | } | 30 | } |
33 | // Infer type | 31 | // Infer type |
34 | let func = function_from_child_node(ctx.db, ctx.frange.file_id, pat.syntax())?; | 32 | let db = ctx.db; |
35 | let inference_res = func.infer(ctx.db); | 33 | let func = function_from_child_node(db, ctx.frange.file_id, pat.syntax())?; |
36 | let source_map = func.body_source_map(ctx.db); | 34 | let inference_res = func.infer(db); |
35 | let source_map = func.body_source_map(db); | ||
37 | let expr_id = source_map.node_expr(expr.into())?; | 36 | let expr_id = source_map.node_expr(expr.into())?; |
38 | let ty = inference_res[expr_id].clone(); | 37 | let ty = inference_res[expr_id].clone(); |
39 | // Assist not applicable if the type is unknown | 38 | // Assist not applicable if the type is unknown |
40 | if is_unknown(&ty) { | 39 | if is_unknown(&ty) { |
41 | return None; | 40 | return None; |
42 | } | 41 | } |
43 | let ty_str = ty.display(ctx.db).to_string(); | ||
44 | 42 | ||
45 | ctx.add_action(AssistId("add_explicit_type"), "add explicit type", |edit| { | 43 | ctx.add_action(AssistId("add_explicit_type"), "add explicit type", |edit| { |
46 | edit.target(pat_range); | 44 | edit.target(pat_range); |
47 | edit.insert(name_range.end(), format!(": {}", ty_str)); | 45 | edit.insert(name_range.end(), format!(": {}", ty.display(db))); |
48 | }); | 46 | }); |
49 | ctx.build() | 47 | ctx.build() |
50 | } | 48 | } |