Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created November 10, 2017 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikomatsakis/a0d5dee0bd3c4d4f0442914a9abdf74c to your computer and use it in GitHub Desktop.
Save nikomatsakis/a0d5dee0bd3c4d4f0442914a9abdf74c to your computer and use it in GitHub Desktop.

How to update a borrowck test for MIR borrowck

When we fix a bug in MIR borrowck, we often want to update an existing test and show that it does the same thing for MIR and AST borrowck. This gist describes the steps to do it.

compile-fail tests

An example of a test that has been updated to test both MIR and AST borrowck is borrowck-match-already-borrowed.

The idea is to first add a comment indicating that the test runner should run the test with two distinct revisions, ast and mir. This will basically cause us to compile the test twice, with different options and flags. This would go somewhere near the top, after the Copyright statement:

// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// ... blah blah blah ...
// except according to those terms.

// revisions: ast mir

Next, we want to indicate some special compile-flags to use when running in the MIR revision:

//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir

This notation indicates that we should use those compile-flags in the mir revision. This will enable the MIR-based borrowck. -Zemit-end-regions causes the MIR builder to include end-region information used by the MIR-based borrowck.

Finally, we have to update the expected errors. If before you had a line like this:

    Foo::A(x) => x //~ ERROR [E0503]

This indicates that we expect to see an error on that line including the test [E0503]. We can update this to say that we expect that, but only in the ast revision:

    Foo::A(x) => x //[ast]~ ERROR [E0503]

Next, we would add additional expected errors in the MIR revision. When MIR is enabled, we still run the AST borrowck, but we suffix its errors with (Ast), and we include the (Mir) tagline for those producd by the MIR borrowck. So the final result looks like:

    Foo::A(x) => x //[ast]~ ERROR [E0503]
                   //[mir]~^ ERROR (Ast) [E0503]
                   //[mir]~| ERROR (Mir) [E0503]

The ~^ indicates that the error is expected on the line above, and the ~| indicates that it is expected on the same line as where the previous error is expected. In other words, all those errors are expeted on the same line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment