@@ -11,8 +11,28 @@ use super::CAST_SIGN_LOSS;
1111/// Includes methods that panic rather than returning a negative value.
1212///
1313/// Methods that can overflow and return a negative value must not be included in this list,
14- /// because checking for negative return values from those functions can be useful.
15- const METHODS_RET_POSITIVE : & [ & str ] = & [ "checked_abs" , "rem_euclid" , "checked_rem_euclid" ] ;
14+ /// because casting their return values can still result in sign loss.
15+ const METHODS_RET_POSITIVE : & [ & str ] = & [
16+ "checked_abs" ,
17+ "saturating_abs" ,
18+ "isqrt" ,
19+ "checked_isqrt" ,
20+ "rem_euclid" ,
21+ "checked_rem_euclid" ,
22+ "wrapping_rem_euclid" ,
23+ ] ;
24+
25+ /// A list of methods that act like `pow()`, and can never return:
26+ /// - a negative value from a non-negative base
27+ /// - a negative value from a negative base and even exponent
28+ /// - a non-negative value from a negative base and odd exponent
29+ ///
30+ /// Methods that can overflow and return a negative value must not be included in this list,
31+ /// because casting their return values can still result in sign loss.
32+ const METHODS_POW : & [ & str ] = & [ "pow" , "saturating_pow" , "checked_pow" ] ;
33+
34+ /// A list of methods that act like `unwrap()`, and don't change the sign of the inner value.
35+ const METHODS_UNWRAP : & [ & str ] = & [ "unwrap" , "unwrap_unchecked" , "expect" , "into_ok" ] ;
1636
1737pub ( super ) fn check ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , cast_op : & Expr < ' _ > , cast_from : Ty < ' _ > , cast_to : Ty < ' _ > ) {
1838 if should_lint ( cx, cast_op, cast_from, cast_to) {
0 commit comments