Skip to content

Documentation for Type-Conditional Spec Refinements #1320

@Pointerbender

Description

@Pointerbender

I'm playing around with the recently stabilized Type-Conditional Spec Refinements feature. I have a question about how to use it. For example, reading the docs I would expect that I would be able to do this:

use prusti_contracts::*;

pub unsafe trait Foo {}

pub trait Bar {
    #[refine_spec(where Self: Foo, [pure])]
    fn baz(&self) -> usize;
}

but this fails with the compilation error:

error: [Prusti: unsupported feature] Type-conditional spec refinements can only be applied to trusted functions
  --> src/lib.rs:33:5
   |
33 |     fn baz(&self) -> usize;
   |     ^^^^^^^^^^^^^^^^^^^^^^^

which is a bit confusing because there is no method body. However, this does seem to compile:

use prusti_contracts::*;

pub unsafe trait Foo {}

pub trait Bar {
    #[trusted]
    #[refine_spec(where Self: Foo, [pure])]
    fn baz(&self) -> usize;
}

and so does this:

use prusti_contracts::*;

pub unsafe trait Foo {}

pub trait Bar {
    fn baz(&self) -> usize;
}

#[extern_spec]
pub trait Bar {
    #[refine_spec(where Self: Foo, [pure])]
    fn baz(&self) -> usize;
}

What is the correct usage of #[refine_spec] on trait methods without a body? :) As an aside question, why can type-conditional spec refinements only be applied to trusted functions? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions