@@ -27,26 +27,42 @@ use rustc_session::config::TraitSolver;
2727use rustc_span:: Span ;
2828
2929pub 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 > ;
3232}
3333
3434impl < ' 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+ ) ,
4149 }
4250 }
4351
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+ ) ,
5066 }
5167 }
5268}
@@ -60,11 +76,11 @@ pub struct ObligationCtxt<'a, 'tcx> {
6076
6177impl < ' a , ' tcx > ObligationCtxt < ' a , ' tcx > {
6278 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) ) }
6480 }
6581
6682 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) ) }
6884 }
6985
7086 pub fn register_obligation ( & self , obligation : PredicateObligation < ' tcx > ) {
0 commit comments