From 4547b622d8d29df964fa2914213088b148c498fc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:32 +0200 Subject: Merging upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- .../src/diagnostics/bound_region_errors.rs | 59 +++++++++++----------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs') diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 02071ed6b..1550958ab 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -1,3 +1,6 @@ +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; use rustc_infer::infer::canonical::Canonical; use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError; @@ -5,14 +8,14 @@ use rustc_infer::infer::region_constraints::Constraint; use rustc_infer::infer::region_constraints::RegionConstraintData; use rustc_infer::infer::RegionVariableOrigin; use rustc_infer::infer::{InferCtxt, RegionResolutionError, SubregionOrigin, TyCtxtInferExt as _}; -use rustc_infer::traits::{Normalized, ObligationCause, TraitEngine, TraitEngineExt}; +use rustc_infer::traits::ObligationCause; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::RegionVid; use rustc_middle::ty::UniverseIndex; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_span::Span; use rustc_trait_selection::traits::query::type_op; -use rustc_trait_selection::traits::{SelectionContext, TraitEngineExt as _}; +use rustc_trait_selection::traits::ObligationCtxt; use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause}; use std::fmt; @@ -158,6 +161,7 @@ trait TypeOpInfo<'tcx> { error_region: Option>, ) -> Option>; + #[instrument(level = "debug", skip(self, mbcx))] fn report_error( &self, mbcx: &mut MirBorrowckCtxt<'_, 'tcx>, @@ -167,6 +171,7 @@ trait TypeOpInfo<'tcx> { ) { let tcx = mbcx.infcx.tcx; let base_universe = self.base_universe(); + debug!(?base_universe); let Some(adjusted_universe) = placeholder.universe.as_u32().checked_sub(base_universe.as_u32()) @@ -238,11 +243,11 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> { placeholder_region: ty::Region<'tcx>, error_region: Option>, ) -> Option> { - let (ref infcx, key, _) = + let (infcx, key, _) = mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query); - let mut fulfill_cx = >::new(infcx.tcx); - type_op_prove_predicate_with_cause(infcx, &mut *fulfill_cx, key, cause); - try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region) + let ocx = ObligationCtxt::new(&infcx); + type_op_prove_predicate_with_cause(&ocx, key, cause); + try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region) } } @@ -279,24 +284,20 @@ where placeholder_region: ty::Region<'tcx>, error_region: Option>, ) -> Option> { - let (ref infcx, key, _) = + let (infcx, key, _) = mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query); - let mut fulfill_cx = >::new(infcx.tcx); - - let mut selcx = SelectionContext::new(infcx); + let ocx = ObligationCtxt::new(&infcx); // FIXME(lqd): Unify and de-duplicate the following with the actual // `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the // `ObligationCause`. The normalization results are currently different between - // `AtExt::normalize` used in the query and `normalize` called below: the former fails - // to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. Check - // after #85499 lands to see if its fixes have erased this difference. + // `QueryNormalizeExt::query_normalize` used in the query and `normalize` called below: + // the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test. + // Check after #85499 lands to see if its fixes have erased this difference. let (param_env, value) = key.into_parts(); - let Normalized { value: _, obligations } = - rustc_trait_selection::traits::normalize(&mut selcx, param_env, cause, value.value); - fulfill_cx.register_predicate_obligations(infcx, obligations); + let _ = ocx.normalize(&cause, param_env, value.value); - try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region) + try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region) } } @@ -327,11 +328,11 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> { placeholder_region: ty::Region<'tcx>, error_region: Option>, ) -> Option> { - let (ref infcx, key, _) = + let (infcx, key, _) = mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query); - let mut fulfill_cx = >::new(infcx.tcx); - type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(cause.span)).ok()?; - try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region) + let ocx = ObligationCtxt::new(&infcx); + type_op_ascribe_user_type_with_span(&ocx, key, Some(cause.span)).ok()?; + try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region) } } @@ -372,28 +373,28 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> { } } -#[instrument(skip(fulfill_cx, infcx), level = "debug")] +#[instrument(skip(ocx), level = "debug")] fn try_extract_error_from_fulfill_cx<'tcx>( - mut fulfill_cx: Box + 'tcx>, - infcx: &InferCtxt<'tcx>, + ocx: &ObligationCtxt<'_, 'tcx>, placeholder_region: ty::Region<'tcx>, error_region: Option>, ) -> Option> { // We generally shouldn't have errors here because the query was // already run, but there's no point using `delay_span_bug` // when we're going to emit an error here anyway. - let _errors = fulfill_cx.select_all_or_error(infcx); - let region_constraints = infcx.with_region_constraints(|r| r.clone()); + let _errors = ocx.select_all_or_error(); + let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone()); try_extract_error_from_region_constraints( - infcx, + ocx.infcx, placeholder_region, error_region, ®ion_constraints, - |vid| infcx.region_var_origin(vid), - |vid| infcx.universe_of_region(infcx.tcx.mk_region(ty::ReVar(vid))), + |vid| ocx.infcx.region_var_origin(vid), + |vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_region(ty::ReVar(vid))), ) } +#[instrument(level = "debug", skip(infcx, region_var_origin, universe_of_region))] fn try_extract_error_from_region_constraints<'tcx>( infcx: &InferCtxt<'tcx>, placeholder_region: ty::Region<'tcx>, -- cgit v1.2.3