Skip to content

Commit 22c5fce

Browse files
authored
Rollup merge of rust-lang#144256 - oli-obk:type-id-ice, r=RalfJung
Don't ICE on non-TypeId metadata within TypeId fixes rust-lang#144253 r? ``@RalfJung``
2 parents c80de8a + b2f8b40 commit 22c5fce

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10001000
ptr: Pointer<Option<M::Provenance>>,
10011001
) -> InterpResult<'tcx, (Ty<'tcx>, u64)> {
10021002
let (alloc_id, offset, _meta) = self.ptr_get_alloc_id(ptr, 0)?;
1003-
let GlobalAlloc::TypeId { ty } = self.tcx.global_alloc(alloc_id) else {
1003+
let Some(GlobalAlloc::TypeId { ty }) = self.tcx.try_get_global_alloc(alloc_id) else {
10041004
throw_ub_format!("invalid `TypeId` value: not all bytes carry type id metadata")
10051005
};
10061006
interp_ok((ty, offset.bytes()))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Test that we do not ICE and that we do report an error
2+
//! when placing non-TypeId provenance into a TypeId.
3+
4+
#![feature(const_trait_impl, const_cmp)]
5+
6+
use std::any::TypeId;
7+
use std::mem::transmute;
8+
9+
const X: bool = {
10+
let a = ();
11+
let id: TypeId = unsafe { transmute([&raw const a; 16 / size_of::<*const ()>()]) };
12+
id == id
13+
//~^ ERROR: invalid `TypeId` value: not all bytes carry type id metadata
14+
};
15+
16+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0080]: invalid `TypeId` value: not all bytes carry type id metadata
2+
--> $DIR/const_transmute_type_id6.rs:12:5
3+
|
4+
LL | id == id
5+
| ^^^^^^^^ evaluation of `X` failed inside this call
6+
|
7+
note: inside `<TypeId as PartialEq>::eq`
8+
--> $SRC_DIR/core/src/any.rs:LL:COL
9+
note: inside `<TypeId as PartialEq>::eq::compiletime`
10+
--> $SRC_DIR/core/src/any.rs:LL:COL
11+
= note: this error originates in the macro `$crate::intrinsics::const_eval_select` which comes from the expansion of the macro `crate::intrinsics::const_eval_select` (in Nightly builds, run with -Z macro-backtrace for more info)
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)