1
1
use clippy_utils:: diagnostics:: { span_lint_and_sugg, span_lint_hir_and_then} ;
2
2
use clippy_utils:: eq_expr_value;
3
- use clippy_utils:: source:: snippet_opt ;
3
+ use clippy_utils:: source:: SpanRangeExt ;
4
4
use clippy_utils:: ty:: { implements_trait, is_type_diagnostic_item} ;
5
5
use rustc_ast:: ast:: LitKind ;
6
6
use rustc_errors:: Applicability ;
@@ -134,28 +134,30 @@ fn check_inverted_bool_in_condition(
134
134
135
135
let suggestion = match ( left. kind , right. kind ) {
136
136
( ExprKind :: Unary ( UnOp :: Not , left_sub) , ExprKind :: Unary ( UnOp :: Not , right_sub) ) => {
137
- let Some ( left) = snippet_opt ( cx , left_sub. span ) else {
137
+ let Some ( left) = left_sub. span . get_source_text ( cx ) else {
138
138
return ;
139
139
} ;
140
- let Some ( right) = snippet_opt ( cx , right_sub. span ) else {
140
+ let Some ( right) = right_sub. span . get_source_text ( cx ) else {
141
141
return ;
142
142
} ;
143
143
let Some ( op) = bin_op_eq_str ( op) else { return } ;
144
144
format ! ( "{left} {op} {right}" )
145
145
} ,
146
146
( ExprKind :: Unary ( UnOp :: Not , left_sub) , _) => {
147
- let Some ( left) = snippet_opt ( cx , left_sub. span ) else {
147
+ let Some ( left) = left_sub. span . get_source_text ( cx ) else {
148
148
return ;
149
149
} ;
150
- let Some ( right) = snippet_opt ( cx , right. span ) else {
150
+ let Some ( right) = right. span . get_source_text ( cx ) else {
151
151
return ;
152
152
} ;
153
153
let Some ( op) = inverted_bin_op_eq_str ( op) else { return } ;
154
154
format ! ( "{left} {op} {right}" )
155
155
} ,
156
156
( _, ExprKind :: Unary ( UnOp :: Not , right_sub) ) => {
157
- let Some ( left) = snippet_opt ( cx, left. span ) else { return } ;
158
- let Some ( right) = snippet_opt ( cx, right_sub. span ) else {
157
+ let Some ( left) = left. span . get_source_text ( cx) else {
158
+ return ;
159
+ } ;
160
+ let Some ( right) = right_sub. span . get_source_text ( cx) else {
159
161
return ;
160
162
} ;
161
163
let Some ( op) = inverted_bin_op_eq_str ( op) else { return } ;
@@ -313,8 +315,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
313
315
self . output . push_str ( & str) ;
314
316
} else {
315
317
self . output . push ( '!' ) ;
316
- let snip = snippet_opt ( self . cx , terminal. span ) ?;
317
- self . output . push_str ( & snip) ;
318
+ self . output . push_str ( & terminal. span . get_source_text ( self . cx ) ?) ;
318
319
}
319
320
} ,
320
321
True | False | Not ( _) => {
@@ -345,8 +346,12 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
345
346
}
346
347
} ,
347
348
& Term ( n) => {
348
- let snip = snippet_opt ( self . cx , self . terminals [ n as usize ] . span . source_callsite ( ) ) ?;
349
- self . output . push_str ( & snip) ;
349
+ self . output . push_str (
350
+ & self . terminals [ n as usize ]
351
+ . span
352
+ . source_callsite ( )
353
+ . get_source_text ( self . cx ) ?,
354
+ ) ;
350
355
} ,
351
356
}
352
357
Some ( ( ) )
@@ -370,8 +375,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
370
375
_ => None ,
371
376
}
372
377
. and_then ( |op| {
373
- let lhs_snippet = snippet_opt ( cx , lhs. span ) ?;
374
- let rhs_snippet = snippet_opt ( cx , rhs. span ) ?;
378
+ let lhs_snippet = lhs. span . get_source_text ( cx ) ?;
379
+ let rhs_snippet = rhs. span . get_source_text ( cx ) ?;
375
380
376
381
if !( lhs_snippet. starts_with ( '(' ) && lhs_snippet. ends_with ( ')' ) ) {
377
382
if let ( ExprKind :: Cast ( ..) , BinOpKind :: Ge ) = ( & lhs. kind , binop. node ) {
@@ -399,7 +404,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
399
404
let path: & str = path. ident . name . as_str ( ) ;
400
405
a == path
401
406
} )
402
- . and_then ( |( _, neg_method) | Some ( format ! ( "{}.{neg_method}()" , snippet_opt ( cx , receiver. span) ?) ) )
407
+ . and_then ( |( _, neg_method) | Some ( format ! ( "{}.{neg_method}()" , receiver. span. get_source_text ( cx ) ?) ) )
403
408
} ,
404
409
_ => None ,
405
410
}
0 commit comments