Skip to content

add code to handle new-style rustc errors #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1381,15 +1381,49 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
"Specifications for matching errors in rustc invocations.
See `compilation-error-regexp-alist' for help on their format.")

(defvar rustc-new-compilation-regexps
(let ((file "\\([^\n]+\\)")
(start-line "\\([0-9]+\\)")
(start-col "\\([0-9]+\\)"))
(let ((re (concat "^ *--> " file ":" start-line ":" start-col ; --> 1:2:3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikomatsakis why didn't you "just" make this regexp match the pair of lines, rather than the hack of scrolling backwards via rustc-scroll-down-after-next-error ?

E.g. this code I think would do the trick:

    (let ((re-new (concat "^" error-or-warning "\\[E[0-9]*\\]: [^\n]*\n"
                          "   --> " file ":" start-line ":" start-col)))
      (cons re-new '(2 3 4 1)))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I infer from this comment #154 (comment) that you tried something like this and determined it does not work reliably.

Do we have errors messages that span multiple lines? I suppose I should not be surprised if we did...

)))
(cons re '(1 2 3))))
"Specifications for matching errors in rustc invocations (new style).
See `compilation-error-regexp-alist' for help on their format.")

;; Match test run failures and panics during compilation as
;; compilation warnings
(defvar cargo-compilation-regexps
'("^\\s-+thread '[^']+' panicked at \\('[^']+', \\([^:]+\\):\\([0-9]+\\)\\)" 2 3 nil nil 1)
"Specifications for matching panics in cargo test invocations.
See `compilation-error-regexp-alist' for help on their format.")

(defun rustc-scroll-down-after-next-error ()
"In the new style error messages, the regular expression
matches on the file name (which appears after `-->`), but the
start of the error appears a few lines earlier. This hook runs
after `M-x next-error`; it simply scrolls down a few lines in
the compilation window until the top of the error is visible."
(save-selected-window
(when (eq major-mode 'rust-mode)
(select-window (get-buffer-window next-error-last-buffer))
(when (save-excursion
(beginning-of-line)
(looking-at " *-->"))
(let ((start-of-error
(save-excursion
(beginning-of-line)
(while (not (looking-at "^[a-z]+:"))
(forward-line -1))
(point))))
(set-window-start (selected-window) start-of-error))))))

(eval-after-load 'compile
'(progn
(add-to-list 'compilation-error-regexp-alist-alist
(cons 'rustc-new rustc-new-compilation-regexps))
(add-to-list 'compilation-error-regexp-alist 'rustc-new)
(add-hook 'next-error-hook 'rustc-scroll-down-after-next-error)
(add-to-list 'compilation-error-regexp-alist-alist
(cons 'rustc rustc-compilation-regexps))
(add-to-list 'compilation-error-regexp-alist 'rustc)
Expand Down