valid: Fix handle dependency validation

The handle dependency validation code was using the handle's index
directly while trying to erase the handle type. This would cause the
validator to crash while processing the first handle of the arena since
it would be trying to construct a `NonZeroU32` with a zero.

This commit fixes the issue by adding 1 to the index which not only
fixes this panic but also makes so that the created Handle is equal to
the passed handle (minus the type that was erased)

It also fixes the error message not including the subject's kind
This commit is contained in:
João Capucho
2023-01-31 14:49:39 +00:00
committed by Jim Blandy
parent 67ea8f0c06
commit bebaac93b6

View File

@@ -532,8 +532,8 @@ pub enum InvalidHandleError {
#[derive(Clone, Debug, thiserror::Error)]
#[error(
"{subject:?} of kind depends on {depends_on:?} of kind {depends_on_kind}, which has not been \
processed yet"
"{subject:?} of kind {subject_kind:?} depends on {depends_on:?} of kind {depends_on_kind}, \
which has not been processed yet"
)]
pub struct FwdDepError {
// This error is used for many `Handle` types, but there's no point in making this generic, so
@@ -580,7 +580,7 @@ impl<T> Handle<T> {
Ok(self)
} else {
let erase_handle_type = |handle: Handle<_>| {
Handle::new(NonZeroU32::new(handle.index().try_into().unwrap()).unwrap())
Handle::new(NonZeroU32::new((handle.index() + 1).try_into().unwrap()).unwrap())
};
Err(FwdDepError {
subject: erase_handle_type(self),