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

Deep question mark not reconstructed #1299

Closed
maximebuyse opened this issue Feb 6, 2025 · 1 comment · Fixed by #1305
Closed

Deep question mark not reconstructed #1299

maximebuyse opened this issue Feb 6, 2025 · 1 comment · Fixed by #1305
Assignees
Labels
engine Issue in the engine workaround This bug has a workaround

Comments

@maximebuyse
Copy link
Contributor

pub struct S {
    pub g: Foo,
}

pub struct OtherS {
    pub g: Option<Foo>,
}

pub struct Foo {
    y: u8,
}

impl Foo {
    pub fn from(i: &Foo) -> Self {
    Self {
        y: i.y.clone(),
    }
}
}
struct Error();
impl S {
    pub fn from(i: &OtherS) -> Result<Self, Error> {
        Ok(Self {
            g: Foo::from(i.g.as_ref().ok_or(Error())?),
        })
    }
}

Open this code snippet in the playground

The F* extraction from the example above contains:

let impl_S__from (i: t_OtherS)
    : Core.Result.t_Result t_S t_Error =
  match
    Core.Ops.Try_trait.f_branch #(Core.Result.t_Result
          t_Foo t_Error)
      #FStar.Tactics.Typeclasses.solve
      (Core.Option.impl__ok_or #t_Foo
          #t_Error
          (Core.Option.impl__as_ref #t_Foo
              i.f_g
            <:
            Core.Option.t_Option t_Foo)
          (Error <: t_Error)
        <:
        Core.Result.t_Result t_Foo t_Error
      )
    <:
    Core.Ops.Control_flow.t_ControlFlow
      (Core.Result.t_Result
          Core.Convert.t_Infallible
          t_Error) t_Foo
  with
  | Core.Ops.Control_flow.ControlFlow_Break
    residual ->
    Core.Ops.Try_trait.f_from_residual #(Core.Result.t_Result
          t_S t_Error)
      #(Core.Result.t_Result
          Core.Convert.t_Infallible
          t_Error)
      #FStar.Tactics.Typeclasses.solve
      residual
  | Core.Ops.Control_flow.ControlFlow_Continue
    v_val ->
    Core.Result.Result_Ok
    ({ f_g = impl_Foo__from v_val } <: t_S
    )
    <:
    Core.Result.t_Result t_S t_Error

This contains the raw encoding used by Rust for question marks, this should be reconstructed by the engine but it is not.

@maximebuyse maximebuyse added engine Issue in the engine workaround This bug has a workaround labels Feb 6, 2025
@maximebuyse
Copy link
Contributor Author

A workaround is to write:

pub fn from(i: &OtherS) -> Result<Self, Error> {
        let g = i.g.as_ref().ok_or(Error())?;
        Ok(Self {
            g: Foo::from(g),
        })
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine Issue in the engine workaround This bug has a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant