(* Generated by coq-of-rust *)
Require Import CoqOfRust.CoqOfRust.

(* StructTuple
  {
    name := "Borrowed";
    const_params := [];
    ty_params := [];
    fields := [ Ty.apply (Ty.path "&") [] [ Ty.path "i32" ] ];
  } *)

Module Impl_core_fmt_Debug_for_scoping_rules_lifetimes_structs_Borrowed.
  Definition Self : Ty.t := Ty.path "scoping_rules_lifetimes_structs::Borrowed".
  
  (* Debug *)
  Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; f ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let f := M.alloc (| f |) in
        M.call_closure (|
          M.get_associated_function (|
            Ty.path "core::fmt::Formatter",
            "debug_tuple_field1_finish",
            []
          |),
          [
            M.read (| f |);
            M.read (| Value.String "Borrowed" |);
            M.alloc (|
              M.SubPointer.get_struct_tuple_field (|
                M.read (| self |),
                "scoping_rules_lifetimes_structs::Borrowed",
                0
              |)
            |)
          ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::fmt::Debug"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("fmt", InstanceField.Method fmt) ].
End Impl_core_fmt_Debug_for_scoping_rules_lifetimes_structs_Borrowed.

(* StructRecord
  {
    name := "NamedBorrowed";
    const_params := [];
    ty_params := [];
    fields :=
      [
        ("x", Ty.apply (Ty.path "&") [] [ Ty.path "i32" ]);
        ("y", Ty.apply (Ty.path "&") [] [ Ty.path "i32" ])
      ];
  } *)

Module Impl_core_fmt_Debug_for_scoping_rules_lifetimes_structs_NamedBorrowed.
  Definition Self : Ty.t := Ty.path "scoping_rules_lifetimes_structs::NamedBorrowed".
  
  (* Debug *)
  Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; f ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let f := M.alloc (| f |) in
        M.call_closure (|
          M.get_associated_function (|
            Ty.path "core::fmt::Formatter",
            "debug_struct_field2_finish",
            []
          |),
          [
            M.read (| f |);
            M.read (| Value.String "NamedBorrowed" |);
            M.read (| Value.String "x" |);
            M.SubPointer.get_struct_record_field (|
              M.read (| self |),
              "scoping_rules_lifetimes_structs::NamedBorrowed",
              "x"
            |);
            M.read (| Value.String "y" |);
            M.alloc (|
              M.SubPointer.get_struct_record_field (|
                M.read (| self |),
                "scoping_rules_lifetimes_structs::NamedBorrowed",
                "y"
              |)
            |)
          ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::fmt::Debug"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("fmt", InstanceField.Method fmt) ].
End Impl_core_fmt_Debug_for_scoping_rules_lifetimes_structs_NamedBorrowed.

(*
Enum Either
{
  const_params := [];
  ty_params := [];
  variants :=
    [
      {
        name := "Num";
        item := StructTuple [ Ty.path "i32" ];
        discriminant := None;
      };
      {
        name := "Ref";
        item := StructTuple [ Ty.apply (Ty.path "&") [] [ Ty.path "i32" ] ];
        discriminant := None;
      }
    ];
}
*)

Module Impl_core_fmt_Debug_for_scoping_rules_lifetimes_structs_Either.
  Definition Self : Ty.t := Ty.path "scoping_rules_lifetimes_structs::Either".
  
  (* Debug *)
  Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; f ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let f := M.alloc (| f |) in
        M.read (|
          M.match_operator (|
            self,
            [
              fun γ =>
                ltac:(M.monadic
                  (let γ := M.read (| γ |) in
                  let γ1_0 :=
                    M.SubPointer.get_struct_tuple_field (|
                      γ,
                      "scoping_rules_lifetimes_structs::Either::Num",
                      0
                    |) in
                  let __self_0 := M.alloc (| γ1_0 |) in
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.path "core::fmt::Formatter",
                        "debug_tuple_field1_finish",
                        []
                      |),
                      [ M.read (| f |); M.read (| Value.String "Num" |); __self_0 ]
                    |)
                  |)));
              fun γ =>
                ltac:(M.monadic
                  (let γ := M.read (| γ |) in
                  let γ1_0 :=
                    M.SubPointer.get_struct_tuple_field (|
                      γ,
                      "scoping_rules_lifetimes_structs::Either::Ref",
                      0
                    |) in
                  let __self_0 := M.alloc (| γ1_0 |) in
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.path "core::fmt::Formatter",
                        "debug_tuple_field1_finish",
                        []
                      |),
                      [ M.read (| f |); M.read (| Value.String "Ref" |); __self_0 ]
                    |)
                  |)))
            ]
          |)
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::fmt::Debug"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("fmt", InstanceField.Method fmt) ].
End Impl_core_fmt_Debug_for_scoping_rules_lifetimes_structs_Either.

(*
fn main() {
    let x = 18;
    let y = 15;

    let single = Borrowed(&x);
    let double = NamedBorrowed { x: &x, y: &y };
    let reference = Either::Ref(&x);
    let number = Either::Num(y);

    println!("x is borrowed in {:?}", single);
    println!("x and y are borrowed in {:?}", double);
    println!("x is borrowed in {:?}", reference);
    println!("y is *not* borrowed in {:?}", number);
}
*)
Definition main (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
  match ε, τ, α with
  | [], [], [] =>
    ltac:(M.monadic
      (M.read (|
        let~ x := M.alloc (| Value.Integer IntegerKind.I32 18 |) in
        let~ y := M.alloc (| Value.Integer IntegerKind.I32 15 |) in
        let~ single :=
          M.alloc (| Value.StructTuple "scoping_rules_lifetimes_structs::Borrowed" [ x ] |) in
        let~ double :=
          M.alloc (|
            Value.StructRecord
              "scoping_rules_lifetimes_structs::NamedBorrowed"
              [ ("x", x); ("y", y) ]
          |) in
        let~ reference :=
          M.alloc (| Value.StructTuple "scoping_rules_lifetimes_structs::Either::Ref" [ x ] |) in
        let~ number :=
          M.alloc (|
            Value.StructTuple "scoping_rules_lifetimes_structs::Either::Num" [ M.read (| y |) ]
          |) in
        let~ _ :=
          let~ _ :=
            M.alloc (|
              M.call_closure (|
                M.get_function (| "std::io::stdio::_print", [] |),
                [
                  M.call_closure (|
                    M.get_associated_function (| Ty.path "core::fmt::Arguments", "new_v1", [] |),
                    [
                      M.alloc (|
                        Value.Array
                          [
                            M.read (| Value.String "x is borrowed in " |);
                            M.read (| Value.String "
" |)
                          ]
                      |);
                      M.alloc (|
                        Value.Array
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_debug",
                                [ Ty.path "scoping_rules_lifetimes_structs::Borrowed" ]
                              |),
                              [ single ]
                            |)
                          ]
                      |)
                    ]
                  |)
                ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |) in
        let~ _ :=
          let~ _ :=
            M.alloc (|
              M.call_closure (|
                M.get_function (| "std::io::stdio::_print", [] |),
                [
                  M.call_closure (|
                    M.get_associated_function (| Ty.path "core::fmt::Arguments", "new_v1", [] |),
                    [
                      M.alloc (|
                        Value.Array
                          [
                            M.read (| Value.String "x and y are borrowed in " |);
                            M.read (| Value.String "
" |)
                          ]
                      |);
                      M.alloc (|
                        Value.Array
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_debug",
                                [ Ty.path "scoping_rules_lifetimes_structs::NamedBorrowed" ]
                              |),
                              [ double ]
                            |)
                          ]
                      |)
                    ]
                  |)
                ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |) in
        let~ _ :=
          let~ _ :=
            M.alloc (|
              M.call_closure (|
                M.get_function (| "std::io::stdio::_print", [] |),
                [
                  M.call_closure (|
                    M.get_associated_function (| Ty.path "core::fmt::Arguments", "new_v1", [] |),
                    [
                      M.alloc (|
                        Value.Array
                          [
                            M.read (| Value.String "x is borrowed in " |);
                            M.read (| Value.String "
" |)
                          ]
                      |);
                      M.alloc (|
                        Value.Array
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_debug",
                                [ Ty.path "scoping_rules_lifetimes_structs::Either" ]
                              |),
                              [ reference ]
                            |)
                          ]
                      |)
                    ]
                  |)
                ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |) in
        let~ _ :=
          let~ _ :=
            M.alloc (|
              M.call_closure (|
                M.get_function (| "std::io::stdio::_print", [] |),
                [
                  M.call_closure (|
                    M.get_associated_function (| Ty.path "core::fmt::Arguments", "new_v1", [] |),
                    [
                      M.alloc (|
                        Value.Array
                          [
                            M.read (| Value.String "y is *not* borrowed in " |);
                            M.read (| Value.String "
" |)
                          ]
                      |);
                      M.alloc (|
                        Value.Array
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.path "core::fmt::rt::Argument",
                                "new_debug",
                                [ Ty.path "scoping_rules_lifetimes_structs::Either" ]
                              |),
                              [ number ]
                            |)
                          ]
                      |)
                    ]
                  |)
                ]
              |)
            |) in
          M.alloc (| Value.Tuple [] |) in
        M.alloc (| Value.Tuple [] |)
      |)))
  | _, _, _ => M.impossible "wrong number of arguments"
  end.

Axiom Function_main : M.IsFunction "scoping_rules_lifetimes_structs::main" main.
