1
- use super :: { AllocId , ConstAlloc , Pointer , Scalar } ;
1
+ use super :: { AllocId , AllocRange , ConstAlloc , Pointer , Scalar } ;
2
2
3
3
use crate :: mir:: interpret:: ConstValue ;
4
4
use crate :: ty:: { layout, query:: TyCtxtAt , tls, FnSig , Ty , ValTree } ;
@@ -162,9 +162,9 @@ impl fmt::Display for InvalidProgramInfo<'_> {
162
162
AlreadyReported ( ErrorGuaranteed { .. } ) => {
163
163
write ! ( f, "encountered constants with type errors, stopping evaluation" )
164
164
}
165
- Layout ( ref err) => write ! ( f, "{}" , err ) ,
166
- FnAbiAdjustForForeignAbi ( ref err) => write ! ( f, "{}" , err ) ,
167
- SizeOfUnsizedType ( ty) => write ! ( f, "size_of called on unsized type `{}`" , ty ) ,
165
+ Layout ( ref err) => write ! ( f, "{err}" ) ,
166
+ FnAbiAdjustForForeignAbi ( ref err) => write ! ( f, "{err}" ) ,
167
+ SizeOfUnsizedType ( ty) => write ! ( f, "size_of called on unsized type `{ty }`" ) ,
168
168
}
169
169
}
170
170
}
@@ -205,14 +205,10 @@ impl fmt::Display for CheckInAllocMsg {
205
205
/// Details of an access to uninitialized bytes where it is not allowed.
206
206
#[ derive( Debug ) ]
207
207
pub struct UninitBytesAccess {
208
- /// Location of the original memory access.
209
- pub access_offset : Size ,
210
- /// Size of the original memory access.
211
- pub access_size : Size ,
212
- /// Location of the first uninitialized byte that was accessed.
213
- pub uninit_offset : Size ,
214
- /// Number of consecutive uninitialized bytes that were accessed.
215
- pub uninit_size : Size ,
208
+ /// Range of the original memory access.
209
+ pub access : AllocRange ,
210
+ /// Range of the uninit memory that was encountered. (Might not be maximal.)
211
+ pub uninit : AllocRange ,
216
212
}
217
213
218
214
/// Information about a size mismatch.
@@ -308,30 +304,28 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
308
304
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
309
305
use UndefinedBehaviorInfo :: * ;
310
306
match self {
311
- Ub ( msg) => write ! ( f, "{}" , msg ) ,
307
+ Ub ( msg) => write ! ( f, "{msg}" ) ,
312
308
Unreachable => write ! ( f, "entering unreachable code" ) ,
313
309
BoundsCheckFailed { ref len, ref index } => {
314
- write ! ( f, "indexing out of bounds: the len is {} but the index is {}" , len , index )
310
+ write ! ( f, "indexing out of bounds: the len is {len } but the index is {index}" )
315
311
}
316
312
DivisionByZero => write ! ( f, "dividing by zero" ) ,
317
313
RemainderByZero => write ! ( f, "calculating the remainder with a divisor of zero" ) ,
318
314
DivisionOverflow => write ! ( f, "overflow in signed division (dividing MIN by -1)" ) ,
319
315
RemainderOverflow => write ! ( f, "overflow in signed remainder (dividing MIN by -1)" ) ,
320
316
PointerArithOverflow => write ! ( f, "overflowing in-bounds pointer arithmetic" ) ,
321
- InvalidMeta ( msg) => write ! ( f, "invalid metadata in wide pointer: {}" , msg ) ,
317
+ InvalidMeta ( msg) => write ! ( f, "invalid metadata in wide pointer: {msg}" ) ,
322
318
InvalidVtableDropFn ( sig) => write ! (
323
319
f,
324
- "invalid drop function signature: got {}, expected exactly one argument which must be a pointer type" ,
325
- sig
320
+ "invalid drop function signature: got {sig}, expected exactly one argument which must be a pointer type" ,
326
321
) ,
327
322
InvalidVtableSize => {
328
323
write ! ( f, "invalid vtable: size is bigger than largest supported object" )
329
324
}
330
- InvalidVtableAlignment ( msg) => write ! ( f, "invalid vtable: alignment {}" , msg ) ,
325
+ InvalidVtableAlignment ( msg) => write ! ( f, "invalid vtable: alignment {msg}" ) ,
331
326
UnterminatedCString ( p) => write ! (
332
327
f,
333
- "reading a null-terminated string starting at {:?} with no null found before end of allocation" ,
334
- p,
328
+ "reading a null-terminated string starting at {p:?} with no null found before end of allocation" ,
335
329
) ,
336
330
PointerUseAfterFree ( a) => {
337
331
write ! ( f, "pointer to {a:?} was dereferenced after this allocation got freed" )
@@ -359,41 +353,36 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
359
353
}
360
354
AlignmentCheckFailed { required, has } => write ! (
361
355
f,
362
- "accessing memory with alignment {}, but alignment {} is required" ,
363
- has. bytes( ) ,
364
- required. bytes( )
356
+ "accessing memory with alignment {has }, but alignment {required } is required" ,
357
+ has = has . bytes( ) ,
358
+ required = required . bytes( )
365
359
) ,
366
360
WriteToReadOnly ( a) => write ! ( f, "writing to {a:?} which is read-only" ) ,
367
361
DerefFunctionPointer ( a) => write ! ( f, "accessing {a:?} which contains a function" ) ,
368
362
ValidationFailure { path : None , msg } => {
369
- write ! ( f, "constructing invalid value: {}" , msg )
363
+ write ! ( f, "constructing invalid value: {msg}" )
370
364
}
371
365
ValidationFailure { path : Some ( path) , msg } => {
372
- write ! ( f, "constructing invalid value at {}: {}" , path , msg )
366
+ write ! ( f, "constructing invalid value at {path }: {msg}" )
373
367
}
374
368
InvalidBool ( b) => {
375
- write ! ( f, "interpreting an invalid 8-bit value as a bool: 0x{:02x}" , b )
369
+ write ! ( f, "interpreting an invalid 8-bit value as a bool: 0x{b :02x}" )
376
370
}
377
371
InvalidChar ( c) => {
378
- write ! ( f, "interpreting an invalid 32-bit value as a char: 0x{:08x}" , c )
372
+ write ! ( f, "interpreting an invalid 32-bit value as a char: 0x{c :08x}" )
379
373
}
380
- InvalidTag ( val) => write ! ( f, "enum value has invalid tag: {:x}" , val ) ,
374
+ InvalidTag ( val) => write ! ( f, "enum value has invalid tag: {val :x}" ) ,
381
375
InvalidFunctionPointer ( p) => {
382
- write ! ( f, "using {:?} as function pointer but it does not point to a function" , p )
376
+ write ! ( f, "using {p :?} as function pointer but it does not point to a function" )
383
377
}
384
- InvalidStr ( err) => write ! ( f, "this string is not valid UTF-8: {}" , err ) ,
385
- InvalidUninitBytes ( Some ( ( alloc, access ) ) ) => write ! (
378
+ InvalidStr ( err) => write ! ( f, "this string is not valid UTF-8: {err}" ) ,
379
+ InvalidUninitBytes ( Some ( ( alloc, info ) ) ) => write ! (
386
380
f,
387
- "reading {} byte{} of memory starting at {:?}, \
388
- but {} byte{} {} uninitialized starting at {:?}, \
381
+ "reading memory at {alloc:?}{access :?}, \
382
+ but memory is uninitialized at {uninit :?}, \
389
383
and this operation requires initialized memory",
390
- access. access_size. bytes( ) ,
391
- pluralize!( access. access_size. bytes( ) ) ,
392
- Pointer :: new( * alloc, access. access_offset) ,
393
- access. uninit_size. bytes( ) ,
394
- pluralize!( access. uninit_size. bytes( ) ) ,
395
- pluralize!( "is" , access. uninit_size. bytes( ) ) ,
396
- Pointer :: new( * alloc, access. uninit_offset) ,
384
+ access = info. access,
385
+ uninit = info. uninit,
397
386
) ,
398
387
InvalidUninitBytes ( None ) => write ! (
399
388
f,
@@ -402,8 +391,7 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
402
391
DeadLocal => write ! ( f, "accessing a dead local variable" ) ,
403
392
ScalarSizeMismatch ( self :: ScalarSizeMismatch { target_size, data_size } ) => write ! (
404
393
f,
405
- "scalar size mismatch: expected {} bytes but got {} bytes instead" ,
406
- target_size, data_size
394
+ "scalar size mismatch: expected {target_size} bytes but got {data_size} bytes instead" ,
407
395
) ,
408
396
UninhabitedEnumVariantWritten => {
409
397
write ! ( f, "writing discriminant of an uninhabited enum" )
@@ -437,13 +425,13 @@ impl fmt::Display for UnsupportedOpInfo {
437
425
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
438
426
use UnsupportedOpInfo :: * ;
439
427
match self {
440
- Unsupported ( ref msg) => write ! ( f, "{}" , msg ) ,
428
+ Unsupported ( ref msg) => write ! ( f, "{msg}" ) ,
441
429
ReadPointerAsBytes => write ! ( f, "unable to turn pointer into raw bytes" ) ,
442
430
PartialPointerOverwrite ( ptr) => {
443
- write ! ( f, "unable to overwrite parts of a pointer in memory at {:?}" , ptr )
431
+ write ! ( f, "unable to overwrite parts of a pointer in memory at {ptr :?}" )
444
432
}
445
- ThreadLocalStatic ( did) => write ! ( f, "cannot access thread local static ({:?})" , did ) ,
446
- ReadExternStatic ( did) => write ! ( f, "cannot read from extern static ({:?})" , did ) ,
433
+ ThreadLocalStatic ( did) => write ! ( f, "cannot access thread local static ({did :?})" ) ,
434
+ ReadExternStatic ( did) => write ! ( f, "cannot read from extern static ({did :?})" ) ,
447
435
}
448
436
}
449
437
}
@@ -526,11 +514,11 @@ impl fmt::Display for InterpError<'_> {
526
514
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
527
515
use InterpError :: * ;
528
516
match * self {
529
- Unsupported ( ref msg) => write ! ( f, "{}" , msg ) ,
530
- InvalidProgram ( ref msg) => write ! ( f, "{}" , msg ) ,
531
- UndefinedBehavior ( ref msg) => write ! ( f, "{}" , msg ) ,
532
- ResourceExhaustion ( ref msg) => write ! ( f, "{}" , msg ) ,
533
- MachineStop ( ref msg) => write ! ( f, "{}" , msg ) ,
517
+ Unsupported ( ref msg) => write ! ( f, "{msg}" ) ,
518
+ InvalidProgram ( ref msg) => write ! ( f, "{msg}" ) ,
519
+ UndefinedBehavior ( ref msg) => write ! ( f, "{msg}" ) ,
520
+ ResourceExhaustion ( ref msg) => write ! ( f, "{msg}" ) ,
521
+ MachineStop ( ref msg) => write ! ( f, "{msg}" ) ,
534
522
}
535
523
}
536
524
}
0 commit comments