set CARGO_HOME correctly or stop using it
It looks like we set CARGO_HOME incorrectly for invocations of both cargo build and cargo test. The cargo build invocations work because we first cd to the directory containing the .cargo directory. The cargo test invocations don't work for out-of-source-tree builds. legacy/trac#26455 (moved) contains a more minimal fix.
The setting of CARGO_HOME is redundant if we cd to the correct directory first. Or we could stop changing directories and instead set CARGO_HOME correctly. We probably shouldn't do both because it's confusing and possibly inconsistent.