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.
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.