Skip to content

Update snapshot predicate to exclude uninhabited discriminants#191

Draft
zgrannan wants to merge 1 commit into
Aurel300:rewrite-2023from
viperproject:zgrannan/fix-uninhabited
Draft

Update snapshot predicate to exclude uninhabited discriminants#191
zgrannan wants to merge 1 commit into
Aurel300:rewrite-2023from
viperproject:zgrannan/fix-uninhabited

Conversation

@zgrannan

Copy link
Copy Markdown

Fixes no-annotations/void.rs.

For functions likes

pub enum Void { }
fn void_unwrap<T>(this: Result<T, Void>) -> T {
    match this {
        Ok(val) => val,
        Err(e) => unreachable(e)
    }
}

Rust does not emit a discriminant check because there is only one inhabited case.

Prusti previously could not verify this example, because this constraint on the type was not encoded in Viper, and without knowing the discriminant, the permissions to val after the downcast could not be obtained.

This PR updates the encoding of types to assert that the variant index of an enum cannot equal the discriminant of an uninhabited variant.

@zgrannan
zgrannan marked this pull request as draft July 20, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant