Unnamed repository; edit this file 'description' to name the repository.
fix: use placeholder as default type in `Extract into function`.
Dawer 2021-09-04
parent a6c650e · commit 3d9d10b
-rw-r--r--crates/ide_assists/src/handlers/extract_function.rs31
1 files changed, 27 insertions, 4 deletions
diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs
index 192403b15d..1e21050911 100644
--- a/crates/ide_assists/src/handlers/extract_function.rs
+++ b/crates/ide_assists/src/handlers/extract_function.rs
@@ -1319,7 +1319,7 @@ impl Function {
.type_arguments()
.nth(1)
.map(|ty| make_ty(&ty, ctx, module))
- .unwrap_or_else(make::ty_unit);
+ .unwrap_or_else(make::ty_placeholder);
make::ext::ty_result(fun_ty.make_ty(ctx, module), handler_ty)
}
FlowHandler::If { .. } => make::ext::ty_bool(),
@@ -1327,7 +1327,7 @@ impl Function {
let handler_ty = action
.expr_ty(ctx)
.map(|ty| make_ty(&ty, ctx, module))
- .unwrap_or_else(make::ty_unit);
+ .unwrap_or_else(make::ty_placeholder);
make::ext::ty_option(handler_ty)
}
FlowHandler::MatchOption { .. } => make::ext::ty_option(fun_ty.make_ty(ctx, module)),
@@ -1335,7 +1335,7 @@ impl Function {
let handler_ty = err
.expr_ty(ctx)
.map(|ty| make_ty(&ty, ctx, module))
- .unwrap_or_else(make::ty_unit);
+ .unwrap_or_else(make::ty_placeholder);
make::ext::ty_result(fun_ty.make_ty(ctx, module), handler_ty)
}
};
@@ -1501,7 +1501,7 @@ fn with_tail_expr(block: ast::BlockExpr, tail_expr: ast::Expr) -> ast::BlockExpr
}
fn format_type(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> String {
- ty.display_source_code(ctx.db(), module.into()).ok().unwrap_or_else(|| "()".to_string())
+ ty.display_source_code(ctx.db(), module.into()).ok().unwrap_or_else(|| "_".to_string())
}
fn make_ty(ty: &hir::Type, ctx: &AssistContext, module: hir::Module) -> ast::Type {
@@ -4194,4 +4194,27 @@ fn $0fun_name(bar: &str) {
"#,
);
}
+
+ #[test]
+ fn unresolveable_types_default_to_placeholder() {
+ check_assist(
+ extract_function,
+ r#"
+fn foo() {
+ let a = __unresolved;
+ let _ = $0{a}$0;
+}
+"#,
+ r#"
+fn foo() {
+ let a = __unresolved;
+ let _ = fun_name(a);
+}
+
+fn $0fun_name(a: _) -> _ {
+ a
+}
+"#,
+ );
+ }
}