Skip to content

Commit 9f59e9a

Browse files
committed
from_str_radix_10 : Reorder checks
1 parent 3fcac2c commit 9f59e9a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

clippy_lints/src/from_str_radix_10.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,23 @@ impl<'tcx> LateLintPass<'tcx> for FromStrRadix10 {
4747
fn check_expr(&mut self, cx: &LateContext<'tcx>, exp: &Expr<'tcx>) {
4848
if let ExprKind::Call(maybe_path, [src, radix]) = &exp.kind
4949
&& let ExprKind::Path(QPath::TypeRelative(ty, pathseg)) = &maybe_path.kind
50-
// do not lint in constant context, because the suggestion won't work.
51-
// NB: keep this check until a new `const_trait_impl` is available and stablized.
52-
&& !in_constant(cx, exp.hir_id)
50+
51+
// check if the second argument is a primitive `10`
52+
&& is_integer_literal(radix, 10)
53+
54+
// check if the second part of the path indeed calls the associated
55+
// function `from_str_radix`
56+
&& pathseg.ident.name.as_str() == "from_str_radix"
5357

5458
// check if the first part of the path is some integer primitive
5559
&& let TyKind::Path(ty_qpath) = &ty.kind
5660
&& let ty_res = cx.qpath_res(ty_qpath, ty.hir_id)
5761
&& let def::Res::PrimTy(prim_ty) = ty_res
5862
&& matches!(prim_ty, PrimTy::Int(_) | PrimTy::Uint(_))
5963

60-
// check if the second part of the path indeed calls the associated
61-
// function `from_str_radix`
62-
&& pathseg.ident.name.as_str() == "from_str_radix"
63-
64-
// check if the second argument is a primitive `10`
65-
&& is_integer_literal(radix, 10)
64+
// do not lint in constant context, because the suggestion won't work.
65+
// NB: keep this check until a new `const_trait_impl` is available and stablized.
66+
&& !in_constant(cx, exp.hir_id)
6667
{
6768
let expr = if let ExprKind::AddrOf(_, _, expr) = &src.kind {
6869
let ty = cx.typeck_results().expr_ty(expr);

0 commit comments

Comments
 (0)