use let chains in hir, lint, mir
This commit is contained in:
@@ -76,28 +76,24 @@ impl<'tcx> ThirBuildCx<'tcx> {
|
||||
let mut pattern = self.pattern_from_hir(local.pat);
|
||||
debug!(?pattern);
|
||||
|
||||
if let Some(ty) = &local.ty {
|
||||
if let Some(&user_ty) =
|
||||
if let Some(ty) = &local.ty
|
||||
&& let Some(&user_ty) =
|
||||
self.typeck_results.user_provided_types().get(ty.hir_id)
|
||||
{
|
||||
debug!("mirror_stmts: user_ty={:?}", user_ty);
|
||||
let annotation = CanonicalUserTypeAnnotation {
|
||||
user_ty: Box::new(user_ty),
|
||||
span: ty.span,
|
||||
inferred_ty: self.typeck_results.node_type(ty.hir_id),
|
||||
};
|
||||
pattern = Box::new(Pat {
|
||||
ty: pattern.ty,
|
||||
span: pattern.span,
|
||||
kind: PatKind::AscribeUserType {
|
||||
ascription: Ascription {
|
||||
annotation,
|
||||
variance: ty::Covariant,
|
||||
},
|
||||
subpattern: pattern,
|
||||
},
|
||||
});
|
||||
}
|
||||
{
|
||||
debug!("mirror_stmts: user_ty={:?}", user_ty);
|
||||
let annotation = CanonicalUserTypeAnnotation {
|
||||
user_ty: Box::new(user_ty),
|
||||
span: ty.span,
|
||||
inferred_ty: self.typeck_results.node_type(ty.hir_id),
|
||||
};
|
||||
pattern = Box::new(Pat {
|
||||
ty: pattern.ty,
|
||||
span: pattern.span,
|
||||
kind: PatKind::AscribeUserType {
|
||||
ascription: Ascription { annotation, variance: ty::Covariant },
|
||||
subpattern: pattern,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let span = match local.init {
|
||||
|
||||
@@ -105,11 +105,11 @@ impl<'tcx> ThirBuildCx<'tcx> {
|
||||
// // ^ error message points at this expression.
|
||||
// }
|
||||
let mut adjust_span = |expr: &mut Expr<'tcx>| {
|
||||
if let ExprKind::Block { block } = expr.kind {
|
||||
if let Some(last_expr) = self.thir[block].expr {
|
||||
span = self.thir[last_expr].span;
|
||||
expr.span = span;
|
||||
}
|
||||
if let ExprKind::Block { block } = expr.kind
|
||||
&& let Some(last_expr) = self.thir[block].expr
|
||||
{
|
||||
span = self.thir[last_expr].span;
|
||||
expr.span = span;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -956,10 +956,10 @@ impl<'tcx> ThirBuildCx<'tcx> {
|
||||
};
|
||||
|
||||
fn local(expr: &rustc_hir::Expr<'_>) -> Option<hir::HirId> {
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind {
|
||||
if let Res::Local(hir_id) = path.res {
|
||||
return Some(hir_id);
|
||||
}
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind
|
||||
&& let Res::Local(hir_id) = path.res
|
||||
{
|
||||
return Some(hir_id);
|
||||
}
|
||||
|
||||
None
|
||||
|
||||
@@ -1155,14 +1155,12 @@ fn find_fallback_pattern_typo<'tcx>(
|
||||
}
|
||||
hir::Node::Block(hir::Block { stmts, .. }) => {
|
||||
for stmt in *stmts {
|
||||
if let hir::StmtKind::Let(let_stmt) = stmt.kind {
|
||||
if let hir::PatKind::Binding(_, _, binding_name, _) =
|
||||
if let hir::StmtKind::Let(let_stmt) = stmt.kind
|
||||
&& let hir::PatKind::Binding(_, _, binding_name, _) =
|
||||
let_stmt.pat.kind
|
||||
{
|
||||
if name == binding_name.name {
|
||||
lint.pattern_let_binding = Some(binding_name.span);
|
||||
}
|
||||
}
|
||||
&& name == binding_name.name
|
||||
{
|
||||
lint.pattern_let_binding = Some(binding_name.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user