From 3508874c9ef48560824c4630dbd935a33f80e1bc Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 11 Apr 2017 22:04:17 -0700 Subject: [PATCH] Remove assumption that region_maps arg is fn id --- src/librustc/ty/context.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index a33a788221815..24f75aee16bbc 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -663,17 +663,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { local as usize == global as usize } - pub fn region_maps(self, fn_id: NodeId) -> Rc { - // Find the `NodeId` of the outermost function that wraps the function pointed to by fn_id - let mut outermost_fn_id = fn_id; + pub fn region_maps(self, node_id: NodeId) -> Rc { + // Find the `NodeId` of the outermost function that wraps the node pointed to by node_id + let mut outermost_fn_id_opt = None; let mut outermost_id = fn_id; loop { - let next_id = self.hir.get_parent(outermost_id); - if outermost_id == next_id { break; } if self.hir.is_fn(outermost_id) { - outermost_fn_id = outermost_id; + outermost_fn_id_opt = Some(outermost_id); } + let next_id = self.hir.get_parent(outermost_id); + if outermost_id == next_id { break; } } + let outermost_fn_id = outermost_fn_id_opt.expect("node_id should point inside a fn"); ty::queries::region_resolve_fn::get(self, DUMMY_SP, self.hir.local_def_id(outermost_fn_id)) }