Skip to content

Commit 0f4d840

Browse files
committed
hir: Remove unnecessary HirId from hir::Let
It has 1-to-1 correspondence to its expression id. Also remove mostly useless `visit_let_expr`.
1 parent 8af70c7 commit 0f4d840

File tree

6 files changed

+17
-28
lines changed

6 files changed

+17
-28
lines changed

compiler/rustc_ast_lowering/src/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
153153
}
154154
ExprKind::Let(pat, scrutinee, span, is_recovered) => {
155155
hir::ExprKind::Let(self.arena.alloc(hir::Let {
156-
hir_id: self.next_id(),
157156
span: self.lower_span(*span),
158157
pat: self.lower_pat(pat),
159158
ty: None,

compiler/rustc_hir/src/hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,6 @@ pub struct Arm<'hir> {
12731273
/// desugaring to if-let. Only let-else supports the type annotation at present.
12741274
#[derive(Debug, Clone, Copy, HashStable_Generic)]
12751275
pub struct Let<'hir> {
1276-
pub hir_id: HirId,
12771276
pub span: Span,
12781277
pub pat: &'hir Pat<'hir>,
12791278
pub ty: Option<&'hir Ty<'hir>>,

compiler/rustc_hir/src/intravisit.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,6 @@ pub trait Visitor<'v>: Sized {
341341
fn visit_expr(&mut self, ex: &'v Expr<'v>) {
342342
walk_expr(self, ex)
343343
}
344-
fn visit_let_expr(&mut self, lex: &'v Let<'v>) {
345-
walk_let_expr(self, lex)
346-
}
347344
fn visit_expr_field(&mut self, field: &'v ExprField<'v>) {
348345
walk_expr_field(self, field)
349346
}
@@ -729,7 +726,12 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
729726
ExprKind::DropTemps(ref subexpression) => {
730727
visitor.visit_expr(subexpression);
731728
}
732-
ExprKind::Let(ref let_expr) => visitor.visit_let_expr(let_expr),
729+
ExprKind::Let(ref let_expr) => {
730+
// match the visit order in walk_local
731+
visitor.visit_expr(let_expr.init);
732+
visitor.visit_pat(let_expr.pat);
733+
walk_list!(visitor, visit_ty, let_expr.ty);
734+
}
733735
ExprKind::If(ref cond, ref then, ref else_opt) => {
734736
visitor.visit_expr(cond);
735737
visitor.visit_expr(then);
@@ -806,14 +808,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
806808
}
807809
}
808810

809-
pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>) {
810-
// match the visit order in walk_local
811-
visitor.visit_expr(let_expr.init);
812-
visitor.visit_id(let_expr.hir_id);
813-
visitor.visit_pat(let_expr.pat);
814-
walk_list!(visitor, visit_ty, let_expr.ty);
815-
}
816-
817811
pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) {
818812
visitor.visit_id(field.hir_id);
819813
visitor.visit_ident(field.ident);

compiler/rustc_hir_typeck/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
320320
}
321321
ExprKind::Ret(ref expr_opt) => self.check_expr_return(expr_opt.as_deref(), expr),
322322
ExprKind::Become(call) => self.check_expr_become(call, expr),
323-
ExprKind::Let(let_expr) => self.check_expr_let(let_expr),
323+
ExprKind::Let(let_expr) => self.check_expr_let(let_expr, expr.hir_id),
324324
ExprKind::Loop(body, _, source, _) => {
325325
self.check_expr_loop(body, source, expected, expr)
326326
}
@@ -1259,12 +1259,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12591259
}
12601260
}
12611261

1262-
pub(super) fn check_expr_let(&self, let_expr: &'tcx hir::Let<'tcx>) -> Ty<'tcx> {
1262+
pub(super) fn check_expr_let(&self, let_expr: &'tcx hir::Let<'tcx>, hir_id: HirId) -> Ty<'tcx> {
12631263
// for let statements, this is done in check_stmt
12641264
let init = let_expr.init;
12651265
self.warn_if_unreachable(init.hir_id, init.span, "block in `let` expression");
12661266
// otherwise check exactly as a let statement
1267-
self.check_decl(let_expr.into());
1267+
self.check_decl((let_expr, hir_id).into());
12681268
// but return a bool, for this is a boolean expression
12691269
if let Some(error_guaranteed) = let_expr.is_recovered {
12701270
self.set_tainted_by_errors(error_guaranteed);

compiler/rustc_hir_typeck/src/gather_locals.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ impl<'a> From<&'a hir::Local<'a>> for Declaration<'a> {
4848
}
4949
}
5050

51-
impl<'a> From<&'a hir::Let<'a>> for Declaration<'a> {
52-
fn from(let_expr: &'a hir::Let<'a>) -> Self {
53-
let hir::Let { hir_id, pat, ty, span, init, is_recovered: _ } = *let_expr;
51+
impl<'a> From<(&'a hir::Let<'a>, hir::HirId)> for Declaration<'a> {
52+
fn from((let_expr, hir_id): (&'a hir::Let<'a>, hir::HirId)) -> Self {
53+
let hir::Let { pat, ty, span, init, is_recovered: _ } = *let_expr;
5454
Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr }
5555
}
5656
}
@@ -125,9 +125,11 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
125125
intravisit::walk_local(self, local)
126126
}
127127

128-
fn visit_let_expr(&mut self, let_expr: &'tcx hir::Let<'tcx>) {
129-
self.declare(let_expr.into());
130-
intravisit::walk_let_expr(self, let_expr);
128+
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
129+
if let hir::ExprKind::Let(let_expr) = expr.kind {
130+
self.declare((let_expr, expr.hir_id).into());
131+
}
132+
intravisit::walk_expr(self, expr)
131133
}
132134

133135
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {

compiler/rustc_passes/src/hir_stats.rs

-5
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
328328
hir_visit::walk_expr(self, e)
329329
}
330330

331-
fn visit_let_expr(&mut self, lex: &'v hir::Let<'v>) {
332-
self.record("Let", Id::Node(lex.hir_id), lex);
333-
hir_visit::walk_let_expr(self, lex)
334-
}
335-
336331
fn visit_expr_field(&mut self, f: &'v hir::ExprField<'v>) {
337332
self.record("ExprField", Id::Node(f.hir_id), f);
338333
hir_visit::walk_expr_field(self, f)

0 commit comments

Comments
 (0)