Skip to content

ALE modifies Rust buffer and triggers E212 when opening file via relative path (cwd != project root) #5092

@rwxguo

Description

@rwxguo

Information

VIM version

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Sep 05 2025 19:44:46)
Included patches: 1-16, 647, 678, 697

Operating System: Linux (Ubuntu 24)

What went wrong

When opening a Rust file via a relative path (for example vim ../handlers/index.rs) and immediately saving the file, Vim reports the following error on the first save:

"-stdin-" E212: Can't open file for writing

After this happens:

  • The buffer is marked as modified even though I did not edit anything
  • I cannot quit with :q
  • I need to press u twice to clear the changes

Saving the file a second time works normally.

This issue does not happen if I first cd into the directory and then open the file (for example cd handlers && vim index.rs).

I have searched through both open and closed issues and could not find an existing report describing this behavior.

Reproducing the bug

  1. Start Vim from a directory that is not the Rust project root
  2. Open a Rust file using a relative path, e.g.: vim ../handlers/index.rs
  3. Immediately run :w
  4. Observe the error: "-stdin-" E212: Can't open file for writing
  5. Run :changes, The output of :changes is:
change line col text
4 2 0 pub mod index;
3 4 0 -invalid-
2 4 0 -invalid-
1 3 0 pub mod logs;

The two -invalid- entries correspond exactly to the two undo steps required to clear the modified state. I did not manually edit the buffer.

Additional observations

  • This only happens when the file is opened via a relative path and Vim’s current working directory is not the Rust project root.
  • It looks like ALE’s Rust integration (rustfmt) may fall back to stdin-based formatting when the project root cannot be determined.
  • This stdin-based formatting appears to replace the entire buffer, leaving it in a modified state and triggering the E212 error on the first save.

:ALEInfo

Error case:

ale-info-error.txt

Good case:

ale-info-good.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions