Format all the let chains in compiler
This commit is contained in:
@@ -782,21 +782,23 @@ trait UnusedDelimLint {
|
||||
};
|
||||
let suggestion = spans.map(|(lo, hi)| {
|
||||
let sm = cx.sess().source_map();
|
||||
let lo_replace =
|
||||
if (keep_space.0 || is_kw) &&
|
||||
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(' ') {
|
||||
" "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let lo_replace = if (keep_space.0 || is_kw)
|
||||
&& let Ok(snip) = sm.span_to_prev_source(lo)
|
||||
&& !snip.ends_with(' ')
|
||||
{
|
||||
" "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let hi_replace =
|
||||
if keep_space.1 &&
|
||||
let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(' ') {
|
||||
" "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let hi_replace = if keep_space.1
|
||||
&& let Ok(snip) = sm.span_to_next_source(hi)
|
||||
&& !snip.starts_with(' ')
|
||||
{
|
||||
" "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
UnusedDelimSuggestion {
|
||||
start_span: lo,
|
||||
start_replace: lo_replace,
|
||||
@@ -1056,10 +1058,10 @@ impl UnusedParens {
|
||||
impl EarlyLintPass for UnusedParens {
|
||||
#[inline]
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
|
||||
if let ExprKind::Binary(op, lhs, _rhs) = &e.kind &&
|
||||
(op.node == ast::BinOpKind::Lt || op.node == ast::BinOpKind::Shl) &&
|
||||
let ExprKind::Cast(_expr, ty) = &lhs.kind &&
|
||||
let ast::TyKind::Paren(_) = &ty.kind
|
||||
if let ExprKind::Binary(op, lhs, _rhs) = &e.kind
|
||||
&& (op.node == ast::BinOpKind::Lt || op.node == ast::BinOpKind::Shl)
|
||||
&& let ExprKind::Cast(_expr, ty) = &lhs.kind
|
||||
&& let ast::TyKind::Paren(_) = &ty.kind
|
||||
{
|
||||
self.parens_in_cast_in_lt.push(ty.id);
|
||||
}
|
||||
@@ -1111,13 +1113,19 @@ impl EarlyLintPass for UnusedParens {
|
||||
}
|
||||
|
||||
fn check_expr_post(&mut self, _cx: &EarlyContext<'_>, e: &ast::Expr) {
|
||||
if let ExprKind::Binary(op, lhs, _rhs) = &e.kind &&
|
||||
(op.node == ast::BinOpKind::Lt || op.node == ast::BinOpKind::Shl) &&
|
||||
let ExprKind::Cast(_expr, ty) = &lhs.kind &&
|
||||
let ast::TyKind::Paren(_) = &ty.kind
|
||||
if let ExprKind::Binary(op, lhs, _rhs) = &e.kind
|
||||
&& (op.node == ast::BinOpKind::Lt || op.node == ast::BinOpKind::Shl)
|
||||
&& let ExprKind::Cast(_expr, ty) = &lhs.kind
|
||||
&& let ast::TyKind::Paren(_) = &ty.kind
|
||||
{
|
||||
let id = self.parens_in_cast_in_lt.pop().expect("check_expr and check_expr_post must balance");
|
||||
assert_eq!(id, ty.id, "check_expr, check_ty, and check_expr_post are called, in that order, by the visitor");
|
||||
let id = self
|
||||
.parens_in_cast_in_lt
|
||||
.pop()
|
||||
.expect("check_expr and check_expr_post must balance");
|
||||
assert_eq!(
|
||||
id, ty.id,
|
||||
"check_expr, check_ty, and check_expr_post are called, in that order, by the visitor"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1161,8 +1169,8 @@ impl EarlyLintPass for UnusedParens {
|
||||
}
|
||||
|
||||
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
||||
if let ast::TyKind::Paren(_) = ty.kind &&
|
||||
Some(&ty.id) == self.parens_in_cast_in_lt.last()
|
||||
if let ast::TyKind::Paren(_) = ty.kind
|
||||
&& Some(&ty.id) == self.parens_in_cast_in_lt.last()
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1206,13 +1214,14 @@ impl EarlyLintPass for UnusedParens {
|
||||
fn enter_where_predicate(&mut self, _: &EarlyContext<'_>, pred: &ast::WherePredicate) {
|
||||
use rustc_ast::{WhereBoundPredicate, WherePredicate};
|
||||
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
|
||||
bounded_ty,
|
||||
bound_generic_params,
|
||||
..
|
||||
}) = pred &&
|
||||
let ast::TyKind::Paren(_) = &bounded_ty.kind &&
|
||||
bound_generic_params.is_empty() {
|
||||
self.with_self_ty_parens = true;
|
||||
bounded_ty,
|
||||
bound_generic_params,
|
||||
..
|
||||
}) = pred
|
||||
&& let ast::TyKind::Paren(_) = &bounded_ty.kind
|
||||
&& bound_generic_params.is_empty()
|
||||
{
|
||||
self.with_self_ty_parens = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1516,9 +1525,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
|
||||
match e.kind {
|
||||
hir::ExprKind::Call(path_expr, [_])
|
||||
if let hir::ExprKind::Path(qpath) = &path_expr.kind
|
||||
&& let Some(did) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()
|
||||
&& cx.tcx.is_diagnostic_item(sym::box_new, did)
|
||||
=> {}
|
||||
&& let Some(did) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()
|
||||
&& cx.tcx.is_diagnostic_item(sym::box_new, did) => {}
|
||||
_ => return,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user