Skip to content

Dafny-to-Rust: #5774

@MikaelMayer

Description

@MikaelMayer

Dafny version

latest-nightly

Code to produce this issue

class Test {
  var x: int
  constructor() {
    x := 1;
  }
  function Plus(c: int): int reads this {
    x + c
  }
  function Get(): int reads this {
    x
  }
  method Test() {
    print Plus(Plus(Get()));
  }
}

method Main() {
  var c := new Test();
  c.Test();
}

Command to run and resulting output

dafny run -t:rs thefile.dfy

What happened?

There is a Rust compilation error because it complains self cannot be borrowed twice mutably in the same line.

Fixing this seems easy, it's just that we need to borrow self instead of mutably borrow self.
However, that would create a soundness issue we prevented in that Object::from_ref's reference count increment might be dropped in --release if we only borrow, not if we mutably borrow.

What type of operating system are you experiencing the problem on?

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalid translated codeThe compiler generates invalid code, making the the target language infrastructure crashkind: bugCrashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions