Skip to content

Commit

Permalink
Use CRATE_HIR_ID and CRATE_DEF_ID for obligations from foreign crates
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Aug 23, 2022
1 parent 4cb492e commit 4da14ef
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use crate::traits::{
};
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::def_id::{DefId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::CRATE_HIR_ID;
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::util;
use rustc_middle::traits::specialization_graph::OverlapMode;
Expand Down Expand Up @@ -395,19 +396,20 @@ fn resolve_negative_obligation<'cx, 'tcx>(
return false;
}

let outlives_env = if let Some(body_def_id) = body_def_id.as_local() {
let body_id = tcx.hir().local_def_id_to_hir_id(body_def_id);
let ocx = ObligationCtxt::new(&infcx);
let wf_tys = ocx.assumed_wf_types(param_env, DUMMY_SP, body_def_id);
OutlivesEnvironment::with_bounds(
param_env,
Some(&infcx),
infcx.implied_bounds_tys(param_env, body_id, wf_tys),
)
let (body_id, body_def_id) = if let Some(body_def_id) = body_def_id.as_local() {
(tcx.hir().local_def_id_to_hir_id(body_def_id), body_def_id)
} else {
OutlivesEnvironment::new(param_env)
(CRATE_HIR_ID, CRATE_DEF_ID)
};

let ocx = ObligationCtxt::new(&infcx);
let wf_tys = ocx.assumed_wf_types(param_env, DUMMY_SP, body_def_id);
let outlives_env = OutlivesEnvironment::with_bounds(
param_env,
Some(&infcx),
infcx.implied_bounds_tys(param_env, body_id, wf_tys),
);

infcx.process_registered_region_obligations(outlives_env.region_bound_pairs(), param_env);

infcx.resolve_regions(&outlives_env).is_empty()
Expand Down

0 comments on commit 4da14ef

Please sign in to comment.