Skip to content

Commit 4fce178

Browse files
committed
Merge pull request #154 from nikomatsakis/new-errors
add code to handle new-style rustc errors
2 parents b23efef + 40c33fd commit 4fce178

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

rust-mode.el

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,15 +1381,49 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
13811381
"Specifications for matching errors in rustc invocations.
13821382
See `compilation-error-regexp-alist' for help on their format.")
13831383

1384+
(defvar rustc-new-compilation-regexps
1385+
(let ((file "\\([^\n]+\\)")
1386+
(start-line "\\([0-9]+\\)")
1387+
(start-col "\\([0-9]+\\)"))
1388+
(let ((re (concat "^ *--> " file ":" start-line ":" start-col ; --> 1:2:3
1389+
)))
1390+
(cons re '(1 2 3))))
1391+
"Specifications for matching errors in rustc invocations (new style).
1392+
See `compilation-error-regexp-alist' for help on their format.")
1393+
13841394
;; Match test run failures and panics during compilation as
13851395
;; compilation warnings
13861396
(defvar cargo-compilation-regexps
13871397
'("^\\s-+thread '[^']+' panicked at \\('[^']+', \\([^:]+\\):\\([0-9]+\\)\\)" 2 3 nil nil 1)
13881398
"Specifications for matching panics in cargo test invocations.
13891399
See `compilation-error-regexp-alist' for help on their format.")
13901400

1401+
(defun rustc-scroll-down-after-next-error ()
1402+
"In the new style error messages, the regular expression
1403+
matches on the file name (which appears after `-->`), but the
1404+
start of the error appears a few lines earlier. This hook runs
1405+
after `M-x next-error`; it simply scrolls down a few lines in
1406+
the compilation window until the top of the error is visible."
1407+
(save-selected-window
1408+
(when (eq major-mode 'rust-mode)
1409+
(select-window (get-buffer-window next-error-last-buffer))
1410+
(when (save-excursion
1411+
(beginning-of-line)
1412+
(looking-at " *-->"))
1413+
(let ((start-of-error
1414+
(save-excursion
1415+
(beginning-of-line)
1416+
(while (not (looking-at "^[a-z]+:"))
1417+
(forward-line -1))
1418+
(point))))
1419+
(set-window-start (selected-window) start-of-error))))))
1420+
13911421
(eval-after-load 'compile
13921422
'(progn
1423+
(add-to-list 'compilation-error-regexp-alist-alist
1424+
(cons 'rustc-new rustc-new-compilation-regexps))
1425+
(add-to-list 'compilation-error-regexp-alist 'rustc-new)
1426+
(add-hook 'next-error-hook 'rustc-scroll-down-after-next-error)
13931427
(add-to-list 'compilation-error-regexp-alist-alist
13941428
(cons 'rustc rustc-compilation-regexps))
13951429
(add-to-list 'compilation-error-regexp-alist 'rustc)

0 commit comments

Comments
 (0)