Skip to content

Commit

Permalink
Rename hir::Node::Local into hir::Node::LetStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Mar 22, 2024
1 parent d318bf1 commit e0d3439
Show file tree
Hide file tree
Showing 43 changed files with 78 additions and 77 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, '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::LetStmt(l));
self.with_parent(l.hir_id, |this| {
intravisit::walk_local(this, l);
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
let e = match node {
hir::Node::Expr(e) => e,
hir::Node::Local(hir::LetStmt { els: Some(els), .. }) => {
hir::Node::LetStmt(hir::LetStmt { els: Some(els), .. }) => {
let mut finder = BreakFinder { found_breaks: vec![], found_continues: vec![] };
finder.visit_block(els);
if !finder.found_breaks.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&& let body = self.infcx.tcx.hir().body(body_id)
&& let Some(hir_id) = (BindingFinder { span: pat_span }).visit_body(body).break_value()
&& let node = self.infcx.tcx.hir_node(hir_id)
&& let hir::Node::Local(hir::LetStmt {
&& let hir::Node::LetStmt(hir::LetStmt {
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
..
})
Expand Down Expand Up @@ -1170,7 +1170,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
};

if let Some(hir_id) = hir_id
&& let hir::Node::Local(local) = self.infcx.tcx.hir_node(hir_id)
&& let hir::Node::LetStmt(local) = self.infcx.tcx.hir_node(hir_id)
{
let tables = self.infcx.tcx.typeck(def_id.as_local().unwrap());
if let Some(clone_trait) = self.infcx.tcx.lang_items().clone_trait()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3529,7 +3529,7 @@ pub enum Node<'hir> {
PatField(&'hir PatField<'hir>),
Arm(&'hir Arm<'hir>),
Block(&'hir Block<'hir>),
Local(&'hir LetStmt<'hir>),
LetStmt(&'hir LetStmt<'hir>),
/// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants
/// with synthesized constructors.
Ctor(&'hir VariantData<'hir>),
Expand Down Expand Up @@ -3585,7 +3585,7 @@ impl<'hir> Node<'hir> {
| Node::Ctor(..)
| Node::Pat(..)
| Node::Arm(..)
| Node::Local(..)
| Node::LetStmt(..)
| Node::Crate(..)
| Node::Ty(..)
| Node::TraitRef(..)
Expand Down Expand Up @@ -3757,7 +3757,7 @@ impl<'hir> Node<'hir> {
expect_pat_field, &'hir PatField<'hir>, Node::PatField(n), n;
expect_arm, &'hir Arm<'hir>, Node::Arm(n), n;
expect_block, &'hir Block<'hir>, Node::Block(n), n;
expect_let_stmt, &'hir LetStmt<'hir>, Node::Local(n), n;
expect_let_stmt, &'hir LetStmt<'hir>, Node::LetStmt(n), n;
expect_ctor, &'hir VariantData<'hir>, Node::Ctor(n), n;
expect_lifetime, &'hir Lifetime, Node::Lifetime(n), n;
expect_generic_param, &'hir GenericParam<'hir>, Node::GenericParam(n), n;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> State<'a> {
// `hir_map` to reconstruct their full structure for pretty
// printing.
Node::Ctor(..) => panic!("cannot print isolated Ctor"),
Node::Local(a) => self.print_local_decl(a),
Node::LetStmt(a) => self.print_local_decl(a),
Node::Crate(..) => panic!("cannot print Crate"),
Node::WhereBoundPredicate(pred) => {
self.print_formal_generic_params(pred.bound_generic_params);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
if let hir::Node::Local(hir::LetStmt { ty: Some(_), pat, .. }) = node {
if let hir::Node::LetStmt(hir::LetStmt { ty: Some(_), pat, .. }) = node {
return Some((pat.span, "expected because of this assignment".to_string()));
}
None
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false;
};
let (init_ty_hir_id, init) = match self.tcx.parent_hir_node(pat.hir_id) {
hir::Node::Local(hir::LetStmt { ty: Some(ty), init, .. }) => (ty.hir_id, *init),
hir::Node::Local(hir::LetStmt { init: Some(init), .. }) => (init.hir_id, Some(*init)),
hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), init, .. }) => (ty.hir_id, *init),
hir::Node::LetStmt(hir::LetStmt { init: Some(init), .. }) => (init.hir_id, Some(*init)),
_ => return false,
};
let Some(init_ty) = self.node_ty_opt(init_ty_hir_id) else {
Expand Down Expand Up @@ -678,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error: Option<TypeError<'tcx>>,
) {
match (self.tcx.parent_hir_node(expr.hir_id), error) {
(hir::Node::Local(hir::LetStmt { ty: Some(ty), init: Some(init), .. }), _)
(hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), init: Some(init), .. }), _)
if init.hir_id == expr.hir_id =>
{
// Point at `let` assignment type.
Expand Down Expand Up @@ -724,11 +724,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
primary_span = pat.span;
secondary_span = pat.span;
match self.tcx.parent_hir_node(pat.hir_id) {
hir::Node::Local(hir::LetStmt { ty: Some(ty), .. }) => {
hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }) => {
primary_span = ty.span;
post_message = " type";
}
hir::Node::Local(hir::LetStmt { init: Some(init), .. }) => {
hir::Node::LetStmt(hir::LetStmt { init: Some(init), .. }) => {
primary_span = init.span;
post_message = " value";
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
let Some((
_,
hir::Node::Local(hir::LetStmt { ty: Some(ty), .. })
hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. })
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. }),
)) = parent_node
else {
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
expr_id = parent_id;
}
Node::Local(local) => {
Node::LetStmt(local) => {
if let Some(mut ty) = local.ty {
while let Some(index) = tuple_indexes.pop() {
match ty.kind {
Expand Down Expand Up @@ -1331,7 +1331,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ++++++++++
// since the user probably just misunderstood how `let else`
// and `&&` work together.
if let Some((_, hir::Node::Local(local))) = cond_parent
if let Some((_, hir::Node::LetStmt(local))) = cond_parent
&& let hir::PatKind::Path(qpath) | hir::PatKind::TupleStruct(qpath, _, _) =
&local.pat.kind
&& let hir::QPath::Resolved(None, path) = qpath
Expand Down Expand Up @@ -1731,7 +1731,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

match self.tcx.parent_hir_node(*hir_id) {
// foo.clone()
hir::Node::Local(hir::LetStmt { init: Some(init), .. }) => {
hir::Node::LetStmt(hir::LetStmt { init: Some(init), .. }) => {
self.note_type_is_not_clone_inner_expr(init)
}
// When `expr` is more complex like a tuple
Expand All @@ -1740,7 +1740,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
kind: hir::PatKind::Tuple(pats, ..),
..
}) => {
let hir::Node::Local(hir::LetStmt { init: Some(init), .. }) =
let hir::Node::LetStmt(hir::LetStmt { init: Some(init), .. }) =
self.tcx.parent_hir_node(*pat_hir_id)
else {
return expr;
Expand Down Expand Up @@ -1774,7 +1774,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let hir::Path { segments: [_], res: crate::Res::Local(binding), .. } =
call_expr_path
&& let hir::Node::Pat(hir::Pat { hir_id, .. }) = self.tcx.hir_node(*binding)
&& let hir::Node::Local(hir::LetStmt { init: Some(init), .. }) =
&& let hir::Node::LetStmt(hir::LetStmt { init: Some(init), .. }) =
self.tcx.parent_hir_node(*hir_id)
&& let Expr {
kind: hir::ExprKind::Closure(hir::Closure { body: body_id, .. }),
Expand Down Expand Up @@ -3134,7 +3134,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let hir::Node::Pat(pat) = self.tcx.hir_node(hir_id) else {
return;
};
let hir::Node::Local(hir::LetStmt { ty: None, init: Some(init), .. }) =
let hir::Node::LetStmt(hir::LetStmt { ty: None, init: Some(init), .. }) =
self.tcx.parent_hir_node(pat.hir_id)
else {
return;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match (filename, parent_node) {
(
FileName::Real(_),
Node::Local(hir::LetStmt {
Node::LetStmt(hir::LetStmt {
source: hir::LocalSource::Normal,
ty,
..
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let ident_kind = match binding_parent {
hir::Node::Param(_) => "parameter",
hir::Node::Local(_) => "variable",
hir::Node::LetStmt(_) => "variable",
hir::Node::Arm(_) => "binding",

// Provide diagnostics only if the parent pattern is struct-like,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/error_reporting/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
&& let Some(expr) = block.expr
&& let hir::ExprKind::Path(QPath::Resolved(_, Path { res, .. })) = expr.kind
&& let Res::Local(local) = res
&& let Node::Local(LetStmt { init: Some(init), .. }) = self.tcx.parent_hir_node(*local)
&& let Node::LetStmt(LetStmt { init: Some(init), .. }) =
self.tcx.parent_hir_node(*local)
{
fn collect_blocks<'hir>(expr: &hir::Expr<'hir>, blocks: &mut Vec<&hir::Block<'hir>>) {
match expr.kind {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ impl<'tcx> LateContext<'tcx> {
}
&& let Some(init) = match parent_node {
hir::Node::Expr(expr) => Some(expr),
hir::Node::Local(hir::LetStmt { init, .. }) => *init,
hir::Node::LetStmt(hir::LetStmt { init, .. }) => *init,
_ => None,
}
{
Expand Down Expand Up @@ -982,7 +982,7 @@ impl<'tcx> LateContext<'tcx> {
}
&& let Some(init) = match parent_node {
hir::Node::Expr(expr) => Some(expr),
hir::Node::Local(hir::LetStmt { init, .. }) => *init,
hir::Node::LetStmt(hir::LetStmt { init, .. }) => *init,
hir::Node::Item(item) => match item.kind {
hir::ItemKind::Const(.., body_id) | hir::ItemKind::Static(.., body_id) => {
Some(self.tcx.hir().body(body_id).value)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ impl<'hir> Map<'hir> {
}
// Ignore `return`s on the first iteration
Node::Expr(Expr { kind: ExprKind::Loop(..) | ExprKind::Ret(..), .. })
| Node::Local(_) => {
| Node::LetStmt(_) => {
return None;
}
_ => {}
Expand Down Expand Up @@ -906,7 +906,7 @@ impl<'hir> Map<'hir> {
Node::Lifetime(lifetime) => lifetime.ident.span,
Node::GenericParam(param) => param.span,
Node::Infer(i) => i.span,
Node::Local(local) => local.span,
Node::LetStmt(local) => local.span,
Node::Crate(item) => item.spans.inner_span,
Node::WhereBoundPredicate(pred) => pred.span,
Node::ArrayLenInfer(inf) => inf.span,
Expand Down Expand Up @@ -1163,7 +1163,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
Node::Arm(_) => node_str("arm"),
Node::Block(_) => node_str("block"),
Node::Infer(_) => node_str("infer"),
Node::Local(_) => node_str("local"),
Node::LetStmt(_) => node_str("local"),
Node::Ctor(ctor) => format!(
"{id} (ctor {})",
ctor.ctor_def_id().map_or("<missing path>".into(), |def_id| path_str(def_id)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
// Different to previous arm because one is `&hir::Local` and the other
// is `P<hir::Local>`.
hir::Node::Local(local) => get_name(err, &local.pat.kind),
hir::Node::LetStmt(local) => get_name(err, &local.pat.kind),
_ => None,
}
}
Expand Down Expand Up @@ -930,7 +930,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let hir::Node::Pat(pat) = self.tcx.hir_node(hir_id) else {
return;
};
let hir::Node::Local(hir::LetStmt { ty: None, init: Some(init), .. }) =
let hir::Node::LetStmt(hir::LetStmt { ty: None, init: Some(init), .. }) =
self.tcx.parent_hir_node(pat.hir_id)
else {
return;
Expand Down Expand Up @@ -1562,7 +1562,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
&& let Res::Local(hir_id) = path.res
&& let hir::Node::Pat(binding) = self.tcx.hir_node(hir_id)
&& let hir::Node::Local(local) = self.tcx.parent_hir_node(binding.hir_id)
&& let hir::Node::LetStmt(local) = self.tcx.parent_hir_node(binding.hir_id)
&& let None = local.ty
&& let Some(binding_expr) = local.init
{
Expand Down Expand Up @@ -2966,7 +2966,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
err.downgrade_to_delayed_bug();
}
match tcx.parent_hir_node(hir_id) {
Node::Local(hir::LetStmt { ty: Some(ty), .. }) => {
Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }) => {
err.span_suggestion_verbose(
ty.span.shrink_to_lo(),
"consider borrowing here",
Expand All @@ -2975,7 +2975,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
);
err.note("all local variables must have a statically known size");
}
Node::Local(hir::LetStmt {
Node::LetStmt(hir::LetStmt {
init: Some(hir::Expr { kind: hir::ExprKind::Index(..), span, .. }),
..
}) => {
Expand Down Expand Up @@ -3867,7 +3867,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
&& let hir::Path { res: Res::Local(hir_id), .. } = path
&& let hir::Node::Pat(binding) = self.tcx.hir_node(*hir_id)
&& let hir::Node::Local(local) = self.tcx.parent_hir_node(binding.hir_id)
&& let hir::Node::LetStmt(local) = self.tcx.parent_hir_node(binding.hir_id)
&& let Some(binding_expr) = local.init
{
// If the expression we're calling on is a binding, we want to point at the
Expand Down Expand Up @@ -4128,7 +4128,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
{
let parent = self.tcx.parent_hir_node(binding.hir_id);
// We've reached the root of the method call chain...
if let hir::Node::Local(local) = parent
if let hir::Node::LetStmt(local) = parent
&& let Some(binding_expr) = local.init
{
// ...and it is a binding. Get the binding creation and continue the chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
{
let parent = self.tcx.parent_hir_node(binding.hir_id);
// We've reached the root of the method call chain...
if let hir::Node::Local(local) = parent
if let hir::Node::LetStmt(local) = parent
&& let Some(binding_expr) = local.init
{
// ...and it is a binding. Get the binding creation and continue the chain.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/assigning_clones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// That is overly conservative - the lint should fire even if there was no initializer,
// 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()
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/box_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'tcx> Visitor<'tcx> for InferVisitor {

fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
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();
v.visit_ty(ty);
!v.0
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/casts/ref_as_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(
&& let ty::RawPtr(TypeAndMut { mutbl: to_mutbl, .. }) = cast_to.kind()
&& let Some(use_cx) = expr_use_ctxt(cx, expr)
// 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 fn_name = match to_mutbl {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(super) fn check<'tcx>(
&& let QPath::Resolved(None, Path { res, .. }) = qpath
&& let Res::Local(hir_id) = res
&& 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
&& let TyKind::Path(qpath) = ty.kind
Expand Down Expand Up @@ -275,7 +275,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
}
// Local usage
} 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
&& is_cast_from_ty_alias(cx, e, cast_from)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/ignored_unit_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
// Ignore function parameters
return;
},
Node::Local(local) if local.ty.is_some() => {
Node::LetStmt(local) if local.ty.is_some() => {
// Ignore let bindings with explicit type
return;
},
Expand Down
Loading

0 comments on commit e0d3439

Please sign in to comment.