Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some usage of DUMMY_HIR_ID #71069

Merged
merged 4 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 2 additions & 3 deletions src/librustc_passes/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::DUMMY_HIR_ID;
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem};
use rustc_hir::{MethodKind, Target};
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
Expand Down Expand Up @@ -360,7 +359,7 @@ impl CheckAttrVisitor<'tcx> {
if let hir::StmtKind::Local(ref l) = stmt.kind {
for attr in l.attrs.iter() {
if attr.check_name(sym::inline) {
self.check_inline(DUMMY_HIR_ID, attr, &stmt.span, Target::Statement);
self.check_inline(l.hir_id, attr, &stmt.span, Target::Statement);
Comment on lines -363 to +362
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh this is a bugfix (#[allow] & friends will now work correctly).

}
if attr.check_name(sym::repr) {
self.emit_repr_error(
Expand All @@ -381,7 +380,7 @@ impl CheckAttrVisitor<'tcx> {
};
for attr in expr.attrs.iter() {
if attr.check_name(sym::inline) {
self.check_inline(DUMMY_HIR_ID, attr, &expr.span, target);
self.check_inline(expr.hir_id, attr, &expr.span, target);
}
if attr.check_name(sym::repr) {
self.emit_repr_error(
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_passes/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,31 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
}

let loop_id = match label.target_id {
Ok(loop_id) => loop_id,
Err(hir::LoopIdError::OutsideLoopScope) => hir::DUMMY_HIR_ID,
Ok(loop_id) => Some(loop_id),
Err(hir::LoopIdError::OutsideLoopScope) => None,
Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => {
self.emit_unlabled_cf_in_while_condition(e.span, "break");
hir::DUMMY_HIR_ID
None
}
Err(hir::LoopIdError::UnresolvedLabel) => hir::DUMMY_HIR_ID,
Err(hir::LoopIdError::UnresolvedLabel) => None,
};

if loop_id != hir::DUMMY_HIR_ID {
if let Some(loop_id) = loop_id {
if let Node::Block(_) = self.hir_map.find(loop_id).unwrap() {
return;
}
}

if opt_expr.is_some() {
let loop_kind = if loop_id == hir::DUMMY_HIR_ID {
None
} else {
let loop_kind = if let Some(loop_id) = loop_id {
Some(match self.hir_map.expect_expr(loop_id).kind {
hir::ExprKind::Loop(_, _, source) => source,
ref r => {
span_bug!(e.span, "break label resolved to a non-loop: {:?}", r)
}
})
} else {
None
};
match loop_kind {
None | Some(hir::LoopSource::Loop) => (),
Expand Down
12 changes: 3 additions & 9 deletions src/librustc_trait_selection/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// to store all of the necessary region/lifetime bounds in the InferContext, as well as
// an additional sanity check.
let mut fulfill = FulfillmentContext::new();
fulfill.register_bound(
&infcx,
full_env,
ty,
trait_did,
ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID),
);
fulfill.register_bound(&infcx, full_env, ty, trait_did, ObligationCause::dummy());
fulfill.select_all_or_error(&infcx).unwrap_or_else(|e| {
panic!("Unable to fulfill trait {:?} for '{:?}': {:?}", trait_did, ty, e)
});
Expand Down Expand Up @@ -292,7 +286,7 @@ impl AutoTraitFinder<'tcx> {
user_env.caller_bounds.iter().cloned().collect();

let mut new_env = param_env;
let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
let dummy_cause = ObligationCause::dummy();

while let Some(pred) = predicates.pop_front() {
infcx.clear_caches();
Expand Down Expand Up @@ -615,7 +609,7 @@ impl AutoTraitFinder<'tcx> {
select: &mut SelectionContext<'_, 'tcx>,
only_projections: bool,
) -> bool {
let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
let dummy_cause = ObligationCause::dummy();

for (obligation, mut predicate) in nested.map(|o| (o.clone(), o.predicate)) {
let is_new_pred = fresh_preds.insert(self.clean_pred(select.infcx(), predicate));
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trait_selection/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rustc_middle::middle::region;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
use rustc_middle::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, WithConstness};
use rustc_span::{Span, DUMMY_SP};
use rustc_span::Span;

use std::fmt::Debug;

Expand Down Expand Up @@ -136,7 +136,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>(
let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) };
let obligation = Obligation {
param_env,
cause: ObligationCause::misc(span, hir::DUMMY_HIR_ID),
cause: ObligationCause::misc(span, hir::CRATE_HIR_ID),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @nikomatsakis Is this a good way to encode this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is what ObligationCause::dummy does, heh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i just "copied" what was done in dummy

recursion_depth: 0,
predicate: trait_ref.without_const().to_predicate(),
};
Expand All @@ -163,7 +163,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>(
// We can use a dummy node-id here because we won't pay any mind
// to region obligations that arise (there shouldn't really be any
// anyhow).
let cause = ObligationCause::misc(span, hir::DUMMY_HIR_ID);
let cause = ObligationCause::misc(span, hir::CRATE_HIR_ID);

fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause);

Expand Down
4 changes: 1 addition & 3 deletions src/librustc_traits/normalize_projection_ty.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use rustc_hir as hir;
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::TraitEngineExt as _;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
use rustc_span::DUMMY_SP;
use rustc_trait_selection::infer::InferCtxtBuilderExt;
use rustc_trait_selection::traits::query::{
normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution,
Expand All @@ -27,7 +25,7 @@ fn normalize_projection_ty<'tcx>(
&goal,
|infcx, fulfill_cx, ParamEnvAnd { param_env, value: goal }| {
let selcx = &mut SelectionContext::new(infcx);
let cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
let cause = ObligationCause::dummy();
let mut obligations = vec![];
let answer = traits::normalize_projection_type(
selcx,
Expand Down