]> git.lizzy.rs Git - rust.git/commitdiff
Merge nested `if` into adjacent `if_let_chain!`
authorscott-linder <scott.b.linder@wmich.edu>
Mon, 12 Jun 2017 12:38:29 +0000 (08:38 -0400)
committerscott-linder <scott.b.linder@wmich.edu>
Mon, 12 Jun 2017 12:38:29 +0000 (08:38 -0400)
clippy_lints/src/types.rs

index da4fe963c30380c2aafe0eac787880b66c5a60dd..b3d2a374865e38ea7a17ec48ee47f29d19b466cc 100644 (file)
@@ -187,38 +187,36 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
             match ty.node {
                 TyPath(ref qpath) => {
                     let def = cx.tables.qpath_def(qpath, ast_ty.id);
-                    if let Some(def_id) = opt_def_id(def) {
-                        if Some(def_id) == cx.tcx.lang_items.owned_box() {
-                            if_let_chain! {[
-                                let QPath::Resolved(None, ref path) = *qpath,
-                                let [ref bx] = *path.segments,
-                                let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
-                                let [ref inner] = *ab_data.types
-                            ], {
-                                let ltopt = if lt.is_elided() {
-                                    "".to_owned()
-                                } else {
-                                    format!("{} ", lt.name.as_str())
-                                };
-                                let mutopt = if *mutbl == Mutability::MutMutable {
-                                    "mut "
-                                } else {
-                                    ""
-                                };
-                                span_lint_and_then(cx,
-                                    BORROWED_BOX,
-                                    ast_ty.span,
-                                    "you seem to be trying to use `&Box<T>`. Consider using just `&T`",
-                                    |db| {
-                                        db.span_suggestion(ast_ty.span,
-                                            "try",
-                                            format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")));
-                                    }
-                                );
-                                return; // don't recurse into the type
-                            }};
-                        }
-                    }
+                    if_let_chain! {[
+                        let Some(def_id) = opt_def_id(def),
+                        Some(def_id) == cx.tcx.lang_items.owned_box(),
+                        let QPath::Resolved(None, ref path) = *qpath,
+                        let [ref bx] = *path.segments,
+                        let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
+                        let [ref inner] = *ab_data.types
+                    ], {
+                        let ltopt = if lt.is_elided() {
+                            "".to_owned()
+                        } else {
+                            format!("{} ", lt.name.as_str())
+                        };
+                        let mutopt = if *mutbl == Mutability::MutMutable {
+                            "mut "
+                        } else {
+                            ""
+                        };
+                        span_lint_and_then(cx,
+                            BORROWED_BOX,
+                            ast_ty.span,
+                            "you seem to be trying to use `&Box<T>`. Consider using just `&T`",
+                            |db| {
+                                db.span_suggestion(ast_ty.span,
+                                    "try",
+                                    format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")));
+                            }
+                        );
+                        return; // don't recurse into the type
+                    }};
                     check_ty(cx, ty, is_local);
                 },
                 _ => check_ty(cx, ty, is_local),