Rename hir::Node::Local into hir::Node::LetStmt

This commit is contained in:
Guillaume Gomez 2024-03-22 18:06:20 +01:00
parent bd9efd5265
commit 43a61e9aca
27 changed files with 40 additions and 40 deletions

View File

@ -163,7 +163,7 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC
// TODO: This check currently bails if the local variable has no initializer. // TODO: This check currently bails if the local variable has no initializer.
// That is overly conservative - the lint should fire even if there was no initializer, // That is overly conservative - the lint should fire even if there was no initializer,
// but the variable has been initialized before `lhs` was evaluated. // but the variable has been initialized before `lhs` was evaluated.
if let Some(Node::Local(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p)) if let Some(Node::LetStmt(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p))
&& local.init.is_none() && local.init.is_none()
{ {
return false; return false;

View File

@ -139,7 +139,7 @@ impl<'tcx> Visitor<'tcx> for InferVisitor {
fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
match cx.tcx.parent_hir_node(expr.hir_id) { match cx.tcx.parent_hir_node(expr.hir_id) {
Node::Local(LetStmt { ty: Some(ty), .. }) => { Node::LetStmt(LetStmt { ty: Some(ty), .. }) => {
let mut v = InferVisitor::default(); let mut v = InferVisitor::default();
v.visit_ty(ty); v.visit_ty(ty);
!v.0 !v.0

View File

@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(
&& let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind() && let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind()
&& let Some(use_cx) = expr_use_ctxt(cx, expr) && let Some(use_cx) = expr_use_ctxt(cx, expr)
// TODO: only block the lint if `cast_expr` is a temporary // TODO: only block the lint if `cast_expr` is a temporary
&& !matches!(use_cx.node, ExprUseNode::Local(_) | ExprUseNode::ConstStatic(_)) && !matches!(use_cx.node, ExprUseNode::LetStmt(_) | ExprUseNode::ConstStatic(_))
{ {
let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" }; let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" };
let fn_name = match to_mutbl { let fn_name = match to_mutbl {

View File

@ -66,7 +66,7 @@ pub(super) fn check<'tcx>(
&& let QPath::Resolved(None, Path { res, .. }) = qpath && let QPath::Resolved(None, Path { res, .. }) = qpath
&& let Res::Local(hir_id) = res && let Res::Local(hir_id) = res
&& let parent = cx.tcx.parent_hir_node(*hir_id) && let parent = cx.tcx.parent_hir_node(*hir_id)
&& let Node::Local(local) = parent && let Node::LetStmt(local) = parent
{ {
if let Some(ty) = local.ty if let Some(ty) = local.ty
&& let TyKind::Path(qpath) = ty.kind && let TyKind::Path(qpath) = ty.kind
@ -275,7 +275,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
} }
// Local usage // Local usage
} else if let Res::Local(hir_id) = res } else if let Res::Local(hir_id) = res
&& let Node::Local(l) = cx.tcx.parent_hir_node(hir_id) && let Node::LetStmt(l) = cx.tcx.parent_hir_node(hir_id)
{ {
if let Some(e) = l.init if let Some(e) = l.init
&& is_cast_from_ty_alias(cx, e, cast_from) && is_cast_from_ty_alias(cx, e, cast_from)

View File

@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
// Ignore function parameters // Ignore function parameters
return; return;
}, },
Node::Local(local) if local.ty.is_some() => { Node::LetStmt(local) if local.ty.is_some() => {
// Ignore let bindings with explicit type // Ignore let bindings with explicit type
return; return;
}, },

View File

@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
if let Node::Pat(pat) = node if let Node::Pat(pat) = node
&& let PatKind::Binding(bind_ann, ..) = pat.kind && let PatKind::Binding(bind_ann, ..) = pat.kind
&& !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut)) && !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut))
&& let Node::Local(parent_let_expr) = cx.tcx.parent_hir_node(hir_id) && let Node::LetStmt(parent_let_expr) = cx.tcx.parent_hir_node(hir_id)
&& let Some(init) = parent_let_expr.init && let Some(init) = parent_let_expr.init
{ {
match init.kind { match init.kind {

View File

@ -81,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
// Apply only to params or locals with annotated types // Apply only to params or locals with annotated types
match cx.tcx.parent_hir_node(hir_id) { match cx.tcx.parent_hir_node(hir_id) {
Node::Param(..) => (), Node::Param(..) => (),
Node::Local(local) => { Node::LetStmt(local) => {
let Some(ty) = local.ty else { return }; let Some(ty) = local.ty else { return };
if matches!(ty.kind, TyKind::Infer) { if matches!(ty.kind, TyKind::Infer) {
return; return;

View File

@ -148,7 +148,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<AssignmentExpr> { fn opt_parent_assign_span<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<AssignmentExpr> {
if let Node::Expr(parent_arm_expr) = cx.tcx.parent_hir_node(ex.hir_id) { if let Node::Expr(parent_arm_expr) = cx.tcx.parent_hir_node(ex.hir_id) {
return match cx.tcx.parent_hir_node(parent_arm_expr.hir_id) { return match cx.tcx.parent_hir_node(parent_arm_expr.hir_id) {
Node::Local(parent_let_expr) => Some(AssignmentExpr::Local { Node::LetStmt(parent_let_expr) => Some(AssignmentExpr::Local {
span: parent_let_expr.span, span: parent_let_expr.span,
pat_span: parent_let_expr.pat.span(), pat_span: parent_let_expr.pat.span(),
}), }),

View File

@ -125,7 +125,7 @@ fn strip_return<'hir>(expr: &'hir Expr<'hir>) -> &'hir Expr<'hir> {
fn expr_ty_matches_p_ty(cx: &LateContext<'_>, expr: &Expr<'_>, p_expr: &Expr<'_>) -> bool { fn expr_ty_matches_p_ty(cx: &LateContext<'_>, expr: &Expr<'_>, p_expr: &Expr<'_>) -> bool {
match cx.tcx.parent_hir_node(p_expr.hir_id) { match cx.tcx.parent_hir_node(p_expr.hir_id) {
// Compare match_expr ty with local in `let local = match match_expr {..}` // Compare match_expr ty with local in `let local = match match_expr {..}`
Node::Local(local) => { Node::LetStmt(local) => {
let results = cx.typeck_results(); let results = cx.typeck_results();
return same_type_and_consts(results.node_type(local.hir_id), results.expr_ty(expr)); return same_type_and_consts(results.node_type(local.hir_id), results.expr_ty(expr));
}, },

View File

@ -69,7 +69,7 @@ pub(super) fn check(
_ => false, _ => false,
}, },
// local binding capturing a reference // local binding capturing a reference
Node::Local(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..)) => { Node::LetStmt(l) if matches!(l.pat.kind, PatKind::Binding(BindingAnnotation(ByRef::Yes, _), ..)) => {
return; return;
}, },
_ => false, _ => false,

View File

@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: &str, re
| ExprKind::Break(_, _) => true, | ExprKind::Break(_, _) => true,
_ => false, _ => false,
}, },
Some((Node::Stmt(_) | Node::Local(_), _)) => false, Some((Node::Stmt(_) | Node::LetStmt(_), _)) => false,
_ => true, _ => true,
}; };

View File

@ -85,7 +85,7 @@ pub(super) fn check<'tcx>(
); );
} }
}, },
Node::Local(l) => { Node::LetStmt(l) => {
if let PatKind::Binding(BindingAnnotation::NONE | BindingAnnotation::MUT, id, _, None) = l.pat.kind if let PatKind::Binding(BindingAnnotation::NONE | BindingAnnotation::MUT, id, _, None) = l.pat.kind
&& let ty = cx.typeck_results().expr_ty(collect_expr) && let ty = cx.typeck_results().expr_ty(collect_expr)
&& [sym::Vec, sym::VecDeque, sym::BinaryHeap, sym::LinkedList] && [sym::Vec, sym::VecDeque, sym::BinaryHeap, sym::LinkedList]

View File

@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, receiver
&& let Node::Expr(unwrap_call_expr) = cx.tcx.parent_hir_node(expr.hir_id) && let Node::Expr(unwrap_call_expr) = cx.tcx.parent_hir_node(expr.hir_id)
&& is_unwrap_call(cx, unwrap_call_expr) && is_unwrap_call(cx, unwrap_call_expr)
&& let parent = cx.tcx.parent_hir_node(unwrap_call_expr.hir_id) && let parent = cx.tcx.parent_hir_node(unwrap_call_expr.hir_id)
&& let Node::Local(local) = parent && let Node::LetStmt(local) = parent
&& let Some(mir) = enclosing_mir(cx.tcx, expr.hir_id) && let Some(mir) = enclosing_mir(cx.tcx, expr.hir_id)
&& let Some((local, _)) = mir && let Some((local, _)) = mir
.local_decls .local_decls

View File

@ -128,7 +128,7 @@ fn check_manual_split_once_indirect(
) -> Option<()> { ) -> Option<()> {
let ctxt = expr.span.ctxt(); let ctxt = expr.span.ctxt();
let mut parents = cx.tcx.hir().parent_iter(expr.hir_id); let mut parents = cx.tcx.hir().parent_iter(expr.hir_id);
if let (_, Node::Local(local)) = parents.next()? if let (_, Node::LetStmt(local)) = parents.next()?
&& let PatKind::Binding(BindingAnnotation::MUT, iter_binding_id, iter_ident, None) = local.pat.kind && let PatKind::Binding(BindingAnnotation::MUT, iter_binding_id, iter_ident, None) = local.pat.kind
&& let (iter_stmt_id, Node::Stmt(_)) = parents.next()? && let (iter_stmt_id, Node::Stmt(_)) = parents.next()?
&& let (_, Node::Block(enclosing_block)) = parents.next()? && let (_, Node::Block(enclosing_block)) = parents.next()?

View File

@ -20,7 +20,7 @@ fn needs_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
// some common cases where turbofish isn't needed: // some common cases where turbofish isn't needed:
// - assigned to a local variable with a type annotation // - assigned to a local variable with a type annotation
if let hir::Node::Local(local) = parent if let hir::Node::LetStmt(local) = parent
&& local.ty.is_some() && local.ty.is_some()
{ {
return false; return false;

View File

@ -604,7 +604,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
match get_expr_use_or_unification_node(self.cx.tcx, e) { match get_expr_use_or_unification_node(self.cx.tcx, e) {
Some((Node::Stmt(_), _)) => (), Some((Node::Stmt(_), _)) => (),
Some((Node::Local(l), _)) => { Some((Node::LetStmt(l), _)) => {
// Only trace simple bindings. e.g `let x = y;` // Only trace simple bindings. e.g `let x = y;`
if let PatKind::Binding(BindingAnnotation::NONE, id, _, None) = l.pat.kind { if let PatKind::Binding(BindingAnnotation::NONE, id, _, None) = l.pat.kind {
self.bindings.insert(id, args_idx); self.bindings.insert(id, args_idx);

View File

@ -241,7 +241,7 @@ fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'
ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some(e), ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some(e),
_ => None, _ => None,
}, },
Node::Local(local) => local.init, Node::LetStmt(local) => local.init,
_ => None, _ => None,
}; };
return init; return init;

View File

@ -159,7 +159,7 @@ fn all_bindings_are_for_conv<'tcx>(
.iter() .iter()
.map(|node| match node { .map(|node| match node {
Node::Pat(pat) => kind.eq(&pat.kind).then_some(pat.hir_id), Node::Pat(pat) => kind.eq(&pat.kind).then_some(pat.hir_id),
Node::Local(l) => Some(l.hir_id), Node::LetStmt(l) => Some(l.hir_id),
_ => None, _ => None,
}) })
.all_equal() .all_equal()
@ -170,7 +170,7 @@ fn all_bindings_are_for_conv<'tcx>(
&& local_parents.first().is_some_and(|node| { && local_parents.first().is_some_and(|node| {
let Some(ty) = match node { let Some(ty) = match node {
Node::Pat(pat) => Some(pat.hir_id), Node::Pat(pat) => Some(pat.hir_id),
Node::Local(l) => Some(l.hir_id), Node::LetStmt(l) => Some(l.hir_id),
_ => None, _ => None,
} }
.map(|hir_id| cx.typeck_results().node_type(hir_id)) else { .map(|hir_id| cx.typeck_results().node_type(hir_id)) else {

View File

@ -342,7 +342,7 @@ fn block_parents_have_safety_comment(
) -> bool { ) -> bool {
let (span, hir_id) = match cx.tcx.parent_hir_node(id) { let (span, hir_id) = match cx.tcx.parent_hir_node(id) {
Node::Expr(expr) => match cx.tcx.parent_hir_node(expr.hir_id) { Node::Expr(expr) => match cx.tcx.parent_hir_node(expr.hir_id) {
Node::Local(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), Node::LetStmt(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id),
Node::Item(hir::Item { Node::Item(hir::Item {
kind: hir::ItemKind::Const(..) | ItemKind::Static(..), kind: hir::ItemKind::Const(..) | ItemKind::Static(..),
span, span,
@ -363,7 +363,7 @@ fn block_parents_have_safety_comment(
| hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }), | hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }),
.. ..
}) })
| Node::Local(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id), | Node::LetStmt(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id),
Node::Item(hir::Item { Node::Item(hir::Item {
kind: hir::ItemKind::Const(..) | ItemKind::Static(..), kind: hir::ItemKind::Const(..) | ItemKind::Static(..),
span, span,
@ -603,7 +603,7 @@ fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
for (_, node) in map.parent_iter(body.hir_id) { for (_, node) in map.parent_iter(body.hir_id) {
match node { match node {
Node::Expr(e) => span = e.span, Node::Expr(e) => span = e.span,
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::Local(_) => (), Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (),
Node::Item(hir::Item { Node::Item(hir::Item {
kind: hir::ItemKind::Const(..) | ItemKind::Static(..), kind: hir::ItemKind::Const(..) | ItemKind::Static(..),
.. ..

View File

@ -102,7 +102,7 @@ fn expr_needs_inferred_result<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -
return false; return false;
} }
while let Some(id) = locals_to_check.pop() { while let Some(id) = locals_to_check.pop() {
if let Node::Local(l) = cx.tcx.parent_hir_node(id) { if let Node::LetStmt(l) = cx.tcx.parent_hir_node(id) {
if !l.ty.map_or(true, |ty| matches!(ty.kind, TyKind::Infer)) { if !l.ty.map_or(true, |ty| matches!(ty.kind, TyKind::Infer)) {
return false; return false;
} }

View File

@ -190,7 +190,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
}, },
} }
}, },
Node::Local(LetStmt { init: Some(init), .. }) => { Node::LetStmt(LetStmt { init: Some(init), .. }) => {
if arg_is_mut_peekable(self.cx, init) { if arg_is_mut_peekable(self.cx, init) {
self.found_peek_call = true; self.found_peek_call = true;
} }

View File

@ -1006,7 +1006,7 @@ fn get_parent_local<'hir>(cx: &LateContext<'hir>, expr: &'hir hir::Expr<'hir>) -
fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> { fn get_parent_local_hir_id<'hir>(cx: &LateContext<'hir>, hir_id: hir::HirId) -> Option<&'hir hir::Local<'hir>> {
match cx.tcx.parent_hir_node(hir_id) { match cx.tcx.parent_hir_node(hir_id) {
hir::Node::Local(local) => Some(local), hir::Node::LetStmt(local) => Some(local),
hir::Node::Pat(pattern) => get_parent_local_hir_id(cx, pattern.hir_id), hir::Node::Pat(pattern) => get_parent_local_hir_id(cx, pattern.hir_id),
_ => None, _ => None,
} }

View File

@ -217,7 +217,7 @@ fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Ve
match peel_hir_expr_refs(expr).0.kind { match peel_hir_expr_refs(expr).0.kind {
ExprKind::Path(ref qpath) => match cx.qpath_res(qpath, expr.hir_id) { ExprKind::Path(ref qpath) => match cx.qpath_res(qpath, expr.hir_id) {
Res::Local(hir_id) => { Res::Local(hir_id) => {
if let Node::Local(Local { init: Some(init), .. }) = cx.tcx.parent_hir_node(hir_id) { if let Node::LetStmt(Local { init: Some(init), .. }) = cx.tcx.parent_hir_node(hir_id) {
path_to_matched_type(cx, init) path_to_matched_type(cx, init)
} else { } else {
None None

View File

@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec {
match cx.tcx.parent_hir_node(expr.hir_id) { match cx.tcx.parent_hir_node(expr.hir_id) {
// search for `let foo = vec![_]` expressions where all uses of `foo` // search for `let foo = vec![_]` expressions where all uses of `foo`
// adjust to slices or call a method that exist on slices (e.g. len) // adjust to slices or call a method that exist on slices (e.g. len)
Node::Local(LetStmt { Node::LetStmt(LetStmt {
ty: None, ty: None,
pat: pat:
Pat { Pat {
@ -93,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec {
} }
}, },
// if the local pattern has a specified type, do not lint. // if the local pattern has a specified type, do not lint.
Node::Local(LetStmt { ty: Some(_), .. }) if higher::VecArgs::hir(cx, expr).is_some() => { Node::LetStmt(LetStmt { ty: Some(_), .. }) if higher::VecArgs::hir(cx, expr).is_some() => {
self.span_to_lint_map.insert(callsite, None); self.span_to_lint_map.insert(callsite, None);
}, },
// search for `for _ in vec![...]` // search for `for _ in vec![...]`

View File

@ -78,7 +78,7 @@ fn inner_check(cx: &LateContext<'_>, expr: &'_ rustc_hir::Expr<'_>, inner_expr:
let parent_hir_node = cx.tcx.parent_hir_node(expr.hir_id); let parent_hir_node = cx.tcx.parent_hir_node(expr.hir_id);
let return_type = cx.typeck_results().expr_ty(expr); let return_type = cx.typeck_results().expr_ty(expr);
if let Node::Local(l) = parent_hir_node { if let Node::LetStmt(l) = parent_hir_node {
array_span_lint( array_span_lint(
cx, cx,
l.span, l.span,

View File

@ -184,7 +184,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr
pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> {
if let Node::Pat(pat) = cx.tcx.hir_node(hir_id) if let Node::Pat(pat) = cx.tcx.hir_node(hir_id)
&& matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..)) && matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..))
&& let Node::Local(local) = cx.tcx.parent_hir_node(hir_id) && let Node::LetStmt(local) = cx.tcx.parent_hir_node(hir_id)
{ {
return local.init; return local.init;
} }
@ -1079,7 +1079,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
}, },
_ => break, _ => break,
}, },
Node::Local(l) => match pat_capture_kind(cx, l.pat) { Node::LetStmt(l) => match pat_capture_kind(cx, l.pat) {
CaptureKind::Value => break, CaptureKind::Value => break,
capture @ CaptureKind::Ref(_) => return capture, capture @ CaptureKind::Ref(_) => return capture,
}, },
@ -1357,7 +1357,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
ExprKind::Closure { .. } | ExprKind::Loop(..) => return Some(e), ExprKind::Closure { .. } | ExprKind::Loop(..) => return Some(e),
_ => (), _ => (),
}, },
Node::Stmt(_) | Node::Block(_) | Node::Local(_) | Node::Arm(_) => (), Node::Stmt(_) | Node::Block(_) | Node::LetStmt(_) | Node::Arm(_) => (),
_ => break, _ => break,
} }
} }
@ -1462,7 +1462,7 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
let mut child_id = expr.hir_id; let mut child_id = expr.hir_id;
for (parent_id, node) in tcx.hir().parent_iter(child_id) { for (parent_id, node) in tcx.hir().parent_iter(child_id) {
if let Node::Local(LetStmt { if let Node::LetStmt(LetStmt {
init: Some(init), init: Some(init),
els: Some(els), els: Some(els),
.. ..
@ -1482,7 +1482,7 @@ pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool { pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
let mut child_id = expr.hir_id; let mut child_id = expr.hir_id;
for (parent_id, node) in tcx.hir().parent_iter(child_id) { for (parent_id, node) in tcx.hir().parent_iter(child_id) {
if let Node::Local(LetStmt { els: Some(els), .. }) = node if let Node::LetStmt(LetStmt { els: Some(els), .. }) = node
&& els.hir_id == child_id && els.hir_id == child_id
{ {
return true; return true;
@ -2639,7 +2639,7 @@ pub struct ExprUseCtxt<'tcx> {
/// The node which consumes a value. /// The node which consumes a value.
pub enum ExprUseNode<'tcx> { pub enum ExprUseNode<'tcx> {
/// Assignment to, or initializer for, a local /// Assignment to, or initializer for, a local
Local(&'tcx LetStmt<'tcx>), LetStmt(&'tcx LetStmt<'tcx>),
/// Initializer for a const or static item. /// Initializer for a const or static item.
ConstStatic(OwnerId), ConstStatic(OwnerId),
/// Implicit or explicit return from a function. /// Implicit or explicit return from a function.
@ -2671,7 +2671,7 @@ impl<'tcx> ExprUseNode<'tcx> {
/// Gets the needed type as it's defined without any type inference. /// Gets the needed type as it's defined without any type inference.
pub fn defined_ty(&self, cx: &LateContext<'tcx>) -> Option<DefinedTy<'tcx>> { pub fn defined_ty(&self, cx: &LateContext<'tcx>) -> Option<DefinedTy<'tcx>> {
match *self { match *self {
Self::Local(LetStmt { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)), Self::LetStmt(LetStmt { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)),
Self::ConstStatic(id) => Some(DefinedTy::Mir( Self::ConstStatic(id) => Some(DefinedTy::Mir(
cx.param_env cx.param_env
.and(Binder::dummy(cx.tcx.type_of(id).instantiate_identity())), .and(Binder::dummy(cx.tcx.type_of(id).instantiate_identity())),
@ -2731,7 +2731,7 @@ impl<'tcx> ExprUseNode<'tcx> {
let sig = cx.tcx.fn_sig(id).skip_binder(); let sig = cx.tcx.fn_sig(id).skip_binder();
Some(DefinedTy::Mir(cx.tcx.param_env(id).and(sig.input(i)))) Some(DefinedTy::Mir(cx.tcx.param_env(id).and(sig.input(i))))
}, },
Self::Local(_) | Self::FieldAccess(..) | Self::Callee | Self::Expr | Self::Other => None, Self::LetStmt(_) | Self::FieldAccess(..) | Self::Callee | Self::Expr | Self::Other => None,
} }
} }
} }
@ -2770,7 +2770,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> Optio
.continue_value() .continue_value()
.map(|(use_node, child_id)| { .map(|(use_node, child_id)| {
let node = match use_node { let node = match use_node {
Node::Local(l) => ExprUseNode::Local(l), Node::LetStmt(l) => ExprUseNode::LetStmt(l),
Node::ExprField(field) => ExprUseNode::Field(field), Node::ExprField(field) => ExprUseNode::Field(field),
Node::Item(&Item { Node::Item(&Item {

View File

@ -242,7 +242,7 @@ fn path_segment_certainty(
Node::Param(..) => Certainty::Certain(None), Node::Param(..) => Certainty::Certain(None),
// A local's type is certain if its type annotation is certain or it has an initializer whose // A local's type is certain if its type annotation is certain or it has an initializer whose
// type is certain. // type is certain.
Node::Local(local) => { Node::LetStmt(local) => {
let lhs = local.ty.map_or(Certainty::Uncertain, |ty| type_certainty(cx, ty)); let lhs = local.ty.map_or(Certainty::Uncertain, |ty| type_certainty(cx, ty));
let rhs = local let rhs = local
.init .init