@@ -3,9 +3,10 @@ use crate::utils::paths;
33use crate :: utils:: sugg:: Sugg ;
44use crate :: utils:: usage:: is_unused;
55use 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,
910} ;
1011use if_chain:: if_chain;
1112use rustc:: lint:: in_external_macro;
@@ -928,14 +929,27 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms:
928929 ) ,
929930 )
930931 } 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+ } ;
931943 (
932944 expr. span ,
933945 format ! (
934- "let {} = {};\n {}{}" ,
946+ "{}let {} = {};\n {}{}{}" ,
947+ cbrace_start,
935948 snippet_with_applicability( cx, bind_names, ".." , & mut applicability) ,
936949 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
939953 ) ,
940954 )
941955 } ;
0 commit comments