Skip to content

Commit

Permalink
Remove usage of DUMMY_HIR_ID in Scope::hir_id
Browse files Browse the repository at this point in the history
  • Loading branch information
marmeladema committed Apr 12, 2020
1 parent 502ae0e commit 0634789
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_middle/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0634789

Please sign in to comment.