Skip to content

Commit

Permalink
operate on HirId in hir::Pat::each_binding, and consequences of that
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
zackmdavis committed May 28, 2018
1 parent 2b1d69d commit 1329605
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 104 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/pat_util.rs
Expand Up @@ -10,7 +10,7 @@

use hir::def::Def;
use hir::def_id::DefId;
use hir::{self, PatKind};
use hir::{self, HirId, PatKind};
use syntax::ast;
use syntax::codemap::Spanned;
use syntax_pos::Span;
Expand Down Expand Up @@ -91,11 +91,11 @@ impl hir::Pat {
/// Call `f` on every "binding" in a pattern, e.g., on `a` in
/// `match foo() { Some(a) => (), None => () }`
pub fn each_binding<F>(&self, mut f: F)
where F: FnMut(hir::BindingAnnotation, ast::NodeId, Span, &Spanned<ast::Name>),
where F: FnMut(hir::BindingAnnotation, HirId, Span, &Spanned<ast::Name>),
{
self.walk(|p| {
if let PatKind::Binding(binding_mode, _, ref pth, _) = p.node {
f(binding_mode, p.id, p.span, pth);
f(binding_mode, p.hir_id, p.span, pth);
}
true
});
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -608,9 +608,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
fn walk_local(&mut self, local: &hir::Local) {
match local.init {
None => {
let delegate = &mut self.delegate;
local.pat.each_binding(|_, id, span, _| {
delegate.decl_without_init(id, span);
local.pat.each_binding(|_, hir_id, span, _| {
// FIXME: converting HirId → NodeId is said to be relatively expensive
let node_id = self.mc.tcx.hir.definitions().find_node_for_hir_id(hir_id);
self.delegate.decl_without_init(node_id, span);
})
}

Expand Down

0 comments on commit 1329605

Please sign in to comment.