Use CRATE_HIR_ID and CRATE_DEF_ID for obligations from foreign crates

This commit is contained in:
Santiago Pastorino 2022-08-23 09:08:30 -03:00
parent 4cb492e740
commit 4da14ef50e
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF

View file

@ -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;
@ -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()