rust-lang / rust-mode

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

compilation-error-regexp not matching panics #507

Closed ntBre closed 4 months ago

ntBre commented 8 months ago

I'm not totally sure this is an issue or caused by this package, per se, but I've been having issues with my compilation links to errors. As you can see in the screenshot below, the warnings are working fine, but the whole panic line is turned into a link, and, more importantly, clicking the link brings up Find this error in (default thread 'atom_typer::tests::atomtyper' panicked at src/lib.rs rather than taking me to the file. I thought this might have to do with the "cleaner panic messages" from Rust 1.73, but I still had a stable 1.72.1 version installed, and it had the same problem. I don't remember exactly when this stopped working, but I've just been dealing with it for a while and finally decided to ask for help.

I managed to get the behavior I wanted on the error with

(setf
 (alist-get 'rustc compilation-error-regexp-alist-alist)
 '("thread '[^']+' panicked at \\(\\(.*\\):\\([0-9]+\\):\\([0-9]+\\)\\)" 2 3 4 nil 1))

but that obviously ruins the matching for warnings and other kinds of errors. I would really appreciate any help with this!

I've also been trying to use rust-ts-mode a bit, but I don't see anything in there that should be clashing with this option. I'm happy to provide any additional information that might be needed.

image

luckysori commented 5 months ago

Great snippet, @ntBre! I was looking for someone with the same problem as me and someone from #emacs:matrix.org led me here.

I would really appreciate any help with this!

I think I made it work by registering a new entry instead of overriding rustc:

(defvar rustc-panics-compilation-regexps
  (let
      ((re
        "thread '[^']+' panicked at \\(\\(.*\\):\\([0-9]+\\):\\([0-9]+\\)\\)"))
    (cons re '(2 3 4 nil 1))))
(add-to-list
 'compilation-error-regexp-alist-alist
 (cons 'rustc-panics rustc-panics-compilation-regexps))
(add-to-list 'compilation-error-regexp-alist 'rustc-panics)

Thank you for sharing your fix!

ntBre commented 5 months ago

Wow, great idea! I'll give this a try tomorrow!

ntBre commented 5 months ago

Thanks again, this works great! I see now that your version is like the other definitions in rust-compile.el. There doesn't seem to be much activity here, but I think this (or something similar) should probably be included in the package if you wanted to submit a PR.

luckysori commented 4 months ago

@ntBre I opened https://github.com/rust-lang/rust-mode/pull/510 and added you as a co-author (I hope that's okay).

ntBre commented 4 months ago

Awesome, thank you!