Use extension trait derive
This commit is contained in:
parent
3250e95305
commit
9c25823bb4
29 changed files with 121 additions and 974 deletions
|
@ -13,30 +13,10 @@ use rustc_middle::ty::{self, TyCtxt};
|
|||
|
||||
/// FIXME(-Znext-solver): This or public because it is shared with the
|
||||
/// new trait solver implementation. We should deduplicate canonicalization.
|
||||
pub trait CanonicalExt<'tcx, V> {
|
||||
#[extension]
|
||||
pub impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
|
||||
/// Instantiate the wrapped value, replacing each canonical value
|
||||
/// with the value given in `var_values`.
|
||||
fn instantiate(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
|
||||
where
|
||||
V: TypeFoldable<TyCtxt<'tcx>>;
|
||||
|
||||
/// Allows one to apply a instantiation to some subset of
|
||||
/// `self.value`. Invoke `projection_fn` with `self.value` to get
|
||||
/// a value V that is expressed in terms of the same canonical
|
||||
/// variables bound in `self` (usually this extracts from subset
|
||||
/// of `self`). Apply the instantiation `var_values` to this value
|
||||
/// V, replacing each of the canonical variables.
|
||||
fn instantiate_projected<T>(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
var_values: &CanonicalVarValues<'tcx>,
|
||||
projection_fn: impl FnOnce(&V) -> T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<TyCtxt<'tcx>>;
|
||||
}
|
||||
|
||||
impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
|
||||
fn instantiate(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
|
||||
where
|
||||
V: TypeFoldable<TyCtxt<'tcx>>,
|
||||
|
@ -44,6 +24,12 @@ impl<'tcx, V> CanonicalExt<'tcx, V> for Canonical<'tcx, V> {
|
|||
self.instantiate_projected(tcx, var_values, |value| value.clone())
|
||||
}
|
||||
|
||||
/// Allows one to apply a instantiation to some subset of
|
||||
/// `self.value`. Invoke `projection_fn` with `self.value` to get
|
||||
/// a value V that is expressed in terms of the same canonical
|
||||
/// variables bound in `self` (usually this extracts from subset
|
||||
/// of `self`). Apply the instantiation `var_values` to this value
|
||||
/// V, replacing each of the canonical variables.
|
||||
fn instantiate_projected<T>(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
|
|
@ -2786,19 +2786,8 @@ pub enum FailureCode {
|
|||
Error0644,
|
||||
}
|
||||
|
||||
pub trait ObligationCauseExt<'tcx> {
|
||||
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode;
|
||||
|
||||
fn as_failure_code_diag(
|
||||
&self,
|
||||
terr: TypeError<'tcx>,
|
||||
span: Span,
|
||||
subdiags: Vec<TypeErrorAdditionalDiags>,
|
||||
) -> ObligationCauseFailureCode;
|
||||
fn as_requirement_str(&self) -> &'static str;
|
||||
}
|
||||
|
||||
impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
|
||||
#[extension]
|
||||
pub impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
|
||||
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode {
|
||||
use self::FailureCode::*;
|
||||
use crate::traits::ObligationCauseCode::*;
|
||||
|
|
|
@ -626,11 +626,8 @@ pub struct InferCtxtBuilder<'tcx> {
|
|||
next_trait_solver: bool,
|
||||
}
|
||||
|
||||
pub trait TyCtxtInferExt<'tcx> {
|
||||
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx>;
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
|
||||
#[extension]
|
||||
pub impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
|
||||
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
|
||||
InferCtxtBuilder {
|
||||
tcx: self,
|
||||
|
|
|
@ -52,18 +52,8 @@ pub trait TraitEngine<'tcx>: 'tcx {
|
|||
) -> Vec<PredicateObligation<'tcx>>;
|
||||
}
|
||||
|
||||
pub trait TraitEngineExt<'tcx> {
|
||||
fn register_predicate_obligations(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
|
||||
);
|
||||
|
||||
#[must_use]
|
||||
fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
|
||||
}
|
||||
|
||||
impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
|
||||
#[extension]
|
||||
pub impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
|
||||
fn register_predicate_obligations(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue