Rename hir::Local into hir::LetStmt

This commit is contained in:
Guillaume Gomez 2024-03-20 17:50:31 +01:00
parent b3df0d7e5e
commit b376f49e30
60 changed files with 132 additions and 132 deletions

View File

@ -81,7 +81,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
(self.arena.alloc_from_iter(stmts), expr) (self.arena.alloc_from_iter(stmts), expr)
} }
fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> { fn lower_local(&mut self, l: &Local) -> &'hir hir::LetStmt<'hir> {
let ty = l let ty = l
.ty .ty
.as_ref() .as_ref()
@ -97,7 +97,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let span = self.lower_span(l.span); let span = self.lower_span(l.span);
let source = hir::LocalSource::Normal; let source = hir::LocalSource::Normal;
self.lower_attrs(hir_id, &l.attrs); self.lower_attrs(hir_id, &l.attrs);
self.arena.alloc(hir::Local { hir_id, ty, pat, init, els, span, source }) self.arena.alloc(hir::LetStmt { hir_id, ty, pat, init, els, span, source })
} }
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode { fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {

View File

@ -302,7 +302,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}); });
} }
fn visit_local(&mut self, l: &'hir Local<'hir>) { fn visit_local(&mut self, l: &'hir LetStmt<'hir>) {
self.insert(l.span, l.hir_id, Node::Local(l)); self.insert(l.span, l.hir_id, Node::Local(l));
self.with_parent(l.hir_id, |this| { self.with_parent(l.hir_id, |this| {
intravisit::walk_local(this, l); intravisit::walk_local(this, l);

View File

@ -2341,7 +2341,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
debug_assert!(!a.is_empty()); debug_assert!(!a.is_empty());
self.attrs.insert(hir_id.local_id, a); self.attrs.insert(hir_id.local_id, a);
} }
let local = hir::Local { let local = hir::LetStmt {
hir_id, hir_id,
init, init,
pat, pat,

View File

@ -622,7 +622,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// FIXME: We make sure that this is a normal top-level binding, // FIXME: We make sure that this is a normal top-level binding,
// but we could suggest `todo!()` for all uninitalized bindings in the pattern pattern // but we could suggest `todo!()` for all uninitalized bindings in the pattern pattern
if let hir::StmtKind::Let(hir::Local { span, ty, init: None, pat, .. }) = if let hir::StmtKind::Let(hir::LetStmt { span, ty, init: None, pat, .. }) =
&ex.kind &ex.kind
&& let hir::PatKind::Binding(..) = pat.kind && let hir::PatKind::Binding(..) = pat.kind
&& span.contains(self.decl_span) && span.contains(self.decl_span)
@ -800,7 +800,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
for (_, node) in tcx.hir().parent_iter(expr.hir_id) { for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
let e = match node { let e = match node {
hir::Node::Expr(e) => e, hir::Node::Expr(e) => e,
hir::Node::Local(hir::Local { els: Some(els), .. }) => { hir::Node::Local(hir::LetStmt { els: Some(els), .. }) => {
let mut finder = BreakFinder { found_breaks: vec![], found_continues: vec![] }; let mut finder = BreakFinder { found_breaks: vec![], found_continues: vec![] };
finder.visit_block(els); finder.visit_block(els);
if !finder.found_breaks.is_empty() { if !finder.found_breaks.is_empty() {
@ -2124,7 +2124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
hir::intravisit::walk_expr(self, e); hir::intravisit::walk_expr(self, e);
} }
fn visit_local(&mut self, local: &'hir hir::Local<'hir>) { fn visit_local(&mut self, local: &'hir hir::LetStmt<'hir>) {
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } = if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } =
local.pat local.pat
&& let Some(init) = local.init && let Some(init) = local.init

View File

@ -558,7 +558,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
hir::intravisit::walk_stmt(self, stmt); hir::intravisit::walk_stmt(self, stmt);
let expr = match stmt.kind { let expr = match stmt.kind {
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr, hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
hir::StmtKind::Let(hir::Local { init: Some(expr), .. }) => expr, hir::StmtKind::Let(hir::LetStmt { init: Some(expr), .. }) => expr,
_ => { _ => {
return; return;
} }
@ -737,7 +737,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&& let body = self.infcx.tcx.hir().body(body_id) && let body = self.infcx.tcx.hir().body(body_id)
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value() && let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value()
&& let node = self.infcx.tcx.hir_node(hir_id) && let node = self.infcx.tcx.hir_node(hir_id)
&& let hir::Node::Local(hir::Local { && let hir::Node::Local(hir::LetStmt {
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. }, pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
.. ..
}) })

View File

@ -1220,7 +1220,7 @@ pub struct Stmt<'hir> {
#[derive(Debug, Clone, Copy, HashStable_Generic)] #[derive(Debug, Clone, Copy, HashStable_Generic)]
pub enum StmtKind<'hir> { pub enum StmtKind<'hir> {
/// A local (`let`) binding. /// A local (`let`) binding.
Let(&'hir Local<'hir>), Let(&'hir LetStmt<'hir>),
/// An item binding. /// An item binding.
Item(ItemId), Item(ItemId),
@ -1234,7 +1234,7 @@ pub enum StmtKind<'hir> {
/// Represents a `let` statement (i.e., `let <pat>:<ty> = <init>;`). /// Represents a `let` statement (i.e., `let <pat>:<ty> = <init>;`).
#[derive(Debug, Clone, Copy, HashStable_Generic)] #[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct Local<'hir> { pub struct LetStmt<'hir> {
pub pat: &'hir Pat<'hir>, pub pat: &'hir Pat<'hir>,
/// Type annotation, if any (otherwise the type will be inferred). /// Type annotation, if any (otherwise the type will be inferred).
pub ty: Option<&'hir Ty<'hir>>, pub ty: Option<&'hir Ty<'hir>>,
@ -1264,7 +1264,7 @@ pub struct Arm<'hir> {
pub body: &'hir Expr<'hir>, pub body: &'hir Expr<'hir>,
} }
/// Represents a `let <pat>[: <ty>] = <expr>` expression (not a [`Local`]), occurring in an `if-let` /// Represents a `let <pat>[: <ty>] = <expr>` expression (not a [`LetStmt`]), occurring in an `if-let`
/// or `let-else`, evaluating to a boolean. Typically the pattern is refutable. /// or `let-else`, evaluating to a boolean. Typically the pattern is refutable.
/// ///
/// In an `if let`, imagine it as `if (let <pat> = <expr>) { ... }`; in a let-else, it is part of /// In an `if let`, imagine it as `if (let <pat> = <expr>) { ... }`; in a let-else, it is part of
@ -1861,7 +1861,7 @@ pub enum ExprKind<'hir> {
DropTemps(&'hir Expr<'hir>), DropTemps(&'hir Expr<'hir>),
/// A `let $pat = $expr` expression. /// A `let $pat = $expr` expression.
/// ///
/// These are not `Local` and only occur as expressions. /// These are not [`LetStmt`] and only occur as expressions.
/// The `let Some(x) = foo()` in `if let Some(x) = foo()` is an example of `Let(..)`. /// The `let Some(x) = foo()` in `if let Some(x) = foo()` is an example of `Let(..)`.
Let(&'hir LetExpr<'hir>), Let(&'hir LetExpr<'hir>),
/// An `if` block, with an optional else block. /// An `if` block, with an optional else block.
@ -3529,7 +3529,7 @@ pub enum Node<'hir> {
PatField(&'hir PatField<'hir>), PatField(&'hir PatField<'hir>),
Arm(&'hir Arm<'hir>), Arm(&'hir Arm<'hir>),
Block(&'hir Block<'hir>), Block(&'hir Block<'hir>),
Local(&'hir Local<'hir>), Local(&'hir LetStmt<'hir>),
/// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants /// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants
/// with synthesized constructors. /// with synthesized constructors.
Ctor(&'hir VariantData<'hir>), Ctor(&'hir VariantData<'hir>),
@ -3757,7 +3757,7 @@ impl<'hir> Node<'hir> {
expect_pat_field, &'hir PatField<'hir>, Node::PatField(n), n; expect_pat_field, &'hir PatField<'hir>, Node::PatField(n), n;
expect_arm, &'hir Arm<'hir>, Node::Arm(n), n; expect_arm, &'hir Arm<'hir>, Node::Arm(n), n;
expect_block, &'hir Block<'hir>, Node::Block(n), n; expect_block, &'hir Block<'hir>, Node::Block(n), n;
expect_local, &'hir Local<'hir>, Node::Local(n), n; expect_local, &'hir LetStmt<'hir>, Node::Local(n), n;
expect_ctor, &'hir VariantData<'hir>, Node::Ctor(n), n; expect_ctor, &'hir VariantData<'hir>, Node::Ctor(n), n;
expect_lifetime, &'hir Lifetime, Node::Lifetime(n), n; expect_lifetime, &'hir Lifetime, Node::Lifetime(n), n;
expect_generic_param, &'hir GenericParam<'hir>, Node::GenericParam(n), n; expect_generic_param, &'hir GenericParam<'hir>, Node::GenericParam(n), n;
@ -3787,7 +3787,7 @@ mod size_asserts {
static_assert_size!(ImplItemKind<'_>, 40); static_assert_size!(ImplItemKind<'_>, 40);
static_assert_size!(Item<'_>, 88); static_assert_size!(Item<'_>, 88);
static_assert_size!(ItemKind<'_>, 56); static_assert_size!(ItemKind<'_>, 56);
static_assert_size!(Local<'_>, 64); static_assert_size!(LetStmt<'_>, 64);
static_assert_size!(Param<'_>, 32); static_assert_size!(Param<'_>, 32);
static_assert_size!(Pat<'_>, 72); static_assert_size!(Pat<'_>, 72);
static_assert_size!(Path<'_>, 40); static_assert_size!(Path<'_>, 40);

View File

@ -320,7 +320,7 @@ pub trait Visitor<'v>: Sized {
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) -> Self::Result { fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) -> Self::Result {
walk_foreign_item(self, i) walk_foreign_item(self, i)
} }
fn visit_local(&mut self, l: &'v Local<'v>) -> Self::Result { fn visit_local(&mut self, l: &'v LetStmt<'v>) -> Self::Result {
walk_local(self, l) walk_local(self, l)
} }
fn visit_block(&mut self, b: &'v Block<'v>) -> Self::Result { fn visit_block(&mut self, b: &'v Block<'v>) -> Self::Result {
@ -606,7 +606,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(
V::Result::output() V::Result::output()
} }
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) -> V::Result { pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v LetStmt<'v>) -> V::Result {
// Intentionally visiting the expr first - the initialization expr // Intentionally visiting the expr first - the initialization expr
// dominates the local's definition. // dominates the local's definition.
visit_opt!(visitor, visit_expr, local.init); visit_opt!(visitor, visit_expr, local.init);

View File

@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Arm, Block, Expr, Local, Pat, PatKind, Stmt}; use rustc_hir::{Arm, Block, Expr, LetStmt, Pat, PatKind, Stmt};
use rustc_index::Idx; use rustc_index::Idx;
use rustc_middle::middle::region::*; use rustc_middle::middle::region::*;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -123,7 +123,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
for (i, statement) in blk.stmts.iter().enumerate() { for (i, statement) in blk.stmts.iter().enumerate() {
match statement.kind { match statement.kind {
hir::StmtKind::Let(hir::Local { els: Some(els), .. }) => { hir::StmtKind::Let(LetStmt { els: Some(els), .. }) => {
// Let-else has a special lexical structure for variables. // Let-else has a special lexical structure for variables.
// First we take a checkpoint of the current scope context here. // First we take a checkpoint of the current scope context here.
let mut prev_cx = visitor.cx; let mut prev_cx = visitor.cx;
@ -855,7 +855,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
resolve_expr(self, ex); resolve_expr(self, ex);
} }
fn visit_local(&mut self, l: &'tcx Local<'tcx>) { fn visit_local(&mut self, l: &'tcx LetStmt<'tcx>) {
resolve_local(self, Some(l.pat), l.init) resolve_local(self, Some(l.pat), l.init)
} }
} }

View File

@ -1544,7 +1544,7 @@ impl<'a> State<'a> {
self.end() self.end()
} }
fn print_local_decl(&mut self, loc: &hir::Local<'_>) { fn print_local_decl(&mut self, loc: &hir::LetStmt<'_>) {
self.print_pat(loc.pat); self.print_pat(loc.pat);
if let Some(ty) = loc.ty { if let Some(ty) = loc.ty {
self.word_space(":"); self.word_space(":");

View File

@ -408,7 +408,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
} }
if let hir::Node::Local(hir::Local { ty: Some(_), pat, .. }) = node { if let hir::Node::Local(hir::LetStmt { ty: Some(_), pat, .. }) = node {
return Some((pat.span, "expected because of this assignment".to_string())); return Some((pat.span, "expected because of this assignment".to_string()));
} }
None None

View File

@ -299,8 +299,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false; return false;
}; };
let (init_ty_hir_id, init) = match self.tcx.parent_hir_node(pat.hir_id) { let (init_ty_hir_id, init) = match self.tcx.parent_hir_node(pat.hir_id) {
hir::Node::Local(hir::Local { ty: Some(ty), init, .. }) => (ty.hir_id, *init), hir::Node::Local(hir::LetStmt { ty: Some(ty), init, .. }) => (ty.hir_id, *init),
hir::Node::Local(hir::Local { init: Some(init), .. }) => (init.hir_id, Some(*init)), hir::Node::Local(hir::LetStmt { init: Some(init), .. }) => (init.hir_id, Some(*init)),
_ => return false, _ => return false,
}; };
let Some(init_ty) = self.node_ty_opt(init_ty_hir_id) else { let Some(init_ty) = self.node_ty_opt(init_ty_hir_id) else {
@ -678,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error: Option<TypeError<'tcx>>, error: Option<TypeError<'tcx>>,
) { ) {
match (self.tcx.parent_hir_node(expr.hir_id), error) { match (self.tcx.parent_hir_node(expr.hir_id), error) {
(hir::Node::Local(hir::Local { ty: Some(ty), init: Some(init), .. }), _) (hir::Node::Local(hir::LetStmt { ty: Some(ty), init: Some(init), .. }), _)
if init.hir_id == expr.hir_id => if init.hir_id == expr.hir_id =>
{ {
// Point at `let` assignment type. // Point at `let` assignment type.
@ -724,11 +724,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
primary_span = pat.span; primary_span = pat.span;
secondary_span = pat.span; secondary_span = pat.span;
match self.tcx.parent_hir_node(pat.hir_id) { match self.tcx.parent_hir_node(pat.hir_id) {
hir::Node::Local(hir::Local { ty: Some(ty), .. }) => { hir::Node::Local(hir::LetStmt { ty: Some(ty), .. }) => {
primary_span = ty.span; primary_span = ty.span;
post_message = " type"; post_message = " type";
} }
hir::Node::Local(hir::Local { init: Some(init), .. }) => { hir::Node::Local(hir::LetStmt { init: Some(init), .. }) => {
primary_span = init.span; primary_span = init.span;
post_message = " value"; post_message = " value";
} }

View File

@ -1452,7 +1452,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}); });
let Some(( let Some((
_, _,
hir::Node::Local(hir::Local { ty: Some(ty), .. }) hir::Node::Local(hir::LetStmt { ty: Some(ty), .. })
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. }), | hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. }),
)) = parent_node )) = parent_node
else { else {

View File

@ -371,7 +371,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
fn walk_stmt(&mut self, stmt: &hir::Stmt<'_>) { fn walk_stmt(&mut self, stmt: &hir::Stmt<'_>) {
match stmt.kind { match stmt.kind {
hir::StmtKind::Let(hir::Local { pat, init: Some(expr), els, .. }) => { hir::StmtKind::Let(hir::LetStmt { pat, init: Some(expr), els, .. }) => {
self.walk_local(expr, pat, *els, |_| {}) self.walk_local(expr, pat, *els, |_| {})
} }

View File

@ -1602,7 +1602,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
/// Type check a `let` statement. /// Type check a `let` statement.
pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) { pub fn check_decl_local(&self, local: &'tcx hir::LetStmt<'tcx>) {
self.check_decl(local.into()); self.check_decl(local.into());
if local.pat.is_never_pattern() { if local.pat.is_never_pattern() {
self.diverges.set(Diverges::Always { self.diverges.set(Diverges::Always {
@ -1790,7 +1790,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
[ [
hir::Stmt { hir::Stmt {
kind: kind:
hir::StmtKind::Let(hir::Local { hir::StmtKind::Let(hir::LetStmt {
source: source:
hir::LocalSource::AssignDesugar(_), hir::LocalSource::AssignDesugar(_),
.. ..

View File

@ -1731,7 +1731,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match self.tcx.parent_hir_node(*hir_id) { match self.tcx.parent_hir_node(*hir_id) {
// foo.clone() // foo.clone()
hir::Node::Local(hir::Local { init: Some(init), .. }) => { hir::Node::Local(hir::LetStmt { init: Some(init), .. }) => {
self.note_type_is_not_clone_inner_expr(init) self.note_type_is_not_clone_inner_expr(init)
} }
// When `expr` is more complex like a tuple // When `expr` is more complex like a tuple
@ -1740,7 +1740,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
kind: hir::PatKind::Tuple(pats, ..), kind: hir::PatKind::Tuple(pats, ..),
.. ..
}) => { }) => {
let hir::Node::Local(hir::Local { init: Some(init), .. }) = let hir::Node::Local(hir::LetStmt { init: Some(init), .. }) =
self.tcx.parent_hir_node(*pat_hir_id) self.tcx.parent_hir_node(*pat_hir_id)
else { else {
return expr; return expr;
@ -1774,7 +1774,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let hir::Path { segments: [_], res: crate::Res::Local(binding), .. } = && let hir::Path { segments: [_], res: crate::Res::Local(binding), .. } =
call_expr_path call_expr_path
&& let hir::Node::Pat(hir::Pat { hir_id, .. }) = self.tcx.hir_node(*binding) && let hir::Node::Pat(hir::Pat { hir_id, .. }) = self.tcx.hir_node(*binding)
&& let hir::Node::Local(hir::Local { init: Some(init), .. }) = && let hir::Node::Local(hir::LetStmt { init: Some(init), .. }) =
self.tcx.parent_hir_node(*hir_id) self.tcx.parent_hir_node(*hir_id)
&& let Expr { && let Expr {
kind: hir::ExprKind::Closure(hir::Closure { body: body_id, .. }), kind: hir::ExprKind::Closure(hir::Closure { body: body_id, .. }),
@ -3134,7 +3134,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let hir::Node::Pat(pat) = self.tcx.hir_node(hir_id) else { let hir::Node::Pat(pat) = self.tcx.hir_node(hir_id) else {
return; return;
}; };
let hir::Node::Local(hir::Local { ty: None, init: Some(init), .. }) = let hir::Node::Local(hir::LetStmt { ty: None, init: Some(init), .. }) =
self.tcx.parent_hir_node(pat.hir_id) self.tcx.parent_hir_node(pat.hir_id)
else { else {
return; return;

View File

@ -29,7 +29,7 @@ impl<'a> DeclOrigin<'a> {
} }
} }
/// A declaration is an abstraction of [hir::Local] and [hir::LetExpr]. /// A declaration is an abstraction of [hir::LetStmt] and [hir::LetExpr].
/// ///
/// It must have a hir_id, as this is how we connect gather_locals to the check functions. /// It must have a hir_id, as this is how we connect gather_locals to the check functions.
pub(super) struct Declaration<'a> { pub(super) struct Declaration<'a> {
@ -41,9 +41,9 @@ pub(super) struct Declaration<'a> {
pub origin: DeclOrigin<'a>, pub origin: DeclOrigin<'a>,
} }
impl<'a> From<&'a hir::Local<'a>> for Declaration<'a> { impl<'a> From<&'a hir::LetStmt<'a>> for Declaration<'a> {
fn from(local: &'a hir::Local<'a>) -> Self { fn from(local: &'a hir::LetStmt<'a>) -> Self {
let hir::Local { hir_id, pat, ty, span, init, els, source: _ } = *local; let hir::LetStmt { hir_id, pat, ty, span, init, els, source: _ } = *local;
Declaration { hir_id, pat, ty, span, init, origin: DeclOrigin::LocalDecl { els } } Declaration { hir_id, pat, ty, span, init, origin: DeclOrigin::LocalDecl { els } }
} }
} }
@ -120,7 +120,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
// Add explicitly-declared locals. // Add explicitly-declared locals.
fn visit_local(&mut self, local: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) {
self.declare(local.into()); self.declare(local.into());
intravisit::walk_local(self, local) intravisit::walk_local(self, local)
} }

View File

@ -2166,7 +2166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match (filename, parent_node) { match (filename, parent_node) {
( (
FileName::Real(_), FileName::Real(_),
Node::Local(hir::Local { Node::Local(hir::LetStmt {
source: hir::LocalSource::Normal, source: hir::LocalSource::Normal,
ty, ty,
.. ..
@ -2221,7 +2221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
impl<'v> Visitor<'v> for LetVisitor { impl<'v> Visitor<'v> for LetVisitor {
type Result = ControlFlow<Option<&'v hir::Expr<'v>>>; type Result = ControlFlow<Option<&'v hir::Expr<'v>>>;
fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) -> Self::Result { fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) -> Self::Result {
if let hir::StmtKind::Let(&hir::Local { pat, init, .. }) = ex.kind if let hir::StmtKind::Let(&hir::LetStmt { pat, init, .. }) = ex.kind
&& let Binding(_, _, ident, ..) = pat.kind && let Binding(_, _, ident, ..) = pat.kind
&& ident.name == self.ident_name && ident.name == self.ident_name
{ {

View File

@ -217,7 +217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
bug!(); bug!();
}; };
for stmt in block.stmts { for stmt in block.stmts {
let hir::StmtKind::Let(hir::Local { let hir::StmtKind::Let(hir::LetStmt {
init: Some(init), init: Some(init),
source: hir::LocalSource::AsyncFn, source: hir::LocalSource::AsyncFn,
pat, pat,

View File

@ -351,7 +351,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
intravisit::walk_pat(self, p); intravisit::walk_pat(self, p);
} }
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, l: &'tcx hir::LetStmt<'tcx>) {
intravisit::walk_local(self, l); intravisit::walk_local(self, l);
let var_ty = self.fcx.local_ty(l.span, l.hir_id); let var_ty = self.fcx.local_ty(l.span, l.hir_id);
let var_ty = self.resolve(var_ty, &l.span); let var_ty = self.resolve(var_ty, &l.span);

View File

@ -2140,7 +2140,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// the same span as the error and the type is specified. // the same span as the error and the type is specified.
if let hir::Stmt { if let hir::Stmt {
kind: kind:
hir::StmtKind::Let(hir::Local { hir::StmtKind::Let(hir::LetStmt {
init: Some(hir::Expr { span: init_span, .. }), init: Some(hir::Expr { span: init_span, .. }),
ty: Some(array_ty), ty: Some(array_ty),
.. ..

View File

@ -11,7 +11,7 @@ use rustc_hir::def::Res;
use rustc_hir::def::{CtorOf, DefKind, Namespace}; use rustc_hir::def::{CtorOf, DefKind, Namespace};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, Local, LocalSource}; use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::infer::unify_key::{ use rustc_middle::infer::unify_key::{
ConstVariableOrigin, ConstVariableOriginKind, ConstVariableValue, ConstVariableOrigin, ConstVariableOriginKind, ConstVariableValue,
@ -1122,7 +1122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
self.tecx.tcx.hir() self.tecx.tcx.hir()
} }
fn visit_local(&mut self, local: &'tcx Local<'tcx>) { fn visit_local(&mut self, local: &'tcx LetStmt<'tcx>) {
intravisit::walk_local(self, local); intravisit::walk_local(self, local);
if let Some(ty) = self.opt_node_type(local.hir_id) { if let Some(ty) = self.opt_node_type(local.hir_id) {

View File

@ -2,7 +2,7 @@ use crate::infer::error_reporting::hir::Path;
use core::ops::ControlFlow; use core::ops::ControlFlow;
use hir::def::CtorKind; use hir::def::CtorKind;
use hir::intravisit::{walk_expr, walk_stmt, Visitor}; use hir::intravisit::{walk_expr, walk_stmt, Visitor};
use hir::{Local, QPath}; use hir::{LetStmt, QPath};
use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{Applicability, Diag}; use rustc_errors::{Applicability, Diag};
use rustc_hir as hir; use rustc_hir as hir;
@ -321,7 +321,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
&& let Some(expr) = block.expr && let Some(expr) = block.expr
&& let hir::ExprKind::Path(QPath::Resolved(_, Path { res, .. })) = expr.kind && let hir::ExprKind::Path(QPath::Resolved(_, Path { res, .. })) = expr.kind
&& let Res::Local(local) = res && let Res::Local(local) = res
&& let Node::Local(Local { init: Some(init), .. }) = self.tcx.parent_hir_node(*local) && let Node::Local(LetStmt { init: Some(init), .. }) = self.tcx.parent_hir_node(*local)
{ {
fn collect_blocks<'hir>(expr: &hir::Expr<'hir>, blocks: &mut Vec<&hir::Block<'hir>>) { fn collect_blocks<'hir>(expr: &hir::Expr<'hir>, blocks: &mut Vec<&hir::Block<'hir>>) {
match expr.kind { match expr.kind {
@ -585,7 +585,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) -> Self::Result { fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) -> Self::Result {
if let hir::StmtKind::Let(hir::Local { if let hir::StmtKind::Let(LetStmt {
span, span,
pat: hir::Pat { .. }, pat: hir::Pat { .. },
ty: None, ty: None,

View File

@ -937,7 +937,7 @@ impl<'tcx> LateContext<'tcx> {
} }
&& let Some(init) = match parent_node { && let Some(init) = match parent_node {
hir::Node::Expr(expr) => Some(expr), hir::Node::Expr(expr) => Some(expr),
hir::Node::Local(hir::Local { init, .. }) => *init, hir::Node::Local(hir::LetStmt { init, .. }) => *init,
_ => None, _ => None,
} }
{ {
@ -982,7 +982,7 @@ impl<'tcx> LateContext<'tcx> {
} }
&& let Some(init) = match parent_node { && let Some(init) = match parent_node {
hir::Node::Expr(expr) => Some(expr), hir::Node::Expr(expr) => Some(expr),
hir::Node::Local(hir::Local { init, .. }) => *init, hir::Node::Local(hir::LetStmt { init, .. }) => *init,
hir::Node::Item(item) => match item.kind { hir::Node::Item(item) => match item.kind {
hir::ItemKind::Const(.., body_id) | hir::ItemKind::Static(.., body_id) => { hir::ItemKind::Const(.., body_id) | hir::ItemKind::Static(.., body_id) => {
Some(self.tcx.hir().body(body_id).value) Some(self.tcx.hir().body(body_id).value)

View File

@ -238,7 +238,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
} }
} }
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, l: &'tcx hir::LetStmt<'tcx>) {
self.with_lint_attrs(l.hir_id, |cx| { self.with_lint_attrs(l.hir_id, |cx| {
lint_callback!(cx, check_local, l); lint_callback!(cx, check_local, l);
hir_visit::walk_local(cx, l); hir_visit::walk_local(cx, l);

View File

@ -105,7 +105,7 @@ const SYNC_GUARD_SYMBOLS: [Symbol; 3] = [
impl<'tcx> LateLintPass<'tcx> for LetUnderscore { impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) {
if matches!(local.source, rustc_hir::LocalSource::AsyncFn) { if matches!(local.source, rustc_hir::LocalSource::AsyncFn) {
return; return;
} }

View File

@ -354,7 +354,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
intravisit::walk_variant(self, v); intravisit::walk_variant(self, v);
} }
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, l: &'tcx hir::LetStmt<'tcx>) {
self.add_id(l.hir_id); self.add_id(l.hir_id);
intravisit::walk_local(self, l); intravisit::walk_local(self, l);
} }
@ -428,7 +428,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'
intravisit::walk_variant(self, v); intravisit::walk_variant(self, v);
} }
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, l: &'tcx hir::LetStmt<'tcx>) {
self.add_id(l.hir_id); self.add_id(l.hir_id);
intravisit::walk_local(self, l); intravisit::walk_local(self, l);
} }

View File

@ -15,7 +15,7 @@ macro_rules! late_lint_methods {
fn check_foreign_item(a: &'tcx rustc_hir::ForeignItem<'tcx>); fn check_foreign_item(a: &'tcx rustc_hir::ForeignItem<'tcx>);
fn check_item(a: &'tcx rustc_hir::Item<'tcx>); fn check_item(a: &'tcx rustc_hir::Item<'tcx>);
fn check_item_post(a: &'tcx rustc_hir::Item<'tcx>); fn check_item_post(a: &'tcx rustc_hir::Item<'tcx>);
fn check_local(a: &'tcx rustc_hir::Local<'tcx>); fn check_local(a: &'tcx rustc_hir::LetStmt<'tcx>);
fn check_block(a: &'tcx rustc_hir::Block<'tcx>); fn check_block(a: &'tcx rustc_hir::Block<'tcx>);
fn check_block_post(a: &'tcx rustc_hir::Block<'tcx>); fn check_block_post(a: &'tcx rustc_hir::Block<'tcx>);
fn check_stmt(a: &'tcx rustc_hir::Stmt<'tcx>); fn check_stmt(a: &'tcx rustc_hir::Stmt<'tcx>);

View File

@ -46,7 +46,7 @@ declare_lint! {
declare_lint_pass!(UnitBindings => [UNIT_BINDINGS]); declare_lint_pass!(UnitBindings => [UNIT_BINDINGS]);
impl<'tcx> LateLintPass<'tcx> for UnitBindings { impl<'tcx> LateLintPass<'tcx> for UnitBindings {
fn check_local(&mut self, cx: &crate::LateContext<'tcx>, local: &'tcx hir::Local<'tcx>) { fn check_local(&mut self, cx: &crate::LateContext<'tcx>, local: &'tcx hir::LetStmt<'tcx>) {
// Suppress warning if user: // Suppress warning if user:
// - explicitly ascribes a type to the pattern // - explicitly ascribes a type to the pattern
// - explicitly wrote `let pat = ();` // - explicitly wrote `let pat = ();`

View File

@ -264,7 +264,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
hir_visit::walk_foreign_item(self, i) hir_visit::walk_foreign_item(self, i)
} }
fn visit_local(&mut self, l: &'v hir::Local<'v>) { fn visit_local(&mut self, l: &'v hir::LetStmt<'v>) {
self.record("Local", Id::Node(l.hir_id), l); self.record("Local", Id::Node(l.hir_id), l);
hir_visit::walk_local(self, l) hir_visit::walk_local(self, l)
} }

View File

@ -342,7 +342,7 @@ impl<'tcx> IrMaps<'tcx> {
} }
impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
fn visit_local(&mut self, local: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) {
self.add_from_pat(local.pat); self.add_from_pat(local.pat);
if local.els.is_some() { if local.els.is_some() {
self.add_live_node_for_node(local.hir_id, ExprNode(local.span, local.hir_id)); self.add_live_node_for_node(local.hir_id, ExprNode(local.span, local.hir_id));
@ -1350,7 +1350,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// Checking for error conditions // Checking for error conditions
impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> {
fn visit_local(&mut self, local: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) {
self.check_unused_vars_in_pat(local.pat, None, None, |spans, hir_id, ln, var| { self.check_unused_vars_in_pat(local.pat, None, None, |spans, hir_id, ln, var| {
if local.init.is_some() { if local.init.is_some() {
self.warn_about_dead_assign(spans, hir_id, ln, var); self.warn_about_dead_assign(spans, hir_id, ln, var);

View File

@ -1209,7 +1209,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
intravisit::walk_pat(self, pattern); intravisit::walk_pat(self, pattern);
} }
fn visit_local(&mut self, local: &'tcx hir::Local<'tcx>) { fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) {
if let Some(init) = local.init { if let Some(init) = local.init {
if self.check_expr_pat_type(init.hir_id, init.span) { if self.check_expr_pat_type(init.hir_id, init.span) {
// Do not report duplicate errors for `let x = y`. // Do not report duplicate errors for `let x = y`.

View File

@ -930,7 +930,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let hir::Node::Pat(pat) = self.tcx.hir_node(hir_id) else { let hir::Node::Pat(pat) = self.tcx.hir_node(hir_id) else {
return; return;
}; };
let hir::Node::Local(hir::Local { ty: None, init: Some(init), .. }) = let hir::Node::Local(hir::LetStmt { ty: None, init: Some(init), .. }) =
self.tcx.parent_hir_node(pat.hir_id) self.tcx.parent_hir_node(pat.hir_id)
else { else {
return; return;
@ -2966,7 +2966,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
err.downgrade_to_delayed_bug(); err.downgrade_to_delayed_bug();
} }
match tcx.parent_hir_node(hir_id) { match tcx.parent_hir_node(hir_id) {
Node::Local(hir::Local { ty: Some(ty), .. }) => { Node::Local(hir::LetStmt { ty: Some(ty), .. }) => {
err.span_suggestion_verbose( err.span_suggestion_verbose(
ty.span.shrink_to_lo(), ty.span.shrink_to_lo(),
"consider borrowing here", "consider borrowing here",
@ -2975,7 +2975,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
); );
err.note("all local variables must have a statically known size"); err.note("all local variables must have a statically known size");
} }
Node::Local(hir::Local { Node::Local(hir::LetStmt {
init: Some(hir::Expr { kind: hir::ExprKind::Index(..), span, .. }), init: Some(hir::Expr { kind: hir::ExprKind::Index(..), span, .. }),
.. ..
}) => { }) => {

View File

@ -6,7 +6,7 @@ use clippy_utils::{is_default_equivalent, path_def_id};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::intravisit::{walk_ty, Visitor};
use rustc_hir::{Block, Expr, ExprKind, Local, Node, QPath, Ty, TyKind}; use rustc_hir::{Block, Expr, ExprKind, LetStmt, Node, QPath, Ty, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::print::with_forced_trimmed_paths;
@ -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(Local { ty: Some(ty), .. }) => { Node::Local(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

@ -3,7 +3,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
use clippy_utils::visitors::for_each_expr_with_closures; use clippy_utils::visitors::for_each_expr_with_closures;
use clippy_utils::{get_enclosing_block, path_to_local_id}; use clippy_utils::{get_enclosing_block, path_to_local_id};
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_hir::{Block, ExprKind, HirId, LangItem, Local, Node, PatKind}; use rustc_hir::{Block, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -58,7 +58,7 @@ static COLLECTIONS: [Symbol; 9] = [
]; ];
impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead { impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
// Look for local variables whose type is a container. Search surrounding bock for read access. // Look for local variables whose type is a container. Search surrounding bock for read access.
if match_acceptable_type(cx, local, &COLLECTIONS) if match_acceptable_type(cx, local, &COLLECTIONS)
&& let PatKind::Binding(_, local_id, _, _) = local.pat.kind && let PatKind::Binding(_, local_id, _, _) = local.pat.kind
@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
} }
} }
fn match_acceptable_type(cx: &LateContext<'_>, local: &Local<'_>, collections: &[rustc_span::Symbol]) -> bool { fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>, collections: &[rustc_span::Symbol]) -> bool {
let ty = cx.typeck_results().pat_ty(local.pat); let ty = cx.typeck_results().pat_ty(local.pat);
collections.iter().any(|&sym| is_type_diagnostic_item(cx, ty, sym)) collections.iter().any(|&sym| is_type_diagnostic_item(cx, ty, sym))
// String type is a lang item but not a diagnostic item for now so we need a separate check // String type is a lang item but not a diagnostic item for now so we need a separate check

View File

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type}; use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths}; use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths};
use rustc_hir::{Local, LocalSource, PatKind}; use rustc_hir::{LetStmt, LocalSource, PatKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{GenericArgKind, IsSuggestable}; use rustc_middle::ty::{GenericArgKind, IsSuggestable};
@ -138,7 +138,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
]; ];
impl<'tcx> LateLintPass<'tcx> for LetUnderscore { impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) {
if matches!(local.source, LocalSource::Normal) if matches!(local.source, LocalSource::Normal)
&& !in_external_macro(cx.tcx.sess, local.span) && !in_external_macro(cx.tcx.sess, local.span)
&& let PatKind::Wild = local.pat.kind && let PatKind::Wild = local.pat.kind

View File

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::source::snippet; use clippy_utils::source::snippet;
use rustc_hir::{Local, TyKind}; use rustc_hir::{LetStmt, TyKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -26,7 +26,7 @@ declare_clippy_lint! {
declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]); declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
impl LateLintPass<'_> for UnderscoreTyped { impl LateLintPass<'_> for UnderscoreTyped {
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) {
if !in_external_macro(cx.tcx.sess, local.span) if !in_external_macro(cx.tcx.sess, local.span)
&& let Some(ty) = local.ty // Ensure that it has a type defined && let Some(ty) = local.ty // Ensure that it has a type defined
&& let TyKind::Infer = &ty.kind // that type is '_' && let TyKind::Infer = &ty.kind // that type is '_'

View File

@ -3,7 +3,7 @@ use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_loc
use rustc_ast::ast::{LitIntType, LitKind}; use rustc_ast::ast::{LitIntType, LitKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_expr, walk_local, Visitor}; use rustc_hir::intravisit::{walk_expr, walk_local, Visitor};
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, PatKind}; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
@ -141,7 +141,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn visit_local(&mut self, l: &'tcx Local<'_>) { fn visit_local(&mut self, l: &'tcx LetStmt<'_>) {
// Look for declarations of the variable // Look for declarations of the variable
if l.pat.hir_id == self.var_id if l.pat.hir_id == self.var_id
&& let PatKind::Binding(.., ident, _) = l.pat.kind && let PatKind::Binding(.., ident, _) = l.pat.kind

View File

@ -5,13 +5,13 @@ use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::needs_ordered_drop; use clippy_utils::ty::needs_ordered_drop;
use clippy_utils::visitors::any_temporaries_need_ordered_drop; use clippy_utils::visitors::any_temporaries_need_ordered_drop;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Block, Expr, ExprKind, Local, MatchSource, Pat, StmtKind}; use rustc_hir::{Block, Expr, ExprKind, LetStmt, MatchSource, Pat, StmtKind};
use rustc_lint::LateContext; use rustc_lint::LateContext;
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) { pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) { let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) {
([stmt, stmts @ ..], expr) => { ([stmt, stmts @ ..], expr) => {
if let StmtKind::Let(&Local { if let StmtKind::Let(&LetStmt {
init: Some(e), init: Some(e),
els: None, els: None,
.. ..

View File

@ -6,7 +6,7 @@ use clippy_utils::{get_enclosing_loop_or_multi_call_closure, higher, is_refutabl
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{Closure, Expr, ExprKind, HirId, LangItem, Local, Mutability, PatKind, UnOp}; use rustc_hir::{Closure, Expr, ExprKind, HirId, LangItem, LetStmt, Mutability, PatKind, UnOp};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::adjustment::Adjust;
@ -286,7 +286,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
self.cx.tcx.hir() self.cx.tcx.hir()
} }
fn visit_local(&mut self, l: &'tcx Local<'_>) { fn visit_local(&mut self, l: &'tcx LetStmt<'_>) {
if !self.after_loop { if !self.after_loop {
l.pat.each_binding_or_first(&mut |_, id, _, _| { l.pat.each_binding_or_first(&mut |_, id, _, _| {
if id == self.local_id { if id == self.local_id {

View File

@ -4,7 +4,7 @@ use clippy_utils::source::snippet_opt;
use clippy_utils::visitors::{is_local_used, local_used_once}; use clippy_utils::visitors::{is_local_used, local_used_once};
use clippy_utils::{is_trait_method, path_to_local_id}; use clippy_utils::{is_trait_method, path_to_local_id};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, ExprKind, Local, Node, PatKind, StmtKind}; use rustc_hir::{BindingAnnotation, ExprKind, LetStmt, Node, PatKind, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
use rustc_span::sym; use rustc_span::sym;
@ -60,7 +60,7 @@ impl ManualHashOne {
impl_lint_pass!(ManualHashOne => [MANUAL_HASH_ONE]); impl_lint_pass!(ManualHashOne => [MANUAL_HASH_ONE]);
impl LateLintPass<'_> for ManualHashOne { impl LateLintPass<'_> for ManualHashOne {
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) { fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) {
// `let mut hasher = seg.build_hasher();` // `let mut hasher = seg.build_hasher();`
if let PatKind::Binding(BindingAnnotation::MUT, hasher, _, None) = local.pat.kind if let PatKind::Binding(BindingAnnotation::MUT, hasher, _, None) = local.pat.kind
&& let Some(init) = local.init && let Some(init) = local.init

View File

@ -2,12 +2,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability; use clippy_utils::source::snippet_with_applicability;
use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs}; use clippy_utils::{path_to_local_id, peel_blocks, strip_pat_refs};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{ByRef, ExprKind, Local, MatchSource, PatKind, QPath}; use rustc_hir::{ByRef, ExprKind, LetStmt, MatchSource, PatKind, QPath};
use rustc_lint::LateContext; use rustc_lint::LateContext;
use super::INFALLIBLE_DESTRUCTURING_MATCH; use super::INFALLIBLE_DESTRUCTURING_MATCH;
pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool { pub(crate) fn check(cx: &LateContext<'_>, local: &LetStmt<'_>) -> bool {
if !local.span.from_expansion() if !local.span.from_expansion()
&& let Some(expr) = local.init && let Some(expr) = local.init
&& let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind && let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind

View File

@ -27,7 +27,7 @@ mod wild_in_or_pats;
use clippy_config::msrvs::{self, Msrv}; use clippy_config::msrvs::{self, Msrv};
use clippy_utils::source::{snippet_opt, walk_span_to_context}; use clippy_utils::source::{snippet_opt, walk_span_to_context};
use clippy_utils::{higher, in_constant, is_direct_expn_of, is_span_match, tokenize_with_text}; use clippy_utils::{higher, in_constant, is_direct_expn_of, is_span_match, tokenize_with_text};
use rustc_hir::{Arm, Expr, ExprKind, Local, MatchSource, Pat}; use rustc_hir::{Arm, Expr, ExprKind, LetStmt, MatchSource, Pat};
use rustc_lexer::TokenKind; use rustc_lexer::TokenKind;
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
@ -1124,7 +1124,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
} }
} }
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
self.infallible_destructuring_match_linted |= self.infallible_destructuring_match_linted |=
local.els.is_none() && infallible_destructuring_match::check(cx, local); local.els.is_none() && infallible_destructuring_match::check(cx, local);
} }

View File

@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Applicability, MultiSpan}; use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, Local, Mutability, Node, PatKind, Stmt, StmtKind, BindingAnnotation, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Mutability, Node, PatKind, Stmt, StmtKind,
}; };
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
@ -424,7 +424,7 @@ fn get_expr_and_hir_id_from_stmt<'v>(stmt: &'v Stmt<'v>) -> Option<(&'v Expr<'v>
match stmt.kind { match stmt.kind {
StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some((expr, None)), StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some((expr, None)),
StmtKind::Item(..) => None, StmtKind::Item(..) => None,
StmtKind::Let(Local { init, pat, .. }) => { StmtKind::Let(LetStmt { init, pat, .. }) => {
if let PatKind::Binding(_, hir_id, ..) = pat.kind { if let PatKind::Binding(_, hir_id, ..) = pat.kind {
init.map(|init_expr| (init_expr, Some(hir_id))) init.map(|init_expr| (init_expr, Some(hir_id)))
} else { } else {

View File

@ -8,7 +8,7 @@ use clippy_utils::{is_diag_item_method, match_def_path, path_to_local_id, paths}
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Expr, ExprKind, HirId, LangItem, Local, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind, BindingAnnotation, Expr, ExprKind, HirId, LangItem, LetStmt, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind,
}; };
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_middle::ty; use rustc_middle::ty;
@ -198,7 +198,7 @@ fn indirect_usage<'tcx>(
binding: HirId, binding: HirId,
ctxt: SyntaxContext, ctxt: SyntaxContext,
) -> Option<IndirectUsage<'tcx>> { ) -> Option<IndirectUsage<'tcx>> {
if let StmtKind::Let(&Local { if let StmtKind::Let(&LetStmt {
pat: Pat { pat: Pat {
kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None), kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None),
.. ..

View File

@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id}; use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Local, Node, Stmt, StmtKind}; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, LetStmt, Node, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty; use rustc_middle::ty;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
match stmt.kind { match stmt.kind {
StmtKind::Let(local) => { StmtKind::Let(local) => {
if let Local { init: Some(e), .. } = local { if let LetStmt { init: Some(e), .. } = local {
DivergenceVisitor { cx }.visit_expr(e); DivergenceVisitor { cx }.visit_expr(e);
} }
}, },

View File

@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
} }
} }
fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::Local<'_>) { fn check_local(&mut self, cx: &LateContext<'_>, local: &hir::LetStmt<'_>) {
if let hir::PatKind::Wild = local.pat.kind { if let hir::PatKind::Wild = local.pat.kind {
return; return;
} }

View File

@ -6,7 +6,7 @@ use clippy_utils::visitors::{for_each_expr, for_each_expr_with_closures, is_loca
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_errors::{Applicability, MultiSpan}; use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, Expr, ExprKind, HirId, Local, LocalSource, MatchSource, Node, Pat, PatKind, Stmt, BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, LocalSource, MatchSource, Node, Pat, PatKind, Stmt,
StmtKind, StmtKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -237,7 +237,7 @@ fn first_usage<'tcx>(
}) })
} }
fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &Local<'_>) -> Option<String> { fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &LetStmt<'_>) -> Option<String> {
let span = local.span.with_hi(match local.ty { let span = local.span.with_hi(match local.ty {
// let <pat>: <ty>; // let <pat>: <ty>;
// ~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~
@ -252,7 +252,7 @@ fn local_snippet_without_semicolon(cx: &LateContext<'_>, local: &Local<'_>) -> O
fn check<'tcx>( fn check<'tcx>(
cx: &LateContext<'tcx>, cx: &LateContext<'tcx>,
local: &'tcx Local<'tcx>, local: &'tcx LetStmt<'tcx>,
local_stmt: &'tcx Stmt<'tcx>, local_stmt: &'tcx Stmt<'tcx>,
block: &'tcx Block<'tcx>, block: &'tcx Block<'tcx>,
binding_id: HirId, binding_id: HirId,
@ -363,9 +363,9 @@ fn check<'tcx>(
} }
impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit { impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
let mut parents = cx.tcx.hir().parent_iter(local.hir_id); let mut parents = cx.tcx.hir().parent_iter(local.hir_id);
if let Local { if let LetStmt {
init: None, init: None,
pat: pat:
&Pat { &Pat {

View File

@ -14,7 +14,7 @@ use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk};
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, ByRef, Expr, ExprKind, Local, Node, PatKind, PathSegment, QPath, Stmt, StmtKind, BindingAnnotation, Block, ByRef, Expr, ExprKind, LetStmt, Node, PatKind, PathSegment, QPath, Stmt, StmtKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
@ -109,7 +109,7 @@ fn find_let_else_ret_expression<'hir>(block: &'hir Block<'hir>) -> Option<&'hir
} }
fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) { fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
if let StmtKind::Let(Local { if let StmtKind::Let(LetStmt {
pat, pat,
init: Some(init_expr), init: Some(init_expr),
els: Some(els), els: Some(els),

View File

@ -3,7 +3,7 @@ use clippy_utils::get_enclosing_block;
use clippy_utils::higher::{get_vec_init_kind, VecInitKind}; use clippy_utils::higher::{get_vec_init_kind, VecInitKind};
use clippy_utils::source::snippet; use clippy_utils::source::snippet;
use hir::{Expr, ExprKind, HirId, Local, PatKind, PathSegment, QPath, StmtKind}; use hir::{Expr, ExprKind, HirId, LetStmt, PatKind, PathSegment, QPath, StmtKind};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::Res; use rustc_hir::def::Res;
@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec {
} }
if let StmtKind::Let(local) = stmt.kind if let StmtKind::Let(local) = stmt.kind
&& let Local { && let LetStmt {
pat, init: Some(init), .. pat, init: Some(init), ..
} = local } = local
&& let PatKind::Binding(_, id, ident, _) = pat.kind && let PatKind::Binding(_, id, ident, _) = pat.kind

View File

@ -3,7 +3,7 @@ use clippy_utils::is_from_proc_macro;
use clippy_utils::ty::needs_ordered_drop; use clippy_utils::ty::needs_ordered_drop;
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, Local, Node, Pat, PatKind, QPath}; use rustc_hir::{BindingAnnotation, ByRef, ExprKind, HirId, LetStmt, Node, Pat, PatKind, QPath};
use rustc_hir_typeck::expr_use_visitor::PlaceBase; use rustc_hir_typeck::expr_use_visitor::PlaceBase;
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
@ -47,7 +47,7 @@ declare_clippy_lint! {
declare_lint_pass!(RedundantLocals => [REDUNDANT_LOCALS]); declare_lint_pass!(RedundantLocals => [REDUNDANT_LOCALS]);
impl<'tcx> LateLintPass<'tcx> for RedundantLocals { impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if !local.span.is_desugaring(DesugaringKind::Async) if !local.span.is_desugaring(DesugaringKind::Async)
// the pattern is a single by-value binding // the pattern is a single by-value binding
&& let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind && let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind

View File

@ -131,7 +131,7 @@ fn extract_primty(ty_kind: &hir::TyKind<'_>) -> Option<hir::PrimTy> {
} }
impl LateLintPass<'_> for RedundantTypeAnnotations { impl LateLintPass<'_> for RedundantTypeAnnotations {
fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx rustc_hir::Local<'tcx>) { fn check_local<'tcx>(&mut self, cx: &LateContext<'tcx>, local: &'tcx rustc_hir::LetStmt<'tcx>) {
if !is_lint_allowed(cx, REDUNDANT_TYPE_ANNOTATIONS, local.hir_id) if !is_lint_allowed(cx, REDUNDANT_TYPE_ANNOTATIONS, local.hir_id)
// type annotation part // type annotation part
&& !local.span.from_expansion() && !local.span.from_expansion()

View File

@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
use clippy_utils::{is_from_proc_macro, path_to_local_id}; use clippy_utils::{is_from_proc_macro, path_to_local_id};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, Local, PatKind, QPath, Stmt, StmtKind}; use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass; use rustc_session::impl_lint_pass;
@ -69,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for ReserveAfterInitialization {
self.searcher = None; self.searcher = None;
} }
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if let Some(init_expr) = local.init if let Some(init_expr) = local.init
&& let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind && let PatKind::Binding(BindingAnnotation::MUT, id, _, None) = local.pat.kind
&& !in_external_macro(cx.sess(), local.span) && !in_external_macro(cx.sess(), local.span)

View File

@ -12,7 +12,7 @@ mod vec_box;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{ use rustc_hir::{
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, Local, MutTy, QPath, TraitItem, Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, LetStmt, MutTy, QPath, TraitItem,
TraitItemKind, TyKind, TraitItemKind, TyKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -425,7 +425,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
} }
} }
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) {
if let Some(ty) = local.ty { if let Some(ty) = local.ty {
self.check_ty( self.check_ty(
cx, cx,

View File

@ -158,7 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
} }
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &hir::Stmt<'tcx>) { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &hir::Stmt<'tcx>) {
let (hir::StmtKind::Let(&hir::Local { init: Some(expr), .. }) let (hir::StmtKind::Let(&hir::LetStmt { init: Some(expr), .. })
| hir::StmtKind::Expr(expr) | hir::StmtKind::Expr(expr)
| hir::StmtKind::Semi(expr)) = stmt.kind | hir::StmtKind::Semi(expr)) = stmt.kind
else { else {
@ -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::Local { span, hir_id, .. }) => (*span, *hir_id), Node::Local(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,
@ -358,12 +358,12 @@ fn block_parents_have_safety_comment(
}, },
Node::Stmt(hir::Stmt { Node::Stmt(hir::Stmt {
kind: kind:
hir::StmtKind::Let(hir::Local { span, hir_id, .. }) hir::StmtKind::Let(hir::LetStmt { span, hir_id, .. })
| hir::StmtKind::Expr(hir::Expr { span, hir_id, .. }) | hir::StmtKind::Expr(hir::Expr { span, hir_id, .. })
| hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }), | hir::StmtKind::Semi(hir::Expr { span, hir_id, .. }),
.. ..
}) })
| Node::Local(hir::Local { span, hir_id, .. }) => (*span, *hir_id), | Node::Local(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,

View File

@ -4,14 +4,14 @@ use clippy_utils::visitors::{for_each_local_assignment, for_each_value_source};
use core::ops::ControlFlow; use core::ops::ControlFlow;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, Local, MatchSource, Node, PatKind, QPath, TyKind}; use rustc_hir::{Expr, ExprKind, HirId, HirIdSet, LetStmt, MatchSource, Node, PatKind, QPath, TyKind};
use rustc_lint::{LateContext, LintContext}; use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::{in_external_macro, is_from_async_await}; use rustc_middle::lint::{in_external_macro, is_from_async_await};
use rustc_middle::ty; use rustc_middle::ty;
use super::LET_UNIT_VALUE; use super::LET_UNIT_VALUE;
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) { pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
// skip `let () = { ... }` // skip `let () = { ... }`
if let PatKind::Tuple(fields, ..) = local.pat.kind if let PatKind::Tuple(fields, ..) = local.pat.kind
&& fields.is_empty() && fields.is_empty()

View File

@ -3,7 +3,7 @@ mod unit_arg;
mod unit_cmp; mod unit_cmp;
mod utils; mod utils;
use rustc_hir::{Expr, Local}; use rustc_hir::{Expr, LetStmt};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -99,7 +99,7 @@ declare_clippy_lint! {
declare_lint_pass!(UnitTypes => [LET_UNIT_VALUE, UNIT_CMP, UNIT_ARG]); declare_lint_pass!(UnitTypes => [LET_UNIT_VALUE, UNIT_CMP, UNIT_ARG]);
impl<'tcx> LateLintPass<'tcx> for UnitTypes { impl<'tcx> LateLintPass<'tcx> for UnitTypes {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
let_unit_value::check(cx, local); let_unit_value::check(cx, local);
} }

View File

@ -3,7 +3,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable};
use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators}; use clippy_utils::{fn_def_id, is_trait_method, path_to_local_id, peel_ref_operators};
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind}; use rustc_hir::{Block, Expr, ExprKind, HirId, LetStmt, Node, PatKind, PathSegment, StmtKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -190,7 +190,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
}, },
} }
}, },
Node::Local(Local { init: Some(init), .. }) => { Node::Local(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

@ -9,7 +9,7 @@ use clippy_utils::ty::is_copy;
use clippy_utils::visitors::for_each_local_use_after_expr; use clippy_utils::visitors::for_each_local_use_after_expr;
use clippy_utils::{get_parent_expr, higher, is_trait_method}; use clippy_utils::{get_parent_expr, higher, is_trait_method};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, Local, Mutability, Node, Pat, PatKind}; use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, LetStmt, Mutability, Node, Pat, PatKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty; use rustc_middle::ty;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
@ -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(Local { Node::Local(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(Local { ty: Some(_), .. }) if higher::VecArgs::hir(cx, expr).is_some() => { Node::Local(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

@ -7,7 +7,7 @@ use core::ops::ControlFlow;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::Res; use rustc_hir::def::Res;
use rustc_hir::{ use rustc_hir::{
BindingAnnotation, Block, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp, BindingAnnotation, Block, Expr, ExprKind, HirId, LetStmt, Mutability, PatKind, QPath, Stmt, StmtKind, UnOp,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
@ -157,7 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for VecInitThenPush {
self.searcher = None; self.searcher = None;
} }
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) { fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
if let Some(init_expr) = local.init if let Some(init_expr) = local.init
&& let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind && let PatKind::Binding(BindingAnnotation::MUT, id, name, None) = local.pat.kind
&& !in_external_macro(cx.sess(), local.span) && !in_external_macro(cx.sess(), local.span)

View File

@ -99,7 +99,7 @@ use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
use rustc_hir::{ use rustc_hir::{
self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Destination, Expr, self as hir, def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Destination, Expr,
ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind, ImplItemRef, Item,
ItemKind, LangItem, Local, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, Param, Pat, PatKind, Path, PathSegment, PrimTy,
QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef, TyKind, UnOp,
}; };
use rustc_lexer::{tokenize, TokenKind}; use rustc_lexer::{tokenize, TokenKind};
@ -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(Local { if let Node::Local(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(Local { els: Some(els), .. }) = node if let Node::Local(LetStmt { els: Some(els), .. }) = node
&& els.hir_id == child_id && els.hir_id == child_id
{ {
return true; return true;
@ -2158,7 +2158,7 @@ pub fn is_expr_used_or_unified(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
Node::Stmt(Stmt { Node::Stmt(Stmt {
kind: StmtKind::Expr(_) kind: StmtKind::Expr(_)
| StmtKind::Semi(_) | StmtKind::Semi(_)
| StmtKind::Let(Local { | StmtKind::Let(LetStmt {
pat: Pat { pat: Pat {
kind: PatKind::Wild, kind: PatKind::Wild,
.. ..
@ -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 Local<'tcx>), Local(&'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(Local { ty: Some(ty), .. }) => Some(DefinedTy::Hir(ty)), Self::Local(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())),
@ -3158,7 +3158,7 @@ pub fn is_never_expr<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> Option<
} }
} }
fn visit_local(&mut self, l: &'tcx Local<'_>) { fn visit_local(&mut self, l: &'tcx LetStmt<'_>) {
if let Some(e) = l.init { if let Some(e) = l.init {
self.visit_expr(e); self.visit_expr(e);
} }