@@ -17,6 +17,8 @@ use rustc_target::spec::abi::Abi;
1717use rustc_typeck:: hir_ty_to_ty;
1818use syntax:: ast:: { FloatTy , IntTy , LitIntType , LitKind , UintTy } ;
1919use syntax:: errors:: DiagnosticBuilder ;
20+ use syntax:: ext:: base:: MacroKind ;
21+ use syntax:: ext:: hygiene:: ExpnKind ;
2022use syntax:: source_map:: Span ;
2123use syntax:: symbol:: { sym, Symbol } ;
2224
@@ -527,6 +529,30 @@ declare_lint_pass!(UnitCmp => [UNIT_CMP]);
527529impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for UnitCmp {
528530 fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) {
529531 if expr. span . from_expansion ( ) {
532+ if let Some ( callee) = expr. span . source_callee ( ) {
533+ if let ExpnKind :: Macro ( MacroKind :: Bang , symbol) = callee. kind {
534+ if let ExprKind :: Binary ( ref cmp, ref left, _) = expr. kind {
535+ let op = cmp. node ;
536+ if op. is_comparison ( ) && is_unit ( cx. tables . expr_ty ( left) ) {
537+ let result = match & * symbol. as_str ( ) {
538+ "assert_eq" | "debug_assert_eq" => "succeed" ,
539+ "assert_ne" | "debug_assert_ne" => "fail" ,
540+ _ => return ,
541+ } ;
542+ span_lint (
543+ cx,
544+ UNIT_CMP ,
545+ expr. span ,
546+ & format ! (
547+ "{} of unit values detected. This will always {}" ,
548+ symbol. as_str( ) ,
549+ result
550+ ) ,
551+ ) ;
552+ }
553+ }
554+ }
555+ }
530556 return ;
531557 }
532558 if let ExprKind :: Binary ( ref cmp, ref left, _) = expr. kind {
0 commit comments