@@ -2,11 +2,34 @@ 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_different ( 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_symbol, l_style) , LitKind :: Str ( r_symbol, r_style) ) => {
15+ l_style != r_style || l_symbol != r_symbol
16+ } ,
17+ ( LitKind :: ByteStr ( l_symbol, l_style) , LitKind :: ByteStr ( r_symbol, r_style) )
18+ | ( LitKind :: CStr ( l_symbol, l_style) , LitKind :: CStr ( r_symbol, r_style) ) => {
19+ l_style != r_style || l_symbol != r_symbol
20+ } ,
21+ ( LitKind :: Int ( _, l_style) , LitKind :: Int ( _, r_style) ) => l_style != r_style,
22+ ( LitKind :: Float ( _, l_style) , LitKind :: Float ( _, r_style) ) => l_style != r_style,
23+ ( LitKind :: Byte ( _) , LitKind :: Byte ( _) )
24+ | ( LitKind :: Char ( _) , LitKind :: Char ( _) )
25+ | ( LitKind :: Bool ( _) , LitKind :: Bool ( _) ) => false ,
26+ _ => true ,
27+ } ;
28+ }
29+
30+ false
31+ }
32+
1033pub ( crate ) fn check_assert < ' tcx > ( cx : & LateContext < ' tcx > , e : & ' tcx Expr < ' _ > ) {
1134 if let Some ( macro_call) = first_node_macro_backtrace ( cx, e) . find ( |macro_call| {
1235 matches ! (
@@ -17,6 +40,7 @@ pub(crate) fn check_assert<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
1740 && eq_expr_value ( cx, lhs, rhs)
1841 && macro_call. is_local ( )
1942 && !is_in_test_function ( cx. tcx , e. hir_id )
43+ && !is_literal_different ( lhs, rhs)
2044 {
2145 span_lint (
2246 cx,
@@ -37,7 +61,11 @@ pub(crate) fn check<'tcx>(
3761 left : & ' tcx Expr < ' _ > ,
3862 right : & ' tcx Expr < ' _ > ,
3963) {
40- if is_useless_with_eq_exprs ( op) && eq_expr_value ( cx, left, right) && !is_in_test_function ( cx. tcx , e. hir_id ) {
64+ if is_useless_with_eq_exprs ( op)
65+ && eq_expr_value ( cx, left, right)
66+ && !is_in_test_function ( cx. tcx , e. hir_id )
67+ && !is_literal_different ( left, right)
68+ {
4169 span_lint_and_then (
4270 cx,
4371 EQ_OP ,
0 commit comments