From 4da14ef50eb697298f36d41f91cb02dc800275bf Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 23 Aug 2022 09:08:30 -0300 Subject: [PATCH] Use CRATE_HIR_ID and CRATE_DEF_ID for obligations from foreign crates --- .../src/traits/coherence.rs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index f09be12b84d0c..292787d4dbb24 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -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()