Skip to content

Commit 1329605

Browse files
committed
operate on HirId in hir::Pat::each_binding, and consequences of that
Changing the `each_binding` utility method to take the `HirId` of a binding pattern rather than its `NodeId` seems like a modest first step in support of the `HirId`ification initiative #50928. (The inspiration for choosing this in particular came from the present author's previous work on diagnostics issued during liveness analysis, which is the most greatly affected module in this change.)
1 parent 2b1d69d commit 1329605

File tree

8 files changed

+131
-104
lines changed

8 files changed

+131
-104
lines changed

src/librustc/hir/pat_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use hir::def::Def;
1212
use hir::def_id::DefId;
13-
use hir::{self, PatKind};
13+
use hir::{self, HirId, PatKind};
1414
use syntax::ast;
1515
use syntax::codemap::Spanned;
1616
use syntax_pos::Span;
@@ -91,11 +91,11 @@ impl hir::Pat {
9191
/// Call `f` on every "binding" in a pattern, e.g., on `a` in
9292
/// `match foo() { Some(a) => (), None => () }`
9393
pub fn each_binding<F>(&self, mut f: F)
94-
where F: FnMut(hir::BindingAnnotation, ast::NodeId, Span, &Spanned<ast::Name>),
94+
where F: FnMut(hir::BindingAnnotation, HirId, Span, &Spanned<ast::Name>),
9595
{
9696
self.walk(|p| {
9797
if let PatKind::Binding(binding_mode, _, ref pth, _) = p.node {
98-
f(binding_mode, p.id, p.span, pth);
98+
f(binding_mode, p.hir_id, p.span, pth);
9999
}
100100
true
101101
});

src/librustc/middle/expr_use_visitor.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
608608
fn walk_local(&mut self, local: &hir::Local) {
609609
match local.init {
610610
None => {
611-
let delegate = &mut self.delegate;
612-
local.pat.each_binding(|_, id, span, _| {
613-
delegate.decl_without_init(id, span);
611+
local.pat.each_binding(|_, hir_id, span, _| {
612+
// FIXME: converting HirId → NodeId is said to be relatively expensive
613+
let node_id = self.mc.tcx.hir.definitions().find_node_for_hir_id(hir_id);
614+
self.delegate.decl_without_init(node_id, span);
614615
})
615616
}
616617

0 commit comments

Comments
 (0)