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

Need to refer to $self_ instead of $self in ensures #1276

Open
maximebuyse opened this issue Jan 29, 2025 · 2 comments
Open

Need to refer to $self_ instead of $self in ensures #1276

maximebuyse opened this issue Jan 29, 2025 · 2 comments
Labels
lib Lib-related issue (e.g. annotations lib)

Comments

@maximebuyse
Copy link
Contributor

trait Test {
    fn f(&self) -> u8;
}

#[hax_lib::attributes]
impl Test for u8 {
    #[hax_lib::ensures(|result| fstar!("${self_} = $result"))]
    fn f(&self) -> u8 {*self}
}

Open this code snippet in the playground

As in the example above, when using fstar! inside an ensures for a method inside a trait implementation, we need to refer to self as $self_ instead of $self which is confusing. Note that this seems not to work at all for a non-trait impl.

@maximebuyse maximebuyse added the lib Lib-related issue (e.g. annotations lib) label Jan 29, 2025
@maximebuyse
Copy link
Contributor Author

struct Test(u8);

#[hax_lib::attributes]
impl Test {
    #[hax_lib::ensures(|result| fstar!("${self_}._0 = $result"))]
    fn f(&self) -> u8 {self.0}
}

Open this code snippet in the playground

Here is a reproducer for an inherent impl, where things seem to be just broken.

@maximebuyse
Copy link
Contributor Author

struct Test(u8);

#[hax_lib::attributes]
impl Test {
#[hax_lib::ensures(|result| fstar!("${self_}._0 = $result"))]
fn f(&self) -> u8 {self.0}
}

Open this code snippet in the playground

Here is a reproducer for an inherent impl, where things seem to be just broken.

Workaround:

struct Test(u8);

#[hax_lib::attributes]
impl Test {
    #[hax_lib::ensures(|result| fstar!("let ${self_} = self in ${self_.0} = $result"))]
    fn f(&self) -> u8 {self.0}
}

Open this code snippet in the playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib Lib-related issue (e.g. annotations lib)
Projects
None yet
Development

No branches or pull requests

1 participant