Closed
Description
Currently, if you pass -Zborrowck-mir
, we output both the AST output (tagged with (Ast)
) and the MIR output (tagged with (Mir)
).
Example:
> cd src/test/compile-fail
> rustc -Zborrowck-mir borrowck/borrowck-unary-move.rs
error[E0505]: cannot move out of `x` because it is borrowed (Ast)
--> borrowck/borrowck-unary-move.rs:17:10
|
16 | let y = &*x;
| -- borrow of `*x` occurs here
17 | free(x); //[ast]~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here
error[E0505]: cannot move out of `x` because it is borrowed (Mir)
--> borrowck/borrowck-unary-move.rs:17:10
|
16 | let y = &*x;
| --- borrow of `(*x)` occurs here
17 | free(x); //[ast]~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here
error: aborting due to 2 previous errors
I would like to alter the switch to be one where there are three mores:
-Zborrowck=ast -- the default, emits only AST
-Zborrowck=mir -- emits only MIR errors (and doesn't write `(Mir)`)
-Zborrowck=compare -- emits both, like `-Zborrowck-mir` does today.
This will be useful as we progress towards our yearly goal of having a working "demo", since the demo isn't very good if people are seeing the old and new errors. It will also be less annoying for editing the unit tests, since we won't need three copies of each error. And if we want the current output when running by hand, it is still available.
Activity
nikomatsakis commentedon Nov 19, 2017
Mentoring instructions
This is where the
-Zborrowck-mir
flag is defined:rust/src/librustc/session/config.rs
Lines 976 to 977 in 5f1c37a
That is part of a macro that ultimately defines the
DebuggingOpts
struct. We could change that line to something like this:This will change from a
borrowck_mir: bool
field to aborrowck: Option<String>
field. One problem is that this will also accept nonsense like-Zborrowck=foo
. I think what we ought to do is to add an enumBorrowckMode
comparable toPrintRequest
and the others that exist already:Then we will add a field in the
Options
struct by inserting a line around here like this:(The setup here is that there is an
Options
struct, which we just edited, which contains adebugging_opts: DebuggingOpts
field that has the "raw" debugging options; thatDebuggingOpts
struct is the one that is auto-generated by the macro above.)Then we can add some code around here that will parse the
debugging_opts.borrowck
data and create aBorrowckMode
enum, or else report an error (using a call toearly_error
like so). Theincremental
field is sort of roughly the model we want, except that it doesn't report any errors:PathBuf
Options
struct hereOK, once we've done that, we should get a few compilation errors because the field
tcx.sess.opts.debugging_opts.borrowck_mir
no longer exists. You can convert those to examine thetcx.sess.opts.borrowck_mode
field. I think I would add some methods toBorrowckMode
:and so on so that we can convert to
tcx.sess.opts.borrowck_mode.use_ast()
or whatever.Finally, we have to make the AST-based borrow checker not execute (or at least not report errors) unless we are in the right mode. It's actually easier to just make it not report errors: this is because the AST-based borrowck is still used for giving "unused mut" warnings, so if we just skip it altogether we'll get a bunch of weird warnings. To make it not report errors, though, we just have to modify the functions in this file, having them check the origin and just do nothing if it is wrong.
nikomatsakis commentedon Nov 19, 2017
Oh, one last thing. We have to edit all the tests! They can be changed from having
-Zborrowck-mir
at the top to-Zborrowck=mir
, and then removing the extra, duplicate comments from the[mir]
revision.est31 commentedon Nov 19, 2017
I want to work on this!
est31 commentedon Nov 19, 2017
@LooMaclin there seems to be a conflict here!
est31 commentedon Nov 19, 2017
Especially, I'm almost done with my PR, the only thing that remains is updating the tests which is a bit time intensive...
LooMaclin commentedon Nov 19, 2017
@est31 no problem. im stop working on that
Auto merge of #46106 - est31:master, r=nikomatsakis