@@ -16,6 +16,7 @@ use super::CodeSelectionError;
16
16
use super :: { ConstEvalFailure , Unimplemented } ;
17
17
use super :: { FulfillmentError , FulfillmentErrorCode } ;
18
18
use super :: { ObligationCause , PredicateObligation } ;
19
+ use crate :: traits:: TraitQueryMode ;
19
20
20
21
impl < ' tcx > ForestObligation for PendingPredicateObligation < ' tcx > {
21
22
type Predicate = ty:: Predicate < ' tcx > ;
@@ -62,6 +63,9 @@ pub struct FulfillmentContext<'tcx> {
62
63
// a snapshot (they don't *straddle* a snapshot, so there
63
64
// is no trouble there).
64
65
usable_in_snapshot : bool ,
66
+
67
+ // The `TraitQueryMode` used when constructing a `SelectionContext`
68
+ query_mode : TraitQueryMode ,
65
69
}
66
70
67
71
#[ derive( Clone , Debug ) ]
@@ -75,12 +79,26 @@ pub struct PendingPredicateObligation<'tcx> {
75
79
static_assert_size ! ( PendingPredicateObligation <' _>, 136 ) ;
76
80
77
81
impl < ' 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`
79
84
pub fn new ( ) -> FulfillmentContext < ' tcx > {
80
85
FulfillmentContext {
81
86
predicates : ObligationForest :: new ( ) ,
82
87
register_region_obligations : true ,
83
88
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,
84
102
}
85
103
}
86
104
@@ -89,6 +107,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
89
107
predicates : ObligationForest :: new ( ) ,
90
108
register_region_obligations : true ,
91
109
usable_in_snapshot : true ,
110
+ query_mode : TraitQueryMode :: Standard ,
92
111
}
93
112
}
94
113
@@ -97,6 +116,7 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
97
116
predicates : ObligationForest :: new ( ) ,
98
117
register_region_obligations : false ,
99
118
usable_in_snapshot : false ,
119
+ query_mode : TraitQueryMode :: Standard ,
100
120
}
101
121
}
102
122
@@ -217,7 +237,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
217
237
& mut self ,
218
238
infcx : & InferCtxt < ' _ , ' tcx > ,
219
239
) -> Result < ( ) , Vec < FulfillmentError < ' tcx > > > {
220
- let mut selcx = SelectionContext :: new ( infcx) ;
240
+ let mut selcx = SelectionContext :: with_query_mode ( infcx, self . query_mode ) ;
221
241
self . select ( & mut selcx)
222
242
}
223
243
0 commit comments