Newbie Rustacean Diaries — Being PR Ready

Some things to remember before you open a PR for the Rust Compiler. Certain mistakes I made when I opened my first PR.

Build the compiler

build - a general purpose command for compiling code. script is used.

./ build --stage 0

./ build --stage 1

Running the above two is almost equivalent to

./ build --incremental

You can pass arguments as what to build.

./ build --stage 1 src/libstd

Here’s more on this -

For more on what stage 0 an stage 1 means, read up here

Running the unit tests

Most of the times, compile-fail and ui tests seem sufficient for me. Depends on what you are trying to do.

./ test src/test/ui

or you can do a

./ test too.

More on the test suite here

Debug Logs

The debug! macro helps to log at a debug level. This first requires you to add a new Config.toml file in the same directory as the script, i.e. move the Config.toml.example from src/bootstrap to the directory specified above. Then uncomment the following lines

# Whether or not debug assertions are enabled for the compiler and standard
# library
#debug-assertions = false

# Whether or not debuginfo is emitted
#debuginfo = false

# Whether or not line number debug information is emitted
#debuginfo-lines = false

This is how you view the logs

RUST_LOG=rustc_borrowck::borrowck::gather_loans rustc >& killme

Tidy checks

Here’s the code for the style checks -

Majority of my travis builds failed because I forgot to run a check locally.

./ test src/tools/tidy

Make sure you run this on your code before you open a PR.


Sometimes, a RUST_BACKTRACE = 1 ./ build --stage 1 can really do wonders.

PATH Settings

The first time I tried to see whether my changes were getting reflected on a test, I forgot to run it using the freshly built compiler while losing out a lot of time figuring out what was wrong.

So that rustc picks up the correct libraries, we need to set the LD_LIBRARY_PATH

LD_LIBRARY_PATH=$DIR/build/x86_64-unknown-linux-gnu/stage2/lib $DIR/build/x86_64-unknown-linux-gnu/stage2/bin/rustc
$DIR-The folder with in it.

For convenience, I create a local-rustc file in $DIR with the following contents.

TARGET_DIR=$PWD/build/x86_64-unknown-linux-gnu/stage1 LD_LIBRARY_PATH=$TARGET_DIR/lib $TARGET_DIR/bin/rustc "$@"`

and change permissions

chmod u+x local-rustc

./local-rustc — version gives a

rustc 1.18.0-dev (6121d2ab7 2017-04-14)

So all you need to do it use local-rustc instead of rustc.

rustc-mux might be of help here.

Rustfmt Formatter

Rustfmt will help you format your code. Instructions on installing are given below

Well there’s tons more to add really. Will make a few edits. Also, feel free to suggest some more :). Thanks for reading!

Happy Coding :)

Edit 1:The Path settings are no longer required.