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

Supertrait limitations of auto traits #1313

Open
juliand665 opened this issue Feb 3, 2023 · 0 comments
Open

Supertrait limitations of auto traits #1313

juliand665 opened this issue Feb 3, 2023 · 0 comments

Comments

@juliand665
Copy link
Contributor

As part of #1249, I repeatedly found myself writing code like this:

#[extern_spec]
trait Default {
#[refine_spec(where Self: Copy + PureDefault, [pure])]
fn default() -> Self;
}

Note the Copy + PureDefault, rather than simply PureDefault. This is because PureDefault is an auto trait expressing that a type's Default implementation is pure. Unfortunately, auto traits cannot have supertraits, so unless we want users to explicitly opt non-Copy types out of this refinement, we need to further constraint PureDefault to be Copy at the use site.

One possible solution would be to implement our own auto-style system, which could even allow defining PureDefault: Copy + Default as a regular trait that Prusti considers implemented on all applicable types unless otherwise stated.

An alternative solution is to tackle this specific purity issue by providing an alternative to pure, or making it take an argument, that makes it only apply when the necessary types implement Copy. This could look something like pure_if_applicable or pure(ignore_invalid_generics), respectively. This would not eliminate the need for marker traits like PureDefault entirely, as it's still possible for a type to be Copy but provide an impure implementation of default(), but it would streamline specs like this not just for us but also for users.

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