@@ -2,7 +2,7 @@ use std::mem;
2
2
3
3
use rustc_errors:: { Diag , DiagArgName , DiagArgValue , DiagMessage , IntoDiagArg } ;
4
4
use rustc_middle:: mir:: AssertKind ;
5
- use rustc_middle:: mir:: interpret:: { Provenance , ReportedErrorInfo } ;
5
+ use rustc_middle:: mir:: interpret:: { AllocId , Provenance , ReportedErrorInfo } ;
6
6
use rustc_middle:: query:: TyCtxtAt ;
7
7
use rustc_middle:: ty:: layout:: LayoutError ;
8
8
use rustc_middle:: ty:: { ConstInt , TyCtxt } ;
@@ -11,8 +11,8 @@ use rustc_span::{Span, Symbol};
11
11
use super :: CompileTimeMachine ;
12
12
use crate :: errors:: { self , FrameNote , ReportErrorExt } ;
13
13
use crate :: interpret:: {
14
- ErrorHandled , Frame , InterpErrorInfo , InterpErrorKind , MachineStopType , err_inval ,
15
- err_machine_stop,
14
+ CtfeProvenance , ErrorHandled , Frame , InterpErrorInfo , InterpErrorKind , MachineStopType ,
15
+ Pointer , err_inval , err_machine_stop,
16
16
} ;
17
17
18
18
/// The CTFE machine has some custom error kinds.
@@ -22,8 +22,22 @@ pub enum ConstEvalErrKind {
22
22
ModifiedGlobal ,
23
23
RecursiveStatic ,
24
24
AssertFailure ( AssertKind < ConstInt > ) ,
25
- Panic { msg : Symbol , line : u32 , col : u32 , file : Symbol } ,
25
+ Panic {
26
+ msg : Symbol ,
27
+ line : u32 ,
28
+ col : u32 ,
29
+ file : Symbol ,
30
+ } ,
26
31
WriteThroughImmutablePointer ,
32
+ /// Called `const_make_global` twice.
33
+ ConstMakeGlobalPtrAlreadyMadeGlobal ( AllocId ) ,
34
+ /// Called `const_make_global` on a non-heap pointer.
35
+ ConstMakeGlobalPtrIsNonHeap ( Pointer < Option < CtfeProvenance > > ) ,
36
+ /// Called `const_make_global` on a dangling pointer.
37
+ ConstMakeGlobalWithDanglingPtr ( Pointer < Option < CtfeProvenance > > ) ,
38
+ /// Called `const_make_global` on a pointer that does not start at the
39
+ /// beginning of an object.
40
+ ConstMakeGlobalWithOffset ( Pointer < Option < CtfeProvenance > > ) ,
27
41
}
28
42
29
43
impl MachineStopType for ConstEvalErrKind {
@@ -38,6 +52,12 @@ impl MachineStopType for ConstEvalErrKind {
38
52
RecursiveStatic => const_eval_recursive_static,
39
53
AssertFailure ( x) => x. diagnostic_message ( ) ,
40
54
WriteThroughImmutablePointer => const_eval_write_through_immutable_pointer,
55
+ ConstMakeGlobalPtrAlreadyMadeGlobal { .. } => {
56
+ const_eval_const_make_global_ptr_already_made_global
57
+ }
58
+ ConstMakeGlobalPtrIsNonHeap ( _) => const_eval_const_make_global_ptr_is_non_heap,
59
+ ConstMakeGlobalWithDanglingPtr ( _) => const_eval_const_make_global_with_dangling_ptr,
60
+ ConstMakeGlobalWithOffset ( _) => const_eval_const_make_global_with_offset,
41
61
}
42
62
}
43
63
fn add_args ( self : Box < Self > , adder : & mut dyn FnMut ( DiagArgName , DiagArgValue ) ) {
@@ -51,6 +71,14 @@ impl MachineStopType for ConstEvalErrKind {
51
71
Panic { msg, .. } => {
52
72
adder ( "msg" . into ( ) , msg. into_diag_arg ( & mut None ) ) ;
53
73
}
74
+ ConstMakeGlobalPtrIsNonHeap ( ptr)
75
+ | ConstMakeGlobalWithOffset ( ptr)
76
+ | ConstMakeGlobalWithDanglingPtr ( ptr) => {
77
+ adder ( "ptr" . into ( ) , format ! ( "{ptr:?}" ) . into_diag_arg ( & mut None ) ) ;
78
+ }
79
+ ConstMakeGlobalPtrAlreadyMadeGlobal ( alloc) => {
80
+ adder ( "alloc" . into ( ) , alloc. into_diag_arg ( & mut None ) ) ;
81
+ }
54
82
}
55
83
}
56
84
}
0 commit comments