Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic with raw pointer operations in default trait method #1134

Open
hayley-leblanc opened this issue May 22, 2024 · 0 comments
Open

Panic with raw pointer operations in default trait method #1134

hayley-leblanc opened this issue May 22, 2024 · 0 comments

Comments

@hayley-leblanc
Copy link
Collaborator

Hi all,

The following trait (minimized from the original code):

trait Serializable : Sized {
    fn serialized_len() -> (out: u64);
    
    #[verifier::external_body]
    fn as_bytes(&self) 
    {
        let ptr = self as *const Self as *const u8;
        let slice = unsafe {
            std::slice::from_raw_parts(ptr, Self::serialized_len() as usize)
        };
    }
}

Triggers the following panic:

thread 'rustc' panicked at rust_verify/src/lifetime_generate.rs:1574:38:
no entry found for key

The initial version of the code had as_bytes with a postcondition involving some other Serializable methods and returning a slice; I thought one or both of those things might be related to the panic, but it still occurs in the code shown above with the postcondition and return value removed.

The same error does not occur in a non-default implementation or in a regular function.

The code that triggers the panic can also be found here https://play.verus-lang.org/?version=stable&mode=basic&edition=2021&gist=e96b6ad0f673da4557efbba97d07a01b. I've also included a commented-out version of the same trait that does not have a default as_bytes implementation + an implementation that do not trigger the panic.

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

No branches or pull requests

1 participant