mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 18:43:38 +00:00
Merge nested if
into adjacent if_let_chain!
This commit is contained in:
parent
54b52054c9
commit
49bba315e4
@ -187,38 +187,36 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
|
|||||||
match ty.node {
|
match ty.node {
|
||||||
TyPath(ref qpath) => {
|
TyPath(ref qpath) => {
|
||||||
let def = cx.tables.qpath_def(qpath, ast_ty.id);
|
let def = cx.tables.qpath_def(qpath, ast_ty.id);
|
||||||
if let Some(def_id) = opt_def_id(def) {
|
if_let_chain! {[
|
||||||
if Some(def_id) == cx.tcx.lang_items.owned_box() {
|
let Some(def_id) = opt_def_id(def),
|
||||||
if_let_chain! {[
|
Some(def_id) == cx.tcx.lang_items.owned_box(),
|
||||||
let QPath::Resolved(None, ref path) = *qpath,
|
let QPath::Resolved(None, ref path) = *qpath,
|
||||||
let [ref bx] = *path.segments,
|
let [ref bx] = *path.segments,
|
||||||
let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
|
let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
|
||||||
let [ref inner] = *ab_data.types
|
let [ref inner] = *ab_data.types
|
||||||
], {
|
], {
|
||||||
let ltopt = if lt.is_elided() {
|
let ltopt = if lt.is_elided() {
|
||||||
"".to_owned()
|
"".to_owned()
|
||||||
} else {
|
} else {
|
||||||
format!("{} ", lt.name.as_str())
|
format!("{} ", lt.name.as_str())
|
||||||
};
|
};
|
||||||
let mutopt = if *mutbl == Mutability::MutMutable {
|
let mutopt = if *mutbl == Mutability::MutMutable {
|
||||||
"mut "
|
"mut "
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
span_lint_and_then(cx,
|
span_lint_and_then(cx,
|
||||||
BORROWED_BOX,
|
BORROWED_BOX,
|
||||||
ast_ty.span,
|
ast_ty.span,
|
||||||
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
|
"you seem to be trying to use `&Box<T>`. Consider using just `&T`",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion(ast_ty.span,
|
db.span_suggestion(ast_ty.span,
|
||||||
"try",
|
"try",
|
||||||
format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")));
|
format!("&{}{}{}", ltopt, mutopt, &snippet(cx, inner.span, "..")));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}};
|
}};
|
||||||
}
|
|
||||||
}
|
|
||||||
check_ty(cx, ty, is_local);
|
check_ty(cx, ty, is_local);
|
||||||
},
|
},
|
||||||
_ => check_ty(cx, ty, is_local),
|
_ => check_ty(cx, ty, is_local),
|
||||||
|
Loading…
Reference in New Issue
Block a user