@@ -27,70 +27,36 @@ pub(crate) enum UndoLog<'tcx> {
2727 PushRegionObligation ,
2828}
2929
30- impl < ' tcx > From < region_constraints:: UndoLog < ' tcx > > for UndoLog < ' tcx > {
31- fn from ( l : region_constraints:: UndoLog < ' tcx > ) -> Self {
32- UndoLog :: RegionConstraintCollector ( l)
33- }
34- }
35-
36- impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < type_variable:: TyVidEqKey < ' tcx > > > > for UndoLog < ' tcx > {
37- fn from ( l : sv:: UndoLog < ut:: Delegate < type_variable:: TyVidEqKey < ' tcx > > > ) -> Self {
38- UndoLog :: TypeVariables ( type_variable:: UndoLog :: EqRelation ( l) )
39- }
40- }
41-
42- impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < ty:: TyVid > > > for UndoLog < ' tcx > {
43- fn from ( l : sv:: UndoLog < ut:: Delegate < ty:: TyVid > > ) -> Self {
44- UndoLog :: TypeVariables ( type_variable:: UndoLog :: SubRelation ( l) )
45- }
46- }
47-
48- impl < ' tcx > From < sv:: UndoLog < type_variable:: Delegate > > for UndoLog < ' tcx > {
49- fn from ( l : sv:: UndoLog < type_variable:: Delegate > ) -> Self {
50- UndoLog :: TypeVariables ( type_variable:: UndoLog :: Values ( l) )
51- }
52- }
53-
54- impl < ' tcx > From < type_variable:: Instantiate > for UndoLog < ' tcx > {
55- fn from ( l : type_variable:: Instantiate ) -> Self {
56- UndoLog :: TypeVariables ( type_variable:: UndoLog :: from ( l) )
30+ macro_rules! impl_from {
31+ ( $( $ctor: ident ( $ty: ty) , ) * ) => {
32+ $(
33+ impl <' tcx> From <$ty> for UndoLog <' tcx> {
34+ fn from( x: $ty) -> Self {
35+ UndoLog :: $ctor( x. into( ) )
36+ }
37+ }
38+ ) *
5739 }
5840}
5941
60- impl From < type_variable:: UndoLog < ' tcx > > for UndoLog < ' tcx > {
61- fn from ( t : type_variable:: UndoLog < ' tcx > ) -> Self {
62- Self :: TypeVariables ( t)
63- }
64- }
42+ // Upcast from a single kind of "undoable action" to the general enum
43+ impl_from ! {
44+ RegionConstraintCollector ( region_constraints:: UndoLog <' tcx>) ,
45+ TypeVariables ( type_variable:: UndoLog <' tcx>) ,
6546
66- impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < ty:: ConstVid < ' tcx > > > > for UndoLog < ' tcx > {
67- fn from ( l : sv:: UndoLog < ut:: Delegate < ty:: ConstVid < ' tcx > > > ) -> Self {
68- Self :: ConstUnificationTable ( l)
69- }
70- }
47+ TypeVariables ( sv:: UndoLog <ut:: Delegate <type_variable:: TyVidEqKey <' tcx>>>) ,
48+ TypeVariables ( sv:: UndoLog <ut:: Delegate <ty:: TyVid >>) ,
49+ TypeVariables ( sv:: UndoLog <type_variable:: Delegate >) ,
50+ TypeVariables ( type_variable:: Instantiate ) ,
7151
72- impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < ty:: IntVid > > > for UndoLog < ' tcx > {
73- fn from ( l : sv:: UndoLog < ut:: Delegate < ty:: IntVid > > ) -> Self {
74- Self :: IntUnificationTable ( l)
75- }
76- }
52+ IntUnificationTable ( sv:: UndoLog <ut:: Delegate <ty:: IntVid >>) ,
7753
78- impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < ty:: FloatVid > > > for UndoLog < ' tcx > {
79- fn from ( l : sv:: UndoLog < ut:: Delegate < ty:: FloatVid > > ) -> Self {
80- Self :: FloatUnificationTable ( l)
81- }
82- }
54+ FloatUnificationTable ( sv:: UndoLog <ut:: Delegate <ty:: FloatVid >>) ,
8355
84- impl < ' tcx > From < sv:: UndoLog < ut:: Delegate < ty:: RegionVid > > > for UndoLog < ' tcx > {
85- fn from ( l : sv:: UndoLog < ut:: Delegate < ty:: RegionVid > > ) -> Self {
86- Self :: RegionUnificationTable ( l)
87- }
88- }
56+ ConstUnificationTable ( sv:: UndoLog <ut:: Delegate <ty:: ConstVid <' tcx>>>) ,
8957
90- impl < ' tcx > From < traits:: UndoLog < ' tcx > > for UndoLog < ' tcx > {
91- fn from ( l : traits:: UndoLog < ' tcx > ) -> Self {
92- Self :: ProjectionCache ( l)
93- }
58+ RegionUnificationTable ( sv:: UndoLog <ut:: Delegate <ty:: RegionVid >>) ,
59+ ProjectionCache ( traits:: UndoLog <' tcx>) ,
9460}
9561
9662impl < ' tcx > Rollback < UndoLog < ' tcx > > for InferCtxtInner < ' tcx > {
0 commit comments