@@ -8,21 +8,16 @@ use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement};
8
8
use rustc_middle:: ty:: GenericArgsRef ;
9
9
use rustc_middle:: ty:: { Ty , TyCtxt } ;
10
10
use rustc_middle:: {
11
- mir:: {
12
- self ,
13
- interpret:: {
14
- Allocation , ConstAllocation , GlobalId , InterpResult , PointerArithmetic , Scalar ,
15
- } ,
16
- BinOp , ConstValue , NonDivergingIntrinsic ,
17
- } ,
11
+ mir:: { self , BinOp , ConstValue , NonDivergingIntrinsic } ,
18
12
ty:: layout:: TyAndLayout ,
19
13
} ;
20
14
use rustc_span:: symbol:: { sym, Symbol } ;
21
15
use rustc_target:: abi:: Size ;
22
16
23
17
use super :: {
24
- memory:: MemoryKind , util:: ensure_monomorphic_enough, CheckInAllocMsg , ImmTy , InterpCx ,
25
- MPlaceTy , Machine , OpTy , Pointer ,
18
+ memory:: MemoryKind , util:: ensure_monomorphic_enough, Allocation , CheckInAllocMsg ,
19
+ ConstAllocation , GlobalId , ImmTy , InterpCx , InterpResult , MPlaceTy , Machine , OpTy , Pointer ,
20
+ PointerArithmetic , Scalar ,
26
21
} ;
27
22
28
23
use crate :: fluent_generated as fluent;
@@ -249,22 +244,30 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
249
244
match ( self . ptr_try_get_alloc_id ( a) , self . ptr_try_get_alloc_id ( b) ) {
250
245
( Err ( a) , Err ( b) ) => {
251
246
// Neither pointer points to an allocation.
252
- // If these are inequal, this *will* fail the deref check below.
247
+ // This is okay only if they are the same.
248
+ if a != b {
249
+ // We'd catch this below in the "dereferenceable" check, but
250
+ // show a nicer error for this particular case.
251
+ throw_ub_custom ! (
252
+ fluent:: const_eval_offset_from_different_integers,
253
+ name = intrinsic_name,
254
+ ) ;
255
+ }
253
256
( a, b)
254
257
}
255
258
( Err ( _) , _) | ( _, Err ( _) ) => {
256
259
// We managed to find a valid allocation for one pointer, but not the other.
257
260
// That means they are definitely not pointing to the same allocation.
258
261
throw_ub_custom ! (
259
- fluent:: const_eval_different_allocations ,
262
+ fluent:: const_eval_offset_from_different_allocations ,
260
263
name = intrinsic_name,
261
264
) ;
262
265
}
263
266
( Ok ( ( a_alloc_id, a_offset, _) ) , Ok ( ( b_alloc_id, b_offset, _) ) ) => {
264
267
// Found allocation for both. They must be into the same allocation.
265
268
if a_alloc_id != b_alloc_id {
266
269
throw_ub_custom ! (
267
- fluent:: const_eval_different_allocations ,
270
+ fluent:: const_eval_offset_from_different_allocations ,
268
271
name = intrinsic_name,
269
272
) ;
270
273
}
@@ -286,7 +289,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
286
289
// a < b
287
290
if intrinsic_name == sym:: ptr_offset_from_unsigned {
288
291
throw_ub_custom ! (
289
- fluent:: const_eval_unsigned_offset_from_overflow ,
292
+ fluent:: const_eval_offset_from_unsigned_overflow ,
290
293
a_offset = a_offset,
291
294
b_offset = b_offset,
292
295
) ;
0 commit comments