# Emacs and compile mode and C-x `

I am a multi-decade emacs user. I've working in Rust on and off since November 2020.
I put:

``````> /*
>  * Local Variables:
>  * mode: rust
>  * compile-command: "cd .. && cargo build"
>  * End:
>  */
``````

so that the compile key (for me, Alt+F12) runs cargo. All is well.
The cargo/rustc output looks like:

``````error[E0515]: cannot return value referencing local data `d1.child_socket`
--> src/dull.rs:102:16
``````

so when I hit C-x ` to go from error to error, emacs goes to the file name just fine.

Where I get into trouble is that I sometimes omit the compile command, or I just run "cargo test",
which works, but now emacs is confused about the current directory, since it thinks I'm compile in "src", but cargo has gone up a directory. Emacs now queries me on each file to be sure I want to go there.
I'm wondering if there is something obvious I'm missing that would make this go away?

I don't know if there are Emacs-specific solutions, but I typically launch my editor from the project's top-level directory by running a command like `vim src/dull.rs`. Then the editor's working directory is the same directory that Cargo runs its commands in.

In theory this should be the fix, it seems.
https://github.com/rust-lang/rust-mode/pull/394

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.