@@ -3,7 +3,7 @@ use clippy_utils::source::snippet_opt;
3
3
use clippy_utils:: ty:: has_drop;
4
4
use rustc_errors:: Applicability ;
5
5
use rustc_hir:: def:: { DefKind , Res } ;
6
- use rustc_hir:: { BinOpKind , BlockCheckMode , Expr , ExprKind , Stmt , StmtKind , UnsafeSource } ;
6
+ use rustc_hir:: { is_range_literal , BinOpKind , BlockCheckMode , Expr , ExprKind , Stmt , StmtKind , UnsafeSource } ;
7
7
use rustc_lint:: { LateContext , LateLintPass } ;
8
8
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
9
9
use std:: ops:: Deref ;
@@ -68,12 +68,14 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
68
68
ExprKind :: Call ( callee, args) => {
69
69
if let ExprKind :: Path ( ref qpath) = callee. kind {
70
70
let res = cx. qpath_res ( qpath, callee. hir_id ) ;
71
- match res {
72
- Res :: Def ( DefKind :: Struct | DefKind :: Variant | DefKind :: Ctor ( ..) , ..) => {
73
- !has_drop ( cx, cx. typeck_results ( ) . expr_ty ( expr) )
74
- && args. iter ( ) . all ( |arg| has_no_effect ( cx, arg) )
75
- } ,
76
- _ => false ,
71
+ let def_matched = matches ! (
72
+ res,
73
+ Res :: Def ( DefKind :: Struct | DefKind :: Variant | DefKind :: Ctor ( ..) , ..)
74
+ ) ;
75
+ if def_matched || is_range_literal ( expr) {
76
+ !has_drop ( cx, cx. typeck_results ( ) . expr_ty ( expr) ) && args. iter ( ) . all ( |arg| has_no_effect ( cx, arg) )
77
+ } else {
78
+ false
77
79
}
78
80
} else {
79
81
false
0 commit comments