I have been using rust-mode on a project whose Rust version I manage using direnv and the associated emacs package envrc. When I try to use rust-test, it can't find cargo.
How envrc works is by making process-environment a file-local variable and updating it analogously to running direnv reload. However, because process-environment has not historically been file-local, some uses of it don't work the way you would expect. In particular, invoking with-temp-buffer does not re-use the correct environment. It's idiomatic in elisp to call call-process inside with-temp-buffer to capture its output, and because with-temp-buffer uses another environment, call-process cannot find executables that "should" be available in that directory.
I filed https://github.com/purcell/envrc/issues/12 to try to identify the correct solution to this problem. It feels like a footgun in emacs/elisp itself, but in the short term, Steve Purcell has been kind enough to write a utility library called inheritenv which allows these temporary buffers to inherit the environment from the buffer where they are being created. Alternately, it's possible for affected packages (like rust-mode) to define a utility that is like with-temp-buffer but propagates the environment, as in https://github.com/magit/magit/pull/4169/. I think one of these approaches would be a good change for rust-mode.
I have been using
rust-mode
on a project whose Rust version I manage usingdirenv
and the associated emacs packageenvrc
. When I try to userust-test
, it can't findcargo
.How
envrc
works is by makingprocess-environment
a file-local variable and updating it analogously to runningdirenv reload
. However, becauseprocess-environment
has not historically been file-local, some uses of it don't work the way you would expect. In particular, invokingwith-temp-buffer
does not re-use the correct environment. It's idiomatic in elisp to callcall-process
insidewith-temp-buffer
to capture its output, and becausewith-temp-buffer
uses another environment,call-process
cannot find executables that "should" be available in that directory.I filed https://github.com/purcell/envrc/issues/12 to try to identify the correct solution to this problem. It feels like a footgun in emacs/elisp itself, but in the short term, Steve Purcell has been kind enough to write a utility library called
inheritenv
which allows these temporary buffers to inherit the environment from the buffer where they are being created. Alternately, it's possible for affected packages (likerust-mode
) to define a utility that is likewith-temp-buffer
but propagates the environment, as in https://github.com/magit/magit/pull/4169/. I think one of these approaches would be a good change forrust-mode
.