Explain pointer and dyn Trait handling in const_to_valtree
This commit is contained in:
parent
c01c49430c
commit
0dd5a1b622
|
@ -84,19 +84,18 @@ fn const_to_valtree_inner<'tcx>(
|
||||||
Some(ty::ValTree::Leaf(val.assert_int()))
|
Some(ty::ValTree::Leaf(val.assert_int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raw pointers are not allowed in type level constants, as raw pointers cannot be treated
|
// Raw pointers are not allowed in type level constants, as raw pointers compare equal if
|
||||||
// like references. If we looked behind the raw pointer, we may be breaking the meaning of
|
// their addresses are equal. Since we cannot guarantee any kind of pointer stability in
|
||||||
// the raw pointer. Equality on raw pointers is performed on the pointer and not on the pointee,
|
// the type system.
|
||||||
// and we cannot guarantee any kind of pointer stability in the type system.
|
|
||||||
// Technically we could allow function pointers, but they are not guaranteed to be the
|
// Technically we could allow function pointers, but they are not guaranteed to be the
|
||||||
// same as the function pointers at runtime.
|
// same as the function pointers at runtime.
|
||||||
ty::FnPtr(_) | ty::RawPtr(_) => None,
|
ty::FnPtr(_) | ty::RawPtr(_) => None,
|
||||||
ty::Ref(..) => unimplemented!("need to use deref_const"),
|
ty::Ref(..) => unimplemented!("need to use deref_const"),
|
||||||
|
|
||||||
// Trait objects are not allowed in type level constants, as we have no concept for
|
// Trait objects are not allowed in type level constants, as we have no concept for
|
||||||
// resolving their backing type, even if we can do that at const eval time. We may want to consider
|
// resolving their backing type, even if we can do that at const eval time. We may
|
||||||
// adding a `ValTree::DownCast(Ty<'tcx>, Box<ValTree>)` in the future, but I don't even know the
|
// hypothetically be able to allow `dyn StructuralEq` trait objects in the future,
|
||||||
// questions such a concept would open up, so an RFC would probably be good for this.
|
// but it is unclear if this is useful.
|
||||||
ty::Dynamic(..) => None,
|
ty::Dynamic(..) => None,
|
||||||
|
|
||||||
ty::Slice(_) | ty::Str => {
|
ty::Slice(_) | ty::Str => {
|
||||||
|
@ -107,8 +106,7 @@ fn const_to_valtree_inner<'tcx>(
|
||||||
|
|
||||||
ty::Adt(def, _) => {
|
ty::Adt(def, _) => {
|
||||||
if def.variants.is_empty() {
|
if def.variants.is_empty() {
|
||||||
// Uninhabited
|
bug!("uninhabited types should have errored and never gotten converted to valtree")
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let variant = ecx.read_discriminant(&place.into()).unwrap().1;
|
let variant = ecx.read_discriminant(&place.into()).unwrap().1;
|
||||||
|
|
Loading…
Reference in New Issue