prusti-dev icon indicating copy to clipboard operation
prusti-dev copied to clipboard

Option type with Generics: cannot return a value of the generic type

Open Ramla-I opened this issue 2 years ago • 1 comments

I copied the Option code that was given in the user guide, and tried to convert it to use generics:

pub enum TrustedOption<T: Copy + Clone> {
    Some(T),
    None,
}

impl<T: Copy + Clone> TrustedOption<T> {

    #[pure]
    pub fn is_none(&self) -> bool {
        match self {
            TrustedOption::Some(_) => false,
            TrustedOption::None => true,
        }
    }

    #[pure]
    pub fn is_some(&self) -> bool {
        !self.is_none()
    }

    #[pure]
    #[requires(self.is_some())]
    pub fn peek(&self) -> T {
        match self {
            TrustedOption::Some(val) => *val,
            TrustedOption::None => unreachable!(),
        }
    }
}

I get the error [Prusti: unsupported feature] T type is not supported

Is this expected, or am I missing something in how generics are used in Prusti?

Ramla-I avatar Aug 02 '22 02:08 Ramla-I

This looks like a bug. Since T is Copy, this should work.

vakaras avatar Aug 06 '22 17:08 vakaras

See my comment here: https://github.com/viperproject/prusti-dev/issues/1117#issuecomment-1229510304 (it looks like you are using an "outdated" - we should do a stable release soon - version of Prusti)

JonasAlaif avatar Aug 28 '22 17:08 JonasAlaif