1
1
use clippy_utils:: diagnostics:: span_lint_and_sugg;
2
2
use 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 } ;
4
4
use clippy_utils:: { get_parent_expr, is_refutable, peel_blocks} ;
5
5
use rustc_errors:: Applicability ;
6
6
use 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
24
24
let bind_names = arms[ 0 ] . pat . span ;
25
25
let match_body = peel_blocks ( arms[ 0 ] . body ) ;
26
26
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 ( ) ;
37
31
38
32
// Do we need to add ';' to suggestion ?
39
33
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
77
71
span,
78
72
format ! (
79
73
"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 ,
82
76
" " . 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
84
78
) ,
85
79
) ,
86
80
None => {
@@ -204,14 +198,17 @@ fn sugg_with_curlies<'a>(
204
198
s
205
199
} ) ;
206
200
201
+ let ctxt = match_expr. span . ctxt ( ) ;
207
202
let scrutinee = if needs_var_binding {
208
203
format ! (
209
204
"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
212
207
)
213
208
} 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 ( )
215
212
} ;
216
213
217
214
format ! ( "{cbrace_start}{scrutinee};\n {indent}{assignment_str}{snippet_body}{cbrace_end}" )
0 commit comments