Skip to content

Commit 3d9d10b

Browse files
committed
fix: use placeholder as default type in Extract into function.
1 parent a6c650e commit 3d9d10b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

crates/ide_assists/src/handlers/extract_function.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,23 +1319,23 @@ impl Function {
13191319
.type_arguments()
13201320
.nth(1)
13211321
.map(|ty| make_ty(&ty, ctx, module))
1322-
.unwrap_or_else(make::ty_unit);
1322+
.unwrap_or_else(make::ty_placeholder);
13231323
make::ext::ty_result(fun_ty.make_ty(ctx, module), handler_ty)
13241324
}
13251325
FlowHandler::If { .. } => make::ext::ty_bool(),
13261326
FlowHandler::IfOption { action } => {
13271327
let handler_ty = action
13281328
.expr_ty(ctx)
13291329
.map(|ty| make_ty(&ty, ctx, module))
1330-
.unwrap_or_else(make::ty_unit);
1330+
.unwrap_or_else(make::ty_placeholder);
13311331
make::ext::ty_option(handler_ty)
13321332
}
13331333
FlowHandler::MatchOption { .. } => make::ext::ty_option(fun_ty.make_ty(ctx, module)),
13341334
FlowHandler::MatchResult { err } => {
13351335
let handler_ty = err
13361336
.expr_ty(ctx)
13371337
.map(|ty| make_ty(&ty, ctx, module))
1338-
.unwrap_or_else(make::ty_unit);
1338+
.unwrap_or_else(make::ty_placeholder);
13391339
make::ext::ty_result(fun_ty.make_ty(ctx, module), handler_ty)
13401340
}
13411341
};
@@ -1501,7 +1501,7 @@ fn with_tail_expr(block: ast::BlockExpr, tail_expr: ast::Expr) -> ast::BlockExpr
15011501
}
15021502

15031503
fn format_type(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> String {
1504-
ty.display_source_code(ctx.db(), module.into()).ok().unwrap_or_else(|| "()".to_string())
1504+
ty.display_source_code(ctx.db(), module.into()).ok().unwrap_or_else(|| "_".to_string())
15051505
}
15061506

15071507
fn make_ty(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> ast::Type {
@@ -4191,6 +4191,29 @@ fn main() {
41914191
fn $0fun_name(bar: &str) {
41924192
m!(bar);
41934193
}
4194+
"#,
4195+
);
4196+
}
4197+
4198+
#[test]
4199+
fn unresolveable_types_default_to_placeholder() {
4200+
check_assist(
4201+
extract_function,
4202+
r#"
4203+
fn foo() {
4204+
let a = __unresolved;
4205+
let _ = $0{a}$0;
4206+
}
4207+
"#,
4208+
r#"
4209+
fn foo() {
4210+
let a = __unresolved;
4211+
let _ = fun_name(a);
4212+
}
4213+
4214+
fn $0fun_name(a: _) -> _ {
4215+
a
4216+
}
41944217
"#,
41954218
);
41964219
}

0 commit comments

Comments
 (0)