Use ErrorGuaranteed more in MIR type ops
This commit is contained in:
parent
cade26637f
commit
91525a4324
8 changed files with 104 additions and 107 deletions
|
@ -1,12 +1,12 @@
|
|||
use std::fmt;
|
||||
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_infer::infer::canonical::Canonical;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
|
||||
use rustc_trait_selection::traits::query::{Fallible, NoSolution};
|
||||
use rustc_trait_selection::traits::ObligationCause;
|
||||
|
||||
use crate::diagnostics::{ToUniverseInfo, UniverseInfo};
|
||||
|
@ -30,14 +30,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
locations: Locations,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
op: Op,
|
||||
) -> Fallible<R>
|
||||
) -> Result<R, ErrorGuaranteed>
|
||||
where
|
||||
Op: type_op::TypeOp<'tcx, Output = R>,
|
||||
Op::ErrorInfo: ToUniverseInfo<'tcx>,
|
||||
{
|
||||
let old_universe = self.infcx.universe();
|
||||
|
||||
let TypeOpOutput { output, constraints, error_info } = op.fully_perform(self.infcx)?;
|
||||
let TypeOpOutput { output, constraints, error_info } =
|
||||
op.fully_perform(self.infcx, locations.span(self.body))?;
|
||||
|
||||
debug!(?output, ?constraints);
|
||||
|
||||
|
@ -135,14 +136,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
) {
|
||||
let param_env = self.param_env;
|
||||
let predicate = predicate.to_predicate(self.tcx());
|
||||
self.fully_perform_op(
|
||||
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||
locations,
|
||||
category,
|
||||
param_env.and(type_op::prove_predicate::ProvePredicate::new(predicate)),
|
||||
)
|
||||
.unwrap_or_else(|NoSolution| {
|
||||
span_mirbug!(self, NoSolution, "could not prove {:?}", predicate);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
|
||||
|
@ -163,15 +161,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
|
||||
{
|
||||
let param_env = self.param_env;
|
||||
self.fully_perform_op(
|
||||
let result: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||
location.to_locations(),
|
||||
category,
|
||||
param_env.and(type_op::normalize::Normalize::new(value)),
|
||||
)
|
||||
.unwrap_or_else(|NoSolution| {
|
||||
span_mirbug!(self, NoSolution, "failed to normalize `{:?}`", value);
|
||||
value
|
||||
})
|
||||
);
|
||||
result.unwrap_or(value)
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
|
@ -181,18 +176,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
user_ty: ty::UserType<'tcx>,
|
||||
span: Span,
|
||||
) {
|
||||
self.fully_perform_op(
|
||||
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||
Locations::All(span),
|
||||
ConstraintCategory::Boring,
|
||||
self.param_env.and(type_op::ascribe_user_type::AscribeUserType::new(mir_ty, user_ty)),
|
||||
)
|
||||
.unwrap_or_else(|err| {
|
||||
span_mirbug!(
|
||||
self,
|
||||
span,
|
||||
"ascribe_user_type `{mir_ty:?}=={user_ty:?}` failed with `{err:?}`",
|
||||
);
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
/// *Incorrectly* skips the WF checks we normally do in `ascribe_user_type`.
|
||||
|
@ -219,7 +207,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
|
||||
let cause = ObligationCause::dummy_with_span(span);
|
||||
let param_env = self.param_env;
|
||||
self.fully_perform_op(
|
||||
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||
Locations::All(span),
|
||||
ConstraintCategory::Boring,
|
||||
type_op::custom::CustomTypeOp::new(
|
||||
|
@ -230,13 +218,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
},
|
||||
"ascribe_user_type_skip_wf",
|
||||
),
|
||||
)
|
||||
.unwrap_or_else(|err| {
|
||||
span_mirbug!(
|
||||
self,
|
||||
span,
|
||||
"ascribe_user_type_skip_wf `{mir_ty:?}=={user_ty:?}` failed with `{err:?}`",
|
||||
);
|
||||
});
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
|
|||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::traits::query::OutlivesBound;
|
||||
use rustc_middle::ty::{self, RegionVid, Ty};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
|
||||
use std::rc::Rc;
|
||||
use type_op::TypeOpOutput;
|
||||
|
@ -243,18 +243,11 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
|||
let TypeOpOutput { output: norm_ty, constraints: constraints_normalize, .. } = self
|
||||
.param_env
|
||||
.and(type_op::normalize::Normalize::new(ty))
|
||||
.fully_perform(self.infcx)
|
||||
.unwrap_or_else(|_| {
|
||||
let guar = self
|
||||
.infcx
|
||||
.tcx
|
||||
.sess
|
||||
.delay_span_bug(span, format!("failed to normalize {:?}", ty));
|
||||
TypeOpOutput {
|
||||
output: self.infcx.tcx.ty_error(guar),
|
||||
constraints: None,
|
||||
error_info: None,
|
||||
}
|
||||
.fully_perform(self.infcx, span)
|
||||
.unwrap_or_else(|guar| TypeOpOutput {
|
||||
output: self.infcx.tcx.ty_error(guar),
|
||||
constraints: None,
|
||||
error_info: None,
|
||||
});
|
||||
if let Some(c) = constraints_normalize {
|
||||
constraints.push(c)
|
||||
|
@ -324,7 +317,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
|||
let TypeOpOutput { output: bounds, constraints, .. } = self
|
||||
.param_env
|
||||
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
|
||||
.fully_perform(self.infcx)
|
||||
.fully_perform(self.infcx, DUMMY_SP)
|
||||
.unwrap_or_else(|_| bug!("failed to compute implied bounds {:?}", ty));
|
||||
debug!(?bounds, ?constraints);
|
||||
self.add_outlives_bounds(bounds);
|
||||
|
|
|
@ -4,6 +4,7 @@ use rustc_index::interval::IntervalSet;
|
|||
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
||||
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
|
||||
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_trait_selection::traits::query::dropck_outlives::DropckOutlivesResult;
|
||||
use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives;
|
||||
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
|
||||
|
@ -568,10 +569,15 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
|||
) -> DropData<'tcx> {
|
||||
debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,);
|
||||
|
||||
let param_env = typeck.param_env;
|
||||
let TypeOpOutput { output, constraints, .. } =
|
||||
param_env.and(DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx).unwrap();
|
||||
|
||||
DropData { dropck_result: output, region_constraint_data: constraints }
|
||||
match typeck
|
||||
.param_env
|
||||
.and(DropckOutlives::new(dropped_ty))
|
||||
.fully_perform(typeck.infcx, DUMMY_SP)
|
||||
{
|
||||
Ok(TypeOpOutput { output, constraints, .. }) => {
|
||||
DropData { dropck_result: output, region_constraint_data: constraints }
|
||||
}
|
||||
Err(_) => DropData { dropck_result: Default::default(), region_constraint_data: None },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use either::Either;
|
|||
use hir::OpaqueTyOrigin;
|
||||
use rustc_data_structures::frozen::Frozen;
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
|
@ -216,24 +217,22 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
|||
let opaque_type_values = opaque_type_values
|
||||
.into_iter()
|
||||
.map(|(opaque_type_key, decl)| {
|
||||
checker
|
||||
.fully_perform_op(
|
||||
Locations::All(body.span),
|
||||
ConstraintCategory::OpaqueType,
|
||||
CustomTypeOp::new(
|
||||
|ocx| {
|
||||
ocx.infcx.register_member_constraints(
|
||||
param_env,
|
||||
opaque_type_key,
|
||||
decl.hidden_type.ty,
|
||||
decl.hidden_type.span,
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
"opaque_type_map",
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let _: Result<_, ErrorGuaranteed> = checker.fully_perform_op(
|
||||
Locations::All(body.span),
|
||||
ConstraintCategory::OpaqueType,
|
||||
CustomTypeOp::new(
|
||||
|ocx| {
|
||||
ocx.infcx.register_member_constraints(
|
||||
param_env,
|
||||
opaque_type_key,
|
||||
decl.hidden_type.ty,
|
||||
decl.hidden_type.span,
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
"opaque_type_map",
|
||||
),
|
||||
);
|
||||
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
|
||||
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
|
||||
if hidden_type.has_non_region_infer() {
|
||||
|
@ -2755,11 +2754,20 @@ impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
|
|||
/// constraints in our `InferCtxt`
|
||||
type ErrorInfo = InstantiateOpaqueType<'tcx>;
|
||||
|
||||
fn fully_perform(mut self, infcx: &InferCtxt<'tcx>) -> Fallible<TypeOpOutput<'tcx, Self>> {
|
||||
let (mut output, region_constraints) = scrape_region_constraints(infcx, |ocx| {
|
||||
ocx.register_obligations(self.obligations.clone());
|
||||
Ok(())
|
||||
})?;
|
||||
fn fully_perform(
|
||||
mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
span: Span,
|
||||
) -> Result<TypeOpOutput<'tcx, Self>, ErrorGuaranteed> {
|
||||
let (mut output, region_constraints) = scrape_region_constraints(
|
||||
infcx,
|
||||
|ocx| {
|
||||
ocx.register_obligations(self.obligations.clone());
|
||||
Ok(())
|
||||
},
|
||||
"InstantiateOpaqueType",
|
||||
span,
|
||||
)?;
|
||||
self.region_constraints = Some(region_constraints);
|
||||
output.error_info = Some(self);
|
||||
Ok(output)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_infer::infer::nll_relate::{TypeRelating, TypeRelatingDelegate};
|
||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||
use rustc_infer::traits::PredicateObligations;
|
||||
|
@ -185,7 +186,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
|
|||
}
|
||||
|
||||
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
|
||||
match self.type_checker.fully_perform_op(
|
||||
let _: Result<_, ErrorGuaranteed> = self.type_checker.fully_perform_op(
|
||||
self.locations,
|
||||
self.category,
|
||||
InstantiateOpaqueType {
|
||||
|
@ -194,16 +195,6 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
|
|||
base_universe: None,
|
||||
region_constraints: None,
|
||||
},
|
||||
) {
|
||||
Ok(()) => {}
|
||||
Err(_) => {
|
||||
// It's a bit redundant to delay a bug here, but I'd rather
|
||||
// delay more bugs than accidentally not delay a bug at all.
|
||||
self.type_checker.tcx().sess.delay_span_bug(
|
||||
self.locations.span(self.type_checker.body),
|
||||
"errors selecting obligation during MIR typeck",
|
||||
);
|
||||
}
|
||||
};
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue