Skip to content

Commit 31ffd29

Browse files
authored
Merge pull request rust-lang#20816 from A4-Tacks/add-ret-ty-adjusted
Fix closure coerced return type for add_return_type
2 parents d8b67b0 + cd77365 commit 31ffd29

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_return_type.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{AssistContext, AssistId, Assists};
1818
pub(crate) fn add_return_type(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
1919
let (fn_type, tail_expr, builder_edit_pos) = extract_tail(ctx)?;
2020
let module = ctx.sema.scope(tail_expr.syntax())?.module();
21-
let ty = ctx.sema.type_of_expr(&peel_blocks(tail_expr.clone()))?.original();
21+
let ty = ctx.sema.type_of_expr(&peel_blocks(tail_expr.clone()))?.adjusted();
2222
if ty.is_unit() {
2323
return None;
2424
}
@@ -421,6 +421,21 @@ mod tests {
421421
);
422422
}
423423

424+
#[test]
425+
fn infer_coerced_return_type_closure() {
426+
check_assist(
427+
add_return_type,
428+
r#"fn foo() {
429+
let f = ||$0 {loop {}};
430+
let _: fn() -> i8 = f;
431+
}"#,
432+
r#"fn foo() {
433+
let f = || -> i8 {loop {}};
434+
let _: fn() -> i8 = f;
435+
}"#,
436+
);
437+
}
438+
424439
#[test]
425440
fn not_applicable_ret_type_specified_closure() {
426441
cov_mark::check!(existing_ret_type_closure);

0 commit comments

Comments
 (0)