@@ -102,24 +102,20 @@ fn expr_sign(cx: &LateContext<'_>, expr: &Expr<'_>, ty: Ty<'_>) -> Sign {
102
102
if let Some ( val) = get_const_int_eval ( cx, expr, ty) {
103
103
return if val >= 0 { Sign :: ZeroOrPositive } else { Sign :: Negative } ;
104
104
}
105
+
105
106
// Calling on methods that always return non-negative values.
106
107
if let ExprKind :: MethodCall ( path, caller, args, ..) = expr. kind {
107
108
let mut method_name = path. ident . name . as_str ( ) ;
108
109
109
- if method_name == "unwrap"
110
- && let Some ( arglist) = method_chain_args ( expr, & [ "unwrap" ] )
111
- && let ExprKind :: MethodCall ( inner_path, ..) = & arglist[ 0 ] . 0 . kind
112
- {
113
- method_name = inner_path. ident . name . as_str ( ) ;
114
- }
115
- if method_name == "expect"
116
- && let Some ( arglist) = method_chain_args ( expr, & [ "expect" ] )
110
+ // Peel unwrap(), expect(), etc.
111
+ while let Some ( & found_name) = METHODS_UNWRAP . iter ( ) . find ( |& name| & method_name == name)
112
+ && let Some ( arglist) = method_chain_args ( expr, & [ found_name] )
117
113
&& let ExprKind :: MethodCall ( inner_path, ..) = & arglist[ 0 ] . 0 . kind
118
114
{
119
115
method_name = inner_path. ident . name . as_str ( ) ;
120
116
}
121
117
122
- if method_name == "pow"
118
+ if METHODS_POW . iter ( ) . any ( | & name| method_name == name )
123
119
&& let [ arg] = args
124
120
{
125
121
return pow_call_result_sign ( cx, caller, arg) ;
0 commit comments