@@ -27,70 +27,36 @@ pub(crate) enum UndoLog<'tcx> {
27
27
PushRegionObligation ,
28
28
}
29
29
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
+ ) *
57
39
}
58
40
}
59
41
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>) ,
65
46
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 ) ,
71
51
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 >>) ,
77
53
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 >>) ,
83
55
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>>>) ,
89
57
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>) ,
94
60
}
95
61
96
62
impl < ' tcx > Rollback < UndoLog < ' tcx > > for InferCtxtInner < ' tcx > {
0 commit comments