1
- use clippy_utils:: diagnostics:: span_lint_and_then ;
1
+ use clippy_utils:: diagnostics:: span_lint_and_sugg ;
2
2
use clippy_utils:: higher;
3
- use clippy_utils:: source:: { snippet , snippet_with_applicability} ;
3
+ use clippy_utils:: source:: { SpanRangeExt , snippet_with_applicability} ;
4
4
5
5
use rustc_ast:: ast;
6
6
use rustc_errors:: Applicability ;
@@ -40,10 +40,6 @@ declare_clippy_lint! {
40
40
41
41
declare_lint_pass ! ( NeedlessParensOnRangeLiterals => [ NEEDLESS_PARENS_ON_RANGE_LITERALS ] ) ;
42
42
43
- fn snippet_enclosed_in_parenthesis ( snippet : & str ) -> bool {
44
- snippet. starts_with ( '(' ) && snippet. ends_with ( ')' )
45
- }
46
-
47
43
fn check_for_parens ( cx : & LateContext < ' _ > , e : & Expr < ' _ > , is_start : bool ) {
48
44
if is_start
49
45
&& let ExprKind :: Lit ( literal) = e. kind
@@ -54,20 +50,20 @@ fn check_for_parens(cx: &LateContext<'_>, e: &Expr<'_>, is_start: bool) {
54
50
}
55
51
if let ExprKind :: Lit ( literal) = e. kind
56
52
// the indicator that parenthesis surround the literal is that the span of the expression and the literal differ
57
- && ( literal. span . data ( ) . hi - literal . span . data ( ) . lo ) != ( e. span . data ( ) . hi - e . span . data ( ) . lo )
53
+ && literal. span != e. span
58
54
// inspect the source code of the expression for parenthesis
59
- && snippet_enclosed_in_parenthesis ( & snippet ( cx, e . span , "" ) )
55
+ && e . span . check_source_text ( cx, |s| s . starts_with ( '(' ) && s . ends_with ( ')' ) )
60
56
{
61
57
let mut applicability = Applicability :: MachineApplicable ;
62
- span_lint_and_then (
58
+ let suggestion = snippet_with_applicability ( cx, literal. span , "_" , & mut applicability) ;
59
+ span_lint_and_sugg (
63
60
cx,
64
61
NEEDLESS_PARENS_ON_RANGE_LITERALS ,
65
62
e. span ,
66
63
"needless parenthesis on range literals can be removed" ,
67
- |diag| {
68
- let suggestion = snippet_with_applicability ( cx, literal. span , "_" , & mut applicability) ;
69
- diag. span_suggestion ( e. span , "try" , suggestion, applicability) ;
70
- } ,
64
+ "try" ,
65
+ suggestion. to_string ( ) ,
66
+ applicability,
71
67
) ;
72
68
}
73
69
}
0 commit comments