Merge UniverseInfo
and UniverseInfoInner
.
It's strange to have a struct that contains a single anonymous field that is an enum. This commit merges them. This does require increasing the visibility of `TypeOfInfo` to `pub(crate)`, but that seems worthwhile.
This commit is contained in:
parent
bf1a5c2b7f
commit
7901c03d2d
@ -31,12 +31,9 @@
|
|||||||
HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError,
|
HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub(crate) struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>);
|
|
||||||
|
|
||||||
/// What operation a universe was created for.
|
/// What operation a universe was created for.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum UniverseInfoInner<'tcx> {
|
pub(crate) enum UniverseInfo<'tcx> {
|
||||||
/// Relating two types which have binders.
|
/// Relating two types which have binders.
|
||||||
RelateTys { expected: Ty<'tcx>, found: Ty<'tcx> },
|
RelateTys { expected: Ty<'tcx>, found: Ty<'tcx> },
|
||||||
/// Created from performing a `TypeOp`.
|
/// Created from performing a `TypeOp`.
|
||||||
@ -47,11 +44,11 @@ enum UniverseInfoInner<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> UniverseInfo<'tcx> {
|
impl<'tcx> UniverseInfo<'tcx> {
|
||||||
pub(crate) fn other() -> UniverseInfo<'tcx> {
|
pub(crate) fn other() -> UniverseInfo<'tcx> {
|
||||||
UniverseInfo(UniverseInfoInner::Other)
|
UniverseInfo::Other
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn relate(expected: Ty<'tcx>, found: Ty<'tcx>) -> UniverseInfo<'tcx> {
|
pub(crate) fn relate(expected: Ty<'tcx>, found: Ty<'tcx>) -> UniverseInfo<'tcx> {
|
||||||
UniverseInfo(UniverseInfoInner::RelateTys { expected, found })
|
UniverseInfo::RelateTys { expected, found }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn report_error(
|
pub(crate) fn report_error(
|
||||||
@ -61,8 +58,8 @@ pub(crate) fn report_error(
|
|||||||
error_element: RegionElement,
|
error_element: RegionElement,
|
||||||
cause: ObligationCause<'tcx>,
|
cause: ObligationCause<'tcx>,
|
||||||
) {
|
) {
|
||||||
match self.0 {
|
match *self {
|
||||||
UniverseInfoInner::RelateTys { expected, found } => {
|
UniverseInfo::RelateTys { expected, found } => {
|
||||||
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
|
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
|
||||||
&cause,
|
&cause,
|
||||||
mbcx.param_env,
|
mbcx.param_env,
|
||||||
@ -72,10 +69,10 @@ pub(crate) fn report_error(
|
|||||||
);
|
);
|
||||||
mbcx.buffer_error(err);
|
mbcx.buffer_error(err);
|
||||||
}
|
}
|
||||||
UniverseInfoInner::TypeOp(ref type_op_info) => {
|
UniverseInfo::TypeOp(ref type_op_info) => {
|
||||||
type_op_info.report_error(mbcx, placeholder, error_element, cause);
|
type_op_info.report_error(mbcx, placeholder, error_element, cause);
|
||||||
}
|
}
|
||||||
UniverseInfoInner::Other => {
|
UniverseInfo::Other => {
|
||||||
// FIXME: This error message isn't great, but it doesn't show
|
// FIXME: This error message isn't great, but it doesn't show
|
||||||
// up in the existing UI tests. Consider investigating this
|
// up in the existing UI tests. Consider investigating this
|
||||||
// some more.
|
// some more.
|
||||||
@ -93,19 +90,16 @@ pub(crate) trait ToUniverseInfo<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToUniverseInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
|
impl<'tcx> ToUniverseInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
|
||||||
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
||||||
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType {
|
UniverseInfo::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType {
|
||||||
base_universe: Some(base_universe),
|
base_universe: Some(base_universe),
|
||||||
..self
|
..self
|
||||||
})))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpProvePredicateGoal<'tcx> {
|
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpProvePredicateGoal<'tcx> {
|
||||||
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
||||||
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(PredicateQuery {
|
UniverseInfo::TypeOp(Rc::new(PredicateQuery { canonical_query: self, base_universe }))
|
||||||
canonical_query: self,
|
|
||||||
base_universe,
|
|
||||||
})))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,19 +107,13 @@ impl<'tcx, T: Copy + fmt::Display + TypeFoldable<TyCtxt<'tcx>> + 'tcx> ToUnivers
|
|||||||
for CanonicalTypeOpNormalizeGoal<'tcx, T>
|
for CanonicalTypeOpNormalizeGoal<'tcx, T>
|
||||||
{
|
{
|
||||||
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
||||||
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(NormalizeQuery {
|
UniverseInfo::TypeOp(Rc::new(NormalizeQuery { canonical_query: self, base_universe }))
|
||||||
canonical_query: self,
|
|
||||||
base_universe,
|
|
||||||
})))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpAscribeUserTypeGoal<'tcx> {
|
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpAscribeUserTypeGoal<'tcx> {
|
||||||
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
||||||
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery {
|
UniverseInfo::TypeOp(Rc::new(AscribeUserTypeQuery { canonical_query: self, base_universe }))
|
||||||
canonical_query: self,
|
|
||||||
base_universe,
|
|
||||||
})))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +131,7 @@ fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tc
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_lifetimes)]
|
#[allow(unused_lifetimes)]
|
||||||
trait TypeOpInfo<'tcx> {
|
pub(crate) trait TypeOpInfo<'tcx> {
|
||||||
/// Returns an error to be reported if rerunning the type op fails to
|
/// Returns an error to be reported if rerunning the type op fails to
|
||||||
/// recover the error's cause.
|
/// recover the error's cause.
|
||||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx>;
|
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx>;
|
||||||
|
Loading…
Reference in New Issue
Block a user