@@ -197,8 +197,8 @@ impl interpret::MayLeak for ! {
197
197
}
198
198
199
199
impl < ' mir , ' tcx : ' mir > CompileTimeEvalContext < ' mir , ' tcx > {
200
- fn guaranteed_eq ( & mut self , a : Scalar , b : Scalar ) -> bool {
201
- match ( a, b) {
200
+ fn guaranteed_eq ( & mut self , a : Scalar , b : Scalar ) -> InterpResult < ' tcx , bool > {
201
+ Ok ( match ( a, b) {
202
202
// Comparisons between integers are always known.
203
203
( Scalar :: Int { .. } , Scalar :: Int { .. } ) => a == b,
204
204
// Equality with integers can never be known for sure.
@@ -207,25 +207,25 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
207
207
// some things (like functions and vtables) do not have stable addresses
208
208
// so we need to be careful around them (see e.g. #73722).
209
209
( Scalar :: Ptr ( ..) , Scalar :: Ptr ( ..) ) => false ,
210
- }
210
+ } )
211
211
}
212
212
213
- fn guaranteed_ne ( & mut self , a : Scalar , b : Scalar ) -> bool {
214
- match ( a, b) {
213
+ fn guaranteed_ne ( & mut self , a : Scalar , b : Scalar ) -> InterpResult < ' tcx , bool > {
214
+ Ok ( match ( a, b) {
215
215
// Comparisons between integers are always known.
216
216
( Scalar :: Int ( _) , Scalar :: Int ( _) ) => a != b,
217
217
// Comparisons of abstract pointers with null pointers are known if the pointer
218
218
// is in bounds, because if they are in bounds, the pointer can't be null.
219
219
// Inequality with integers other than null can never be known for sure.
220
220
( Scalar :: Int ( int) , ptr @ Scalar :: Ptr ( ..) )
221
221
| ( ptr @ Scalar :: Ptr ( ..) , Scalar :: Int ( int) ) => {
222
- int. is_null ( ) && !self . scalar_may_be_null ( ptr)
222
+ int. is_null ( ) && !self . scalar_may_be_null ( ptr) ?
223
223
}
224
224
// FIXME: return `true` for at least some comparisons where we can reliably
225
225
// determine the result of runtime inequality tests at compile-time.
226
226
// Examples include comparison of addresses in different static items.
227
227
( Scalar :: Ptr ( ..) , Scalar :: Ptr ( ..) ) => false ,
228
- }
228
+ } )
229
229
}
230
230
}
231
231
@@ -329,9 +329,9 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
329
329
let a = ecx. read_immediate ( & args[ 0 ] ) ?. to_scalar ( ) ?;
330
330
let b = ecx. read_immediate ( & args[ 1 ] ) ?. to_scalar ( ) ?;
331
331
let cmp = if intrinsic_name == sym:: ptr_guaranteed_eq {
332
- ecx. guaranteed_eq ( a, b)
332
+ ecx. guaranteed_eq ( a, b) ?
333
333
} else {
334
- ecx. guaranteed_ne ( a, b)
334
+ ecx. guaranteed_ne ( a, b) ?
335
335
} ;
336
336
ecx. write_scalar ( Scalar :: from_bool ( cmp) , dest) ?;
337
337
}
0 commit comments