Skip to content

Commit 7901c03

Browse files
committed
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.
1 parent bf1a5c2 commit 7901c03

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+13-25
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ use crate::session_diagnostics::{
3131
HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError,
3232
};
3333

34-
#[derive(Clone)]
35-
pub(crate) struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>);
36-
3734
/// What operation a universe was created for.
3835
#[derive(Clone)]
39-
enum UniverseInfoInner<'tcx> {
36+
pub(crate) enum UniverseInfo<'tcx> {
4037
/// Relating two types which have binders.
4138
RelateTys { expected: Ty<'tcx>, found: Ty<'tcx> },
4239
/// Created from performing a `TypeOp`.
@@ -47,11 +44,11 @@ enum UniverseInfoInner<'tcx> {
4744

4845
impl<'tcx> UniverseInfo<'tcx> {
4946
pub(crate) fn other() -> UniverseInfo<'tcx> {
50-
UniverseInfo(UniverseInfoInner::Other)
47+
UniverseInfo::Other
5148
}
5249

5350
pub(crate) fn relate(expected: Ty<'tcx>, found: Ty<'tcx>) -> UniverseInfo<'tcx> {
54-
UniverseInfo(UniverseInfoInner::RelateTys { expected, found })
51+
UniverseInfo::RelateTys { expected, found }
5552
}
5653

5754
pub(crate) fn report_error(
@@ -61,8 +58,8 @@ impl<'tcx> UniverseInfo<'tcx> {
6158
error_element: RegionElement,
6259
cause: ObligationCause<'tcx>,
6360
) {
64-
match self.0 {
65-
UniverseInfoInner::RelateTys { expected, found } => {
61+
match *self {
62+
UniverseInfo::RelateTys { expected, found } => {
6663
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
6764
&cause,
6865
mbcx.param_env,
@@ -72,10 +69,10 @@ impl<'tcx> UniverseInfo<'tcx> {
7269
);
7370
mbcx.buffer_error(err);
7471
}
75-
UniverseInfoInner::TypeOp(ref type_op_info) => {
72+
UniverseInfo::TypeOp(ref type_op_info) => {
7673
type_op_info.report_error(mbcx, placeholder, error_element, cause);
7774
}
78-
UniverseInfoInner::Other => {
75+
UniverseInfo::Other => {
7976
// FIXME: This error message isn't great, but it doesn't show
8077
// up in the existing UI tests. Consider investigating this
8178
// some more.
@@ -93,39 +90,30 @@ pub(crate) trait ToUniverseInfo<'tcx> {
9390

9491
impl<'tcx> ToUniverseInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
9592
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
96-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType {
93+
UniverseInfo::TypeOp(Rc::new(crate::type_check::InstantiateOpaqueType {
9794
base_universe: Some(base_universe),
9895
..self
99-
})))
96+
}))
10097
}
10198
}
10299

103100
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpProvePredicateGoal<'tcx> {
104101
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
105-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(PredicateQuery {
106-
canonical_query: self,
107-
base_universe,
108-
})))
102+
UniverseInfo::TypeOp(Rc::new(PredicateQuery { canonical_query: self, base_universe }))
109103
}
110104
}
111105

112106
impl<'tcx, T: Copy + fmt::Display + TypeFoldable<TyCtxt<'tcx>> + 'tcx> ToUniverseInfo<'tcx>
113107
for CanonicalTypeOpNormalizeGoal<'tcx, T>
114108
{
115109
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
116-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(NormalizeQuery {
117-
canonical_query: self,
118-
base_universe,
119-
})))
110+
UniverseInfo::TypeOp(Rc::new(NormalizeQuery { canonical_query: self, base_universe }))
120111
}
121112
}
122113

123114
impl<'tcx> ToUniverseInfo<'tcx> for CanonicalTypeOpAscribeUserTypeGoal<'tcx> {
124115
fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
125-
UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery {
126-
canonical_query: self,
127-
base_universe,
128-
})))
116+
UniverseInfo::TypeOp(Rc::new(AscribeUserTypeQuery { canonical_query: self, base_universe }))
129117
}
130118
}
131119

@@ -143,7 +131,7 @@ impl<'tcx> ToUniverseInfo<'tcx> for ! {
143131
}
144132

145133
#[allow(unused_lifetimes)]
146-
trait TypeOpInfo<'tcx> {
134+
pub(crate) trait TypeOpInfo<'tcx> {
147135
/// Returns an error to be reported if rerunning the type op fails to
148136
/// recover the error's cause.
149137
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx>;

0 commit comments

Comments
 (0)