rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.1k stars 178 forks source link

rust-goto-format-problem: Search failed: "--> \\([^:]+\\):" #360

Closed kaiwk closed 4 years ago

kaiwk commented 4 years ago

execute rust-format-buffer, it gives error

rust-goto-format-problem: Search failed: "--> \([^:]+\):"

version: 20200303.932

mookid commented 4 years ago

Hi, when that happens, what is the content of the *rustfmt* buffer?

zonotope commented 4 years ago

I have a very similar problem, only a slightly different error message. When I execute rust-format-buffer, The error I get is:

Search failed: "--> \([^:]+\):"

I think that error is close enough to warrant tacking onto this issue instead of opening another one, but please let me know if I should open another issue instead.

The contents of my *rustfmt* buffer after this error is:

Unrecognized option: 'edition'

I'm using the 2018 edition of course, and I have that specified in my Cargo.toml:

name = "powalert"
version = "0.1.0"
authors = ["ben lamothe <bl@732.one>"]
edition = "2018"

[dependencies]
battery = "0.7.5"
log = "0.4.8"
simplelog = "0.7.4"

I would also like to add that everything works fine if I call the rustfmt binary on any of these rust source files directly.

mookid commented 4 years ago

@zonotope it's a bit weird, because it means that rustfmt fails to parse the --edition flag.

What does echo fn foo( | rustfmt --edition 2018 in your shell respond?

Does #359 solve mitigate the issue?

zonotope commented 4 years ago

Ha!

% ➜ echo "fn foo(" | rustfmt --edition 2018            
Unrecognized option: 'edition'

I was running rustfmt with no arguments before when the binary worked. Here's my rustfmt version:

% ➜ rustfmt --version                                  
rustfmt 0.99.5-nightly ( )

Perhaps it's out of date? It seems weird that it would be that out of date though.

mookid commented 4 years ago
$ rustfmt -V
rustfmt 1.4.11-stable (18382352 2019-12-03)

:)

That explains that. Because it might happen, we should try to detect it to put a meaningful hint to the user.

Another workaround would be to (setq rust-rustfmt-switches nil).

zonotope commented 4 years ago

That worked! It looks like my version of rustfmt was managed by cargo instead of rustup and not being updated properly. Once I cleared that up, rust-format-buffer works for me now. Thanks!

mookid commented 4 years ago

cool! thanks for the feedback.

Closing this for now, but I expect the issue to be back as there seem to be non-handled outputs from rustfmt.