11use clippy_utils:: diagnostics:: span_lint_and_sugg;
22use clippy_utils:: macros:: HirNode ;
3- use clippy_utils:: source:: { indent_of, snippet, snippet_block_with_context, snippet_with_applicability } ;
3+ use clippy_utils:: source:: { indent_of, snippet, snippet_block_with_context, snippet_with_context } ;
44use clippy_utils:: { get_parent_expr, is_refutable, peel_blocks} ;
55use rustc_errors:: Applicability ;
66use rustc_hir:: { Arm , Expr , ExprKind , Node , PatKind , StmtKind } ;
@@ -24,16 +24,10 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
2424 let bind_names = arms[ 0 ] . pat . span ;
2525 let match_body = peel_blocks ( arms[ 0 ] . body ) ;
2626 let mut app = Applicability :: MaybeIncorrect ;
27- let mut snippet_body = snippet_block_with_context (
28- cx,
29- match_body. span ,
30- arms[ 0 ] . span . ctxt ( ) ,
31- ".." ,
32- Some ( expr. span ) ,
33- & mut app,
34- )
35- . 0
36- . to_string ( ) ;
27+ let ctxt = expr. span . ctxt ( ) ;
28+ let mut snippet_body = snippet_block_with_context ( cx, match_body. span , ctxt, ".." , Some ( expr. span ) , & mut app)
29+ . 0
30+ . to_string ( ) ;
3731
3832 // Do we need to add ';' to suggestion ?
3933 if let Node :: Stmt ( stmt) = cx. tcx . parent_hir_node ( expr. hir_id )
@@ -77,10 +71,10 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
7771 span,
7872 format ! (
7973 "let {} = {};\n {}let {} = {snippet_body};" ,
80- snippet_with_applicability ( cx, bind_names, ".." , & mut app) ,
81- snippet_with_applicability ( cx, matched_vars, ".." , & mut app) ,
74+ snippet_with_context ( cx, bind_names, ctxt , ".." , & mut app) . 0 ,
75+ snippet_with_context ( cx, matched_vars, ctxt , ".." , & mut app) . 0 ,
8276 " " . repeat( indent_of( cx, expr. span) . unwrap_or( 0 ) ) ,
83- snippet_with_applicability ( cx, pat_span, ".." , & mut app)
77+ snippet_with_context ( cx, pat_span, ctxt , ".." , & mut app) . 0
8478 ) ,
8579 ) ,
8680 None => {
@@ -204,14 +198,17 @@ fn sugg_with_curlies<'a>(
204198 s
205199 } ) ;
206200
201+ let ctxt = match_expr. span . ctxt ( ) ;
207202 let scrutinee = if needs_var_binding {
208203 format ! (
209204 "let {} = {}" ,
210- snippet_with_applicability ( cx, bind_names, ".." , applicability) ,
211- snippet_with_applicability ( cx, matched_vars, ".." , applicability)
205+ snippet_with_context ( cx, bind_names, ctxt , ".." , applicability) . 0 ,
206+ snippet_with_context ( cx, matched_vars, ctxt , ".." , applicability) . 0
212207 )
213208 } else {
214- snippet_with_applicability ( cx, matched_vars, ".." , applicability) . to_string ( )
209+ snippet_with_context ( cx, matched_vars, ctxt, ".." , applicability)
210+ . 0
211+ . to_string ( )
215212 } ;
216213
217214 format ! ( "{cbrace_start}{scrutinee};\n {indent}{assignment_str}{snippet_body}{cbrace_end}" )
0 commit comments