@@ -3,8 +3,7 @@ use super::{AllocId, Pointer, RawConst, ScalarMaybeUndef};
3
3
use crate :: mir:: interpret:: ConstValue ;
4
4
use crate :: ty:: layout:: LayoutError ;
5
5
use crate :: ty:: query:: TyCtxtAt ;
6
- use crate :: ty:: tls;
7
- use crate :: ty:: { self , layout, Ty } ;
6
+ use crate :: ty:: { self , layout, tls, FnSig , Ty } ;
8
7
9
8
use rustc_data_structures:: sync:: Lock ;
10
9
use rustc_errors:: { struct_span_err, DiagnosticBuilder , ErrorReported } ;
@@ -329,7 +328,7 @@ impl fmt::Display for CheckInAllocMsg {
329
328
}
330
329
331
330
/// Error information for when the program caused Undefined Behavior.
332
- pub enum UndefinedBehaviorInfo {
331
+ pub enum UndefinedBehaviorInfo < ' tcx > {
333
332
/// Free-form case. Only for errors that are never caught!
334
333
Ub ( String ) ,
335
334
/// Unreachable code was executed.
@@ -347,6 +346,8 @@ pub enum UndefinedBehaviorInfo {
347
346
PointerArithOverflow ,
348
347
/// Invalid metadata in a wide pointer (using `str` to avoid allocations).
349
348
InvalidMeta ( & ' static str ) ,
349
+ /// Invalid drop function in vtable.
350
+ InvalidDropFn ( FnSig < ' tcx > ) ,
350
351
/// Reading a C string that does not end within its allocation.
351
352
UnterminatedCString ( Pointer ) ,
352
353
/// Dereferencing a dangling pointer after it got freed.
@@ -380,6 +381,8 @@ pub enum UndefinedBehaviorInfo {
380
381
InvalidDiscriminant ( ScalarMaybeUndef ) ,
381
382
/// Using a pointer-not-to-a-function as function pointer.
382
383
InvalidFunctionPointer ( Pointer ) ,
384
+ /// Using a string that is not valid UTF-8,
385
+ InvalidStr ( std:: str:: Utf8Error ) ,
383
386
/// Using uninitialized data where it is not allowed.
384
387
InvalidUndefBytes ( Option < Pointer > ) ,
385
388
/// Working with a local that is not currently live.
@@ -391,7 +394,7 @@ pub enum UndefinedBehaviorInfo {
391
394
} ,
392
395
}
393
396
394
- impl fmt:: Display for UndefinedBehaviorInfo {
397
+ impl fmt:: Display for UndefinedBehaviorInfo < ' _ > {
395
398
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
396
399
use UndefinedBehaviorInfo :: * ;
397
400
match self {
@@ -404,6 +407,11 @@ impl fmt::Display for UndefinedBehaviorInfo {
404
407
RemainderByZero => write ! ( f, "calculating the remainder with a divisor of zero" ) ,
405
408
PointerArithOverflow => write ! ( f, "overflowing in-bounds pointer arithmetic" ) ,
406
409
InvalidMeta ( msg) => write ! ( f, "invalid metadata in wide pointer: {}" , msg) ,
410
+ InvalidDropFn ( sig) => write ! (
411
+ f,
412
+ "invalid drop function signature: got {}, expected exactly one argument which must be a pointer type" ,
413
+ sig
414
+ ) ,
407
415
UnterminatedCString ( p) => write ! (
408
416
f,
409
417
"reading a null-terminated string starting at {} with no null found before end of allocation" ,
@@ -446,6 +454,7 @@ impl fmt::Display for UndefinedBehaviorInfo {
446
454
InvalidFunctionPointer ( p) => {
447
455
write ! ( f, "using {} as function pointer but it does not point to a function" , p)
448
456
}
457
+ InvalidStr ( err) => write ! ( f, "this string is not valid UTF-8: {}" , err) ,
449
458
InvalidUndefBytes ( Some ( p) ) => write ! (
450
459
f,
451
460
"reading uninitialized memory at {}, but this operation requires initialized memory" ,
@@ -549,7 +558,7 @@ impl dyn MachineStopType {
549
558
550
559
pub enum InterpError < ' tcx > {
551
560
/// The program caused undefined behavior.
552
- UndefinedBehavior ( UndefinedBehaviorInfo ) ,
561
+ UndefinedBehavior ( UndefinedBehaviorInfo < ' tcx > ) ,
553
562
/// The program did something the interpreter does not support (some of these *might* be UB
554
563
/// but the interpreter is not sure).
555
564
Unsupported ( UnsupportedOpInfo ) ,
0 commit comments