From 812854cdd313c0644534ce50b22d2a1c4fbe4957 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Sun, 12 Apr 2020 18:42:45 +0100 Subject: [PATCH] Remove usage of `DUMMY_HIR_ID` in calls to `ObligationClause::misc` Use `ObligationClause::dummy()` when appropriate or replace `hir::DUMMY_HIR_ID` by `hir::CRATE_HIR_ID`, as used in `ObligationClause::dummy()`. --- src/librustc_trait_selection/traits/auto_trait.rs | 12 +++--------- src/librustc_trait_selection/traits/mod.rs | 6 +++--- src/librustc_traits/normalize_projection_ty.rs | 4 +--- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs index b4c790eebc106..052de4a4e5b55 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -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) }); @@ -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(); @@ -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)); diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index a9d0f35fb276a..f5f4a51eb54e2 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -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; @@ -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), recursion_depth: 0, predicate: trait_ref.without_const().to_predicate(), }; @@ -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); diff --git a/src/librustc_traits/normalize_projection_ty.rs b/src/librustc_traits/normalize_projection_ty.rs index 11c97b03c44c3..d6d3e86a2c8d3 100644 --- a/src/librustc_traits/normalize_projection_ty.rs +++ b/src/librustc_traits/normalize_projection_ty.rs @@ -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, @@ -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,