You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #121199 - RalfJung:ref-to-vtable-fn, r=<try>
const-eval: error when encountering references to functions / vtables
Such references sound like an exceedingly bad idea... just use raw pointers if you must do things like this.
But we should crater this, to be on the safe side.
Copy file name to clipboardExpand all lines: compiler/rustc_const_eval/messages.ftl
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -464,8 +464,10 @@ const_eval_validation_out_of_range = {$front_matter}: encountered {$value}, but
464
464
const_eval_validation_partial_pointer = {$front_matter}: encountered a partial pointer or a mix of pointers
465
465
const_eval_validation_pointer_as_int = {$front_matter}: encountered a pointer, but {$expected}
466
466
const_eval_validation_ptr_out_of_range = {$front_matter}: encountered a pointer, but expected something that cannot possibly fail to be {$in_range}
467
+
const_eval_validation_ref_to_function = {$front_matter}: encountered a reference pointing to a function
467
468
const_eval_validation_ref_to_static = {$front_matter}: encountered a reference pointing to a static variable in a constant
468
469
const_eval_validation_ref_to_uninhabited = {$front_matter}: encountered a reference pointing to uninhabited type {$ty}
470
+
const_eval_validation_ref_to_vtable = {$front_matter}: encountered a reference pointing to a vtable
469
471
const_eval_validation_unaligned_box = {$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})
470
472
const_eval_validation_unaligned_ref = {$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})
471
473
const_eval_validation_uninhabited_enum_variant = {$front_matter}: encountered an uninhabited enum variant
error[E0080]: it is undefined behavior to use this value
167
+
--> $DIR/ub-ref-ptr.rs:76:1
168
+
|
169
+
LL | const POINTS_TO_FUNCTION: &() = unsafe {
170
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a function
171
+
|
172
+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
173
+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
174
+
HEX_DUMP
175
+
}
176
+
177
+
error[E0080]: it is undefined behavior to use this value
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .1: encountered a reference pointing to a vtable
182
+
|
183
+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
184
+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
185
+
HEX_DUMP
186
+
}
187
+
188
+
error: aborting due to 17 previous errors
167
189
168
190
For more information about this error, try `rustc --explain E0080`.
0 commit comments