@@ -176,6 +176,8 @@ pub struct Validator<'mir, 'tcx> {
176
176
177
177
/// The span of the current statement.
178
178
span : Span ,
179
+
180
+ const_checking_stopped : bool ,
179
181
}
180
182
181
183
impl Deref for Validator < ' mir , ' tcx > {
@@ -188,7 +190,12 @@ impl Deref for Validator<'mir, 'tcx> {
188
190
189
191
impl Validator < ' mir , ' tcx > {
190
192
pub fn new ( ccx : & ' mir ConstCx < ' mir , ' tcx > ) -> Self {
191
- Validator { span : ccx. body . span , ccx, qualifs : Default :: default ( ) }
193
+ Validator {
194
+ span : ccx. body . span ,
195
+ ccx,
196
+ qualifs : Default :: default ( ) ,
197
+ const_checking_stopped : false ,
198
+ }
192
199
}
193
200
194
201
pub fn check_body ( & mut self ) {
@@ -226,13 +233,22 @@ impl Validator<'mir, 'tcx> {
226
233
227
234
/// Emits an error if an expression cannot be evaluated in the current context.
228
235
pub fn check_op ( & mut self , op : impl NonConstOp ) {
229
- ops :: non_const ( self . ccx , op, self . span ) ;
236
+ self . check_op_spanned ( op, self . span ) ;
230
237
}
231
238
232
239
/// Emits an error at the given `span` if an expression cannot be evaluated in the current
233
240
/// context.
234
- pub fn check_op_spanned ( & mut self , op : impl NonConstOp , span : Span ) {
235
- ops:: non_const ( self . ccx , op, span) ;
241
+ pub fn check_op_spanned < O : NonConstOp > ( & mut self , op : O , span : Span ) {
242
+ // HACK: This is for strict equivalence with the old `qualify_min_const_fn` pass, which
243
+ // only emitted one error per function. It should be removed and the test output updated.
244
+ if self . const_checking_stopped {
245
+ return ;
246
+ }
247
+
248
+ let err_emitted = ops:: non_const ( self . ccx , op, span) ;
249
+ if err_emitted && O :: STOPS_CONST_CHECKING {
250
+ self . const_checking_stopped = true ;
251
+ }
236
252
}
237
253
238
254
fn check_static ( & mut self , def_id : DefId , span : Span ) {
0 commit comments