@@ -3,7 +3,7 @@ use clippy_utils::source::snippet_opt;
33use clippy_utils:: ty:: has_drop;
44use rustc_errors:: Applicability ;
55use 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 } ;
77use rustc_lint:: { LateContext , LateLintPass } ;
88use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
99use std:: ops:: Deref ;
@@ -68,12 +68,14 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
6868 ExprKind :: Call ( callee, args) => {
6969 if let ExprKind :: Path ( ref qpath) = callee. kind {
7070 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
7779 }
7880 } else {
7981 false
0 commit comments