@@ -3,9 +3,10 @@ use crate::utils::paths;
3
3
use crate :: utils:: sugg:: Sugg ;
4
4
use crate :: utils:: usage:: is_unused;
5
5
use crate :: utils:: {
6
- expr_block, get_arg_name, in_macro, indent_of, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath,
7
- match_type, match_var, multispan_sugg, remove_blocks, snippet, snippet_block, snippet_with_applicability,
8
- span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, walk_ptrs_ty,
6
+ expr_block, get_arg_name, get_parent_expr, in_macro, indent_of, is_allowed, is_expn_of, is_refutable, is_wild,
7
+ match_qpath, match_type, match_var, multispan_sugg, remove_blocks, snippet, snippet_block,
8
+ snippet_with_applicability, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then,
9
+ walk_ptrs_ty,
9
10
} ;
10
11
use if_chain:: if_chain;
11
12
use rustc:: lint:: in_external_macro;
@@ -928,14 +929,27 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms:
928
929
) ,
929
930
)
930
931
} else {
932
+ // If we are in closure, we need curly braces around suggestion
933
+ let mut indent = " " . repeat ( indent_of ( cx, ex. span ) . unwrap_or ( 0 ) ) ;
934
+ let ( mut cbrace_start, mut cbrace_end) = ( "" . to_string ( ) , "" . to_string ( ) ) ;
935
+ if let Some ( parent_expr) = get_parent_expr ( cx, expr) {
936
+ if let ExprKind :: Closure ( ..) = parent_expr. kind {
937
+ cbrace_end = format ! ( "\n {}}}" , indent) ;
938
+ // Fix body indent due to the closure
939
+ indent = " " . repeat ( indent_of ( cx, bind_names) . unwrap_or ( 0 ) ) ;
940
+ cbrace_start = format ! ( "{{\n {}" , indent) ;
941
+ }
942
+ } ;
931
943
(
932
944
expr. span ,
933
945
format ! (
934
- "let {} = {};\n {}{}" ,
946
+ "{}let {} = {};\n {}{}{}" ,
947
+ cbrace_start,
935
948
snippet_with_applicability( cx, bind_names, ".." , & mut applicability) ,
936
949
snippet_with_applicability( cx, matched_vars, ".." , & mut applicability) ,
937
- " " . repeat( indent_of( cx, expr. span) . unwrap_or( 0 ) ) ,
938
- snippet_body
950
+ indent,
951
+ snippet_body,
952
+ cbrace_end
939
953
) ,
940
954
)
941
955
} ;
0 commit comments