@@ -27,26 +27,42 @@ use rustc_session::config::TraitSolver;
27
27
use rustc_span:: Span ;
28
28
29
29
pub trait TraitEngineExt < ' tcx > {
30
- fn new ( tcx : TyCtxt < ' tcx > ) -> Box < Self > ;
31
- fn new_in_snapshot ( tcx : TyCtxt < ' tcx > ) -> Box < Self > ;
30
+ fn new ( infcx : & InferCtxt < ' tcx > ) -> Box < Self > ;
31
+ fn new_in_snapshot ( infcx : & InferCtxt < ' tcx > ) -> Box < Self > ;
32
32
}
33
33
34
34
impl < ' tcx > TraitEngineExt < ' tcx > for dyn TraitEngine < ' tcx > {
35
- fn new ( tcx : TyCtxt < ' tcx > ) -> Box < Self > {
36
- match tcx. sess . opts . unstable_opts . trait_solver {
37
- TraitSolver :: Classic => Box :: new ( FulfillmentContext :: new ( ) ) ,
38
- TraitSolver :: NextCoherence => Box :: new ( FulfillmentContext :: new ( ) ) ,
39
- TraitSolver :: Chalk => Box :: new ( ChalkFulfillmentContext :: new ( ) ) ,
40
- TraitSolver :: Next => Box :: new ( NextFulfillmentCtxt :: new ( ) ) ,
35
+ fn new ( infcx : & InferCtxt < ' tcx > ) -> Box < Self > {
36
+ match ( infcx. tcx . sess . opts . unstable_opts . trait_solver , infcx. next_trait_solver ( ) ) {
37
+ ( TraitSolver :: Classic , false ) | ( TraitSolver :: NextCoherence , false ) => {
38
+ Box :: new ( FulfillmentContext :: new ( ) )
39
+ }
40
+ ( TraitSolver :: Next | TraitSolver :: NextCoherence , true ) => {
41
+ Box :: new ( NextFulfillmentCtxt :: new ( ) )
42
+ }
43
+ ( TraitSolver :: Chalk , false ) => Box :: new ( ChalkFulfillmentContext :: new ( ) ) ,
44
+ _ => bug ! (
45
+ "incompatible combination of -Ztrait-solver flag ({:?}) and InferCtxt::next_trait_solver ({:?})" ,
46
+ infcx. tcx. sess. opts. unstable_opts. trait_solver,
47
+ infcx. next_trait_solver( )
48
+ ) ,
41
49
}
42
50
}
43
51
44
- fn new_in_snapshot ( tcx : TyCtxt < ' tcx > ) -> Box < Self > {
45
- match tcx. sess . opts . unstable_opts . trait_solver {
46
- TraitSolver :: Classic => Box :: new ( FulfillmentContext :: new_in_snapshot ( ) ) ,
47
- TraitSolver :: NextCoherence => Box :: new ( FulfillmentContext :: new_in_snapshot ( ) ) ,
48
- TraitSolver :: Chalk => Box :: new ( ChalkFulfillmentContext :: new_in_snapshot ( ) ) ,
49
- TraitSolver :: Next => Box :: new ( NextFulfillmentCtxt :: new ( ) ) ,
52
+ fn new_in_snapshot ( infcx : & InferCtxt < ' tcx > ) -> Box < Self > {
53
+ match ( infcx. tcx . sess . opts . unstable_opts . trait_solver , infcx. next_trait_solver ( ) ) {
54
+ ( TraitSolver :: Classic , false ) | ( TraitSolver :: NextCoherence , false ) => {
55
+ Box :: new ( FulfillmentContext :: new_in_snapshot ( ) )
56
+ }
57
+ ( TraitSolver :: Next | TraitSolver :: NextCoherence , true ) => {
58
+ Box :: new ( NextFulfillmentCtxt :: new ( ) )
59
+ }
60
+ ( TraitSolver :: Chalk , false ) => Box :: new ( ChalkFulfillmentContext :: new_in_snapshot ( ) ) ,
61
+ _ => bug ! (
62
+ "incompatible combination of -Ztrait-solver flag ({:?}) and InferCtxt::next_trait_solver ({:?})" ,
63
+ infcx. tcx. sess. opts. unstable_opts. trait_solver,
64
+ infcx. next_trait_solver( )
65
+ ) ,
50
66
}
51
67
}
52
68
}
@@ -60,11 +76,11 @@ pub struct ObligationCtxt<'a, 'tcx> {
60
76
61
77
impl < ' a , ' tcx > ObligationCtxt < ' a , ' tcx > {
62
78
pub fn new ( infcx : & ' a InferCtxt < ' tcx > ) -> Self {
63
- Self { infcx, engine : RefCell :: new ( <dyn TraitEngine < ' _ > >:: new ( infcx. tcx ) ) }
79
+ Self { infcx, engine : RefCell :: new ( <dyn TraitEngine < ' _ > >:: new ( infcx) ) }
64
80
}
65
81
66
82
pub fn new_in_snapshot ( infcx : & ' a InferCtxt < ' tcx > ) -> Self {
67
- Self { infcx, engine : RefCell :: new ( <dyn TraitEngine < ' _ > >:: new_in_snapshot ( infcx. tcx ) ) }
83
+ Self { infcx, engine : RefCell :: new ( <dyn TraitEngine < ' _ > >:: new_in_snapshot ( infcx) ) }
68
84
}
69
85
70
86
pub fn register_obligation ( & self , obligation : PredicateObligation < ' tcx > ) {
0 commit comments