Skip to content

Commit 49bba31

Browse files
author
scott-linder
committed
Merge nested if into adjacent if_let_chain!
1 parent 54b5205 commit 49bba31

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

clippy_lints/src/types.rs

+30-32
Original file line numberDiff line numberDiff line change
@@ -187,38 +187,36 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
187187
match ty.node {
188188
TyPath(ref qpath) => {
189189
let def = cx.tables.qpath_def(qpath, ast_ty.id);
190-
if let Some(def_id) = opt_def_id(def) {
191-
if Some(def_id) == cx.tcx.lang_items.owned_box() {
192-
if_let_chain! {[
193-
let QPath::Resolved(None, ref path) = *qpath,
194-
let [ref bx] = *path.segments,
195-
let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
196-
let [ref inner] = *ab_data.types
197-
], {
198-
let ltopt = if lt.is_elided() {
199-
"".to_owned()
200-
} else {
201-
format!("{} ", lt.name.as_str())
202-
};
203-
let mutopt = if *mutbl == Mutability::MutMutable {
204-
"mut "
205-
} else {
206-
""
207-
};
208-
span_lint_and_then(cx,
209-
BORROWED_BOX,
210-
ast_ty.span,
211-
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
212-
|db| {
213-
db.span_suggestion(ast_ty.span,
214-
"try",
215-
format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")));
216-
}
217-
);
218-
return; // don't recurse into the type
219-
}};
220-
}
221-
}
190+
if_let_chain! {[
191+
let Some(def_id) = opt_def_id(def),
192+
Some(def_id) == cx.tcx.lang_items.owned_box(),
193+
let QPath::Resolved(None, ref path) = *qpath,
194+
let [ref bx] = *path.segments,
195+
let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
196+
let [ref inner] = *ab_data.types
197+
], {
198+
let ltopt = if lt.is_elided() {
199+
"".to_owned()
200+
} else {
201+
format!("{} ", lt.name.as_str())
202+
};
203+
let mutopt = if *mutbl == Mutability::MutMutable {
204+
"mut "
205+
} else {
206+
""
207+
};
208+
span_lint_and_then(cx,
209+
BORROWED_BOX,
210+
ast_ty.span,
211+
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
212+
|db| {
213+
db.span_suggestion(ast_ty.span,
214+
"try",
215+
format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")));
216+
}
217+
);
218+
return; // don't recurse into the type
219+
}};
222220
check_ty(cx, ty, is_local);
223221
},
224222
_ => check_ty(cx, ty, is_local),

0 commit comments

Comments
 (0)