use deeply_normalize
for assumed_wf_types
This commit is contained in:
parent
d2c7449189
commit
5378f07d64
10 changed files with 112 additions and 52 deletions
|
@ -427,7 +427,11 @@ fn prove_negated_obligation<'tcx>(
|
|||
let body_def_id = body_def_id.as_local().unwrap_or(CRATE_DEF_ID);
|
||||
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
let wf_tys = ocx.assumed_wf_types(param_env, DUMMY_SP, body_def_id);
|
||||
let Ok(wf_tys) = ocx.assumed_wf_types(param_env, body_def_id)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let outlives_env = OutlivesEnvironment::with_bounds(
|
||||
param_env,
|
||||
infcx.implied_bounds_tys(param_env, body_def_id, wf_tys),
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::fmt::Debug;
|
|||
use super::TraitEngine;
|
||||
use super::{ChalkFulfillmentContext, FulfillmentContext};
|
||||
use crate::solve::FulfillmentCtxt as NextFulfillmentCtxt;
|
||||
use crate::traits::error_reporting::TypeErrCtxtExt;
|
||||
use crate::traits::NormalizeExt;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
|
@ -24,7 +25,6 @@ use rustc_middle::ty::ToPredicate;
|
|||
use rustc_middle::ty::TypeFoldable;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::config::TraitSolver;
|
||||
use rustc_span::Span;
|
||||
|
||||
pub trait TraitEngineExt<'tcx> {
|
||||
fn new(infcx: &InferCtxt<'tcx>) -> Box<Self>;
|
||||
|
@ -198,17 +198,24 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn assumed_wf_types_and_report_errors(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
def_id: LocalDefId,
|
||||
) -> Result<FxIndexSet<Ty<'tcx>>, ErrorGuaranteed> {
|
||||
self.assumed_wf_types(param_env, def_id)
|
||||
.map_err(|errors| self.infcx.err_ctxt().report_fulfillment_errors(&errors))
|
||||
}
|
||||
|
||||
pub fn assumed_wf_types(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
span: Span,
|
||||
def_id: LocalDefId,
|
||||
) -> FxIndexSet<Ty<'tcx>> {
|
||||
) -> Result<FxIndexSet<Ty<'tcx>>, Vec<FulfillmentError<'tcx>>> {
|
||||
let tcx = self.infcx.tcx;
|
||||
let assumed_wf_types = tcx.assumed_wf_types(def_id);
|
||||
let mut implied_bounds = FxIndexSet::default();
|
||||
let cause = ObligationCause::misc(span, def_id);
|
||||
for ty in assumed_wf_types {
|
||||
let mut errors = Vec::new();
|
||||
for &(ty, span) in tcx.assumed_wf_types(def_id) {
|
||||
// FIXME(@lcnr): rustc currently does not check wf for types
|
||||
// pre-normalization, meaning that implied bounds are sometimes
|
||||
// incorrect. See #100910 for more details.
|
||||
|
@ -221,10 +228,15 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
|||
// sound and then uncomment this line again.
|
||||
|
||||
// implied_bounds.insert(ty);
|
||||
let normalized = self.normalize(&cause, param_env, ty);
|
||||
implied_bounds.insert(normalized);
|
||||
let cause = ObligationCause::misc(span, def_id);
|
||||
match self.infcx.at(&cause, param_env).deeply_normalize(ty) {
|
||||
// Insert well-formed types, ignoring duplicates.
|
||||
Ok(normalized) => drop(implied_bounds.insert(normalized)),
|
||||
Err(normalization_errors) => errors.extend(normalization_errors),
|
||||
};
|
||||
}
|
||||
implied_bounds
|
||||
|
||||
if errors.is_empty() { Ok(implied_bounds) } else { Err(errors) }
|
||||
}
|
||||
|
||||
pub fn make_canonicalized_query_response<T>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue