1- use super :: { AllocId , ConstAlloc , Pointer , Scalar } ;
1+ use super :: { AllocId , AllocRange , ConstAlloc , Pointer , Scalar } ;
22
33use crate :: mir:: interpret:: ConstValue ;
44use crate :: ty:: { layout, query:: TyCtxtAt , tls, FnSig , Ty , ValTree } ;
@@ -162,9 +162,9 @@ impl fmt::Display for InvalidProgramInfo<'_> {
162162 AlreadyReported ( ErrorGuaranteed { .. } ) => {
163163 write ! ( f, "encountered constants with type errors, stopping evaluation" )
164164 }
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 }`" ) ,
168168 }
169169 }
170170}
@@ -205,14 +205,10 @@ impl fmt::Display for CheckInAllocMsg {
205205/// Details of an access to uninitialized bytes where it is not allowed.
206206#[ derive( Debug ) ]
207207pub 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 ,
216212}
217213
218214/// Information about a size mismatch.
@@ -308,30 +304,28 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
308304 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
309305 use UndefinedBehaviorInfo :: * ;
310306 match self {
311- Ub ( msg) => write ! ( f, "{}" , msg ) ,
307+ Ub ( msg) => write ! ( f, "{msg}" ) ,
312308 Unreachable => write ! ( f, "entering unreachable code" ) ,
313309 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}" )
315311 }
316312 DivisionByZero => write ! ( f, "dividing by zero" ) ,
317313 RemainderByZero => write ! ( f, "calculating the remainder with a divisor of zero" ) ,
318314 DivisionOverflow => write ! ( f, "overflow in signed division (dividing MIN by -1)" ) ,
319315 RemainderOverflow => write ! ( f, "overflow in signed remainder (dividing MIN by -1)" ) ,
320316 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}" ) ,
322318 InvalidVtableDropFn ( sig) => write ! (
323319 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" ,
326321 ) ,
327322 InvalidVtableSize => {
328323 write ! ( f, "invalid vtable: size is bigger than largest supported object" )
329324 }
330- InvalidVtableAlignment ( msg) => write ! ( f, "invalid vtable: alignment {}" , msg ) ,
325+ InvalidVtableAlignment ( msg) => write ! ( f, "invalid vtable: alignment {msg}" ) ,
331326 UnterminatedCString ( p) => write ! (
332327 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" ,
335329 ) ,
336330 PointerUseAfterFree ( a) => {
337331 write ! ( f, "pointer to {a:?} was dereferenced after this allocation got freed" )
@@ -359,41 +353,36 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
359353 }
360354 AlignmentCheckFailed { required, has } => write ! (
361355 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( )
365359 ) ,
366360 WriteToReadOnly ( a) => write ! ( f, "writing to {a:?} which is read-only" ) ,
367361 DerefFunctionPointer ( a) => write ! ( f, "accessing {a:?} which contains a function" ) ,
368362 ValidationFailure { path : None , msg } => {
369- write ! ( f, "constructing invalid value: {}" , msg )
363+ write ! ( f, "constructing invalid value: {msg}" )
370364 }
371365 ValidationFailure { path : Some ( path) , msg } => {
372- write ! ( f, "constructing invalid value at {}: {}" , path , msg )
366+ write ! ( f, "constructing invalid value at {path }: {msg}" )
373367 }
374368 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}" )
376370 }
377371 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}" )
379373 }
380- InvalidTag ( val) => write ! ( f, "enum value has invalid tag: {:x}" , val ) ,
374+ InvalidTag ( val) => write ! ( f, "enum value has invalid tag: {val :x}" ) ,
381375 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" )
383377 }
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 ! (
386380 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 :?}, \
389383 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,
397386 ) ,
398387 InvalidUninitBytes ( None ) => write ! (
399388 f,
@@ -402,8 +391,7 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
402391 DeadLocal => write ! ( f, "accessing a dead local variable" ) ,
403392 ScalarSizeMismatch ( self :: ScalarSizeMismatch { target_size, data_size } ) => write ! (
404393 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" ,
407395 ) ,
408396 UninhabitedEnumVariantWritten => {
409397 write ! ( f, "writing discriminant of an uninhabited enum" )
@@ -437,13 +425,13 @@ impl fmt::Display for UnsupportedOpInfo {
437425 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
438426 use UnsupportedOpInfo :: * ;
439427 match self {
440- Unsupported ( ref msg) => write ! ( f, "{}" , msg ) ,
428+ Unsupported ( ref msg) => write ! ( f, "{msg}" ) ,
441429 ReadPointerAsBytes => write ! ( f, "unable to turn pointer into raw bytes" ) ,
442430 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 :?}" )
444432 }
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 :?})" ) ,
447435 }
448436 }
449437}
@@ -526,11 +514,11 @@ impl fmt::Display for InterpError<'_> {
526514 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
527515 use InterpError :: * ;
528516 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}" ) ,
534522 }
535523 }
536524}
0 commit comments