Skip to content

Commit 0634789

Browse files
committed
Remove usage of DUMMY_HIR_ID in Scope::hir_id
1 parent 502ae0e commit 0634789

File tree

2 files changed

+10
-10
lines changed
  • src

2 files changed

+10
-10
lines changed

src/librustc_infer/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ pub(super) fn note_and_explain_region(
9393
let unknown_scope =
9494
|| format!("{}unknown scope: {:?}{}. Please report a bug.", prefix, scope, suffix);
9595
let span = scope.span(tcx, region_scope_tree);
96-
let tag = match tcx.hir().find(scope.hir_id(region_scope_tree)) {
96+
let hir_id = scope.hir_id(region_scope_tree);
97+
let tag = match hir_id.and_then(|hir_id| tcx.hir().find(hir_id)) {
9798
Some(Node::Block(_)) => "block",
9899
Some(Node::Expr(expr)) => match expr.kind {
99100
hir::ExprKind::Call(..) => "call",

src/librustc_middle/middle/region.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,20 @@ impl Scope {
159159
self.id
160160
}
161161

162-
pub fn hir_id(&self, scope_tree: &ScopeTree) -> hir::HirId {
163-
match scope_tree.root_body {
164-
Some(hir_id) => hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() },
165-
None => hir::DUMMY_HIR_ID,
166-
}
162+
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<hir::HirId> {
163+
scope_tree
164+
.root_body
165+
.map(|hir_id| hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() })
167166
}
168167

169168
/// Returns the span of this `Scope`. Note that in general the
170169
/// returned span may not correspond to the span of any `NodeId` in
171170
/// the AST.
172171
pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span {
173-
let hir_id = self.hir_id(scope_tree);
174-
if hir_id == hir::DUMMY_HIR_ID {
175-
return DUMMY_SP;
176-
}
172+
let hir_id = match self.hir_id(scope_tree) {
173+
Some(hir_id) => hir_id,
174+
None => return DUMMY_SP,
175+
};
177176
let span = tcx.hir().span(hir_id);
178177
if let ScopeData::Remainder(first_statement_index) = self.data {
179178
if let Node::Block(ref blk) = tcx.hir().get(hir_id) {

0 commit comments

Comments
 (0)