@@ -2,11 +2,30 @@ use clippy_utils::ast_utils::is_useless_with_eq_exprs;
22use clippy_utils:: diagnostics:: { span_lint, span_lint_and_then} ;
33use clippy_utils:: macros:: { find_assert_eq_args, first_node_macro_backtrace} ;
44use clippy_utils:: { eq_expr_value, is_in_test_function, sym} ;
5- use rustc_hir:: { BinOpKind , Expr } ;
5+ use rustc_ast:: LitKind ;
6+ use rustc_hir:: { BinOpKind , Expr , ExprKind } ;
67use rustc_lint:: LateContext ;
78
89use super :: EQ_OP ;
910
11+ fn is_literal_in_different_form ( l : & Expr < ' _ > , r : & Expr < ' _ > ) -> bool {
12+ if let ( ExprKind :: Lit ( l) , ExprKind :: Lit ( r) ) = ( l. kind , r. kind ) {
13+ return match ( l. node , r. node ) {
14+ ( LitKind :: Str ( _, l_style) , LitKind :: Str ( _, r_style) )
15+ | ( LitKind :: ByteStr ( _, l_style) , LitKind :: ByteStr ( _, r_style) )
16+ | ( LitKind :: CStr ( _, l_style) , LitKind :: CStr ( _, r_style) ) => l_style != r_style,
17+ ( LitKind :: Int ( _, l_style) , LitKind :: Int ( _, r_style) ) => l_style != r_style,
18+ ( LitKind :: Float ( _, l_style) , LitKind :: Float ( _, r_style) ) => l_style != r_style,
19+ ( LitKind :: Byte ( _) , LitKind :: Byte ( _) )
20+ | ( LitKind :: Char ( _) , LitKind :: Char ( _) )
21+ | ( LitKind :: Bool ( _) , LitKind :: Bool ( _) ) => false ,
22+ _ => true ,
23+ } ;
24+ }
25+
26+ false
27+ }
28+
1029pub ( crate ) fn check_assert < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > ) {
1130 if let Some ( macro_call) = first_node_macro_backtrace ( cx, e) . find ( |macro_call| {
1231 matches ! (
@@ -17,6 +36,7 @@ pub(crate) fn check_assert<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
1736 && eq_expr_value ( cx, lhs, rhs)
1837 && macro_call. is_local ( )
1938 && !is_in_test_function ( cx. tcx , e. hir_id )
39+ && !is_literal_in_different_form ( lhs, rhs)
2040 {
2141 span_lint (
2242 cx,
@@ -37,7 +57,11 @@ pub(crate) fn check<'tcx>(
3757 left : & ' tcx Expr < ' _ > ,
3858 right : & ' tcx Expr < ' _ > ,
3959) {
40- if is_useless_with_eq_exprs ( op) && eq_expr_value ( cx, left, right) && !is_in_test_function ( cx. tcx , e. hir_id ) {
60+ if is_useless_with_eq_exprs ( op)
61+ && eq_expr_value ( cx, left, right)
62+ && !is_in_test_function ( cx. tcx , e. hir_id )
63+ && !is_literal_in_different_form ( left, right)
64+ {
4165 span_lint_and_then (
4266 cx,
4367 EQ_OP ,
0 commit comments