about summary refs log tree commit diff
diff options
context:
space:
mode:
authormarmeladema <xademax@gmail.com>2020-04-12 20:59:13 +0100
committermarmeladema <xademax@gmail.com>2020-04-12 21:01:55 +0100
commit0634789dee9fadf31bd0fe94898eb5937c130f77 (patch)
tree00901d14b32ed5b104eb397bbc407ff799577b4d
parent502ae0e8988c1fa3ffc109c0d924e20c85f9426d (diff)
downloadrust-0634789dee9fadf31bd0fe94898eb5937c130f77.tar.gz
rust-0634789dee9fadf31bd0fe94898eb5937c130f77.zip
Remove usage of `DUMMY_HIR_ID` in `Scope::hir_id`
-rw-r--r--src/librustc_infer/infer/error_reporting/mod.rs3
-rw-r--r--src/librustc_middle/middle/region.rs17
2 files changed, 10 insertions, 10 deletions
diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs
index 942d76e3202..db81ceea43f 100644
--- a/src/librustc_infer/infer/error_reporting/mod.rs
+++ b/src/librustc_infer/infer/error_reporting/mod.rs
@@ -93,7 +93,8 @@ pub(super) fn note_and_explain_region(
             let unknown_scope =
                 || format!("{}unknown scope: {:?}{}.  Please report a bug.", prefix, scope, suffix);
             let span = scope.span(tcx, region_scope_tree);
-            let tag = match tcx.hir().find(scope.hir_id(region_scope_tree)) {
+            let hir_id = scope.hir_id(region_scope_tree);
+            let tag = match hir_id.and_then(|hir_id| tcx.hir().find(hir_id)) {
                 Some(Node::Block(_)) => "block",
                 Some(Node::Expr(expr)) => match expr.kind {
                     hir::ExprKind::Call(..) => "call",
diff --git a/src/librustc_middle/middle/region.rs b/src/librustc_middle/middle/region.rs
index dd9ab102129..2ad6fe14ec7 100644
--- a/src/librustc_middle/middle/region.rs
+++ b/src/librustc_middle/middle/region.rs
@@ -159,21 +159,20 @@ impl Scope {
         self.id
     }
 
-    pub fn hir_id(&self, scope_tree: &ScopeTree) -> hir::HirId {
-        match scope_tree.root_body {
-            Some(hir_id) => hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() },
-            None => hir::DUMMY_HIR_ID,
-        }
+    pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<hir::HirId> {
+        scope_tree
+            .root_body
+            .map(|hir_id| hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() })
     }
 
     /// Returns the span of this `Scope`. Note that in general the
     /// returned span may not correspond to the span of any `NodeId` in
     /// the AST.
     pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span {
-        let hir_id = self.hir_id(scope_tree);
-        if hir_id == hir::DUMMY_HIR_ID {
-            return DUMMY_SP;
-        }
+        let hir_id = match self.hir_id(scope_tree) {
+            Some(hir_id) => hir_id,
+            None => return DUMMY_SP,
+        };
         let span = tcx.hir().span(hir_id);
         if let ScopeData::Remainder(first_statement_index) = self.data {
             if let Node::Block(ref blk) = tcx.hir().get(hir_id) {