@@ -16,6 +16,7 @@ use super::CodeSelectionError;
1616use  super :: { ConstEvalFailure ,  Unimplemented } ; 
1717use  super :: { FulfillmentError ,  FulfillmentErrorCode } ; 
1818use  super :: { ObligationCause ,  PredicateObligation } ; 
19+ use  crate :: traits:: TraitQueryMode ; 
1920
2021impl < ' tcx >  ForestObligation  for  PendingPredicateObligation < ' tcx >  { 
2122    type  Predicate  = ty:: Predicate < ' tcx > ; 
@@ -62,6 +63,9 @@ pub struct FulfillmentContext<'tcx> {
6263    // a snapshot (they don't *straddle* a snapshot, so there 
6364    // is no trouble there). 
6465    usable_in_snapshot :  bool , 
66+ 
67+     // The `TraitQueryMode` used when constructing a `SelectionContext` 
68+     query_mode :  TraitQueryMode , 
6569} 
6670
6771#[ derive( Clone ,  Debug ) ]  
@@ -75,12 +79,26 @@ pub struct PendingPredicateObligation<'tcx> {
7579static_assert_size ! ( PendingPredicateObligation <' _>,  136 ) ; 
7680
7781impl < ' a ,  ' tcx >  FulfillmentContext < ' tcx >  { 
78-     /// Creates a new fulfillment context. 
82+     /// Creates a new fulfillment context with `TraitQueryMode::Standard` 
83+ /// You almost always want to use this instead of `with_query_mode` 
7984pub  fn  new ( )  -> FulfillmentContext < ' tcx >  { 
8085        FulfillmentContext  { 
8186            predicates :  ObligationForest :: new ( ) , 
8287            register_region_obligations :  true , 
8388            usable_in_snapshot :  false , 
89+             query_mode :  TraitQueryMode :: Standard , 
90+         } 
91+     } 
92+ 
93+     /// Creates a new fulfillment context with the specified query mode. 
94+ /// This should only be used when you want to ignore overflow, 
95+ /// rather than reporting it as an error. 
96+ pub  fn  with_query_mode ( query_mode :  TraitQueryMode )  -> FulfillmentContext < ' tcx >  { 
97+         FulfillmentContext  { 
98+             predicates :  ObligationForest :: new ( ) , 
99+             register_region_obligations :  true , 
100+             usable_in_snapshot :  false , 
101+             query_mode, 
84102        } 
85103    } 
86104
@@ -89,6 +107,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
89107            predicates :  ObligationForest :: new ( ) , 
90108            register_region_obligations :  true , 
91109            usable_in_snapshot :  true , 
110+             query_mode :  TraitQueryMode :: Standard , 
92111        } 
93112    } 
94113
@@ -97,6 +116,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
97116            predicates :  ObligationForest :: new ( ) , 
98117            register_region_obligations :  false , 
99118            usable_in_snapshot :  false , 
119+             query_mode :  TraitQueryMode :: Standard , 
100120        } 
101121    } 
102122
@@ -217,7 +237,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
217237        & mut  self , 
218238        infcx :  & InferCtxt < ' _ ,  ' tcx > , 
219239    )  -> Result < ( ) ,  Vec < FulfillmentError < ' tcx > > >  { 
220-         let  mut  selcx = SelectionContext :: new ( infcx) ; 
240+         let  mut  selcx = SelectionContext :: with_query_mode ( infcx,   self . query_mode ) ; 
221241        self . select ( & mut  selcx) 
222242    } 
223243
0 commit comments