@@ -1381,15 +1381,49 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
1381
1381
" Specifications for matching errors in rustc invocations.
1382
1382
See `compilation-error-regexp-alist' for help on their format." )
1383
1383
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
+
1384
1394
; ; Match test run failures and panics during compilation as
1385
1395
; ; compilation warnings
1386
1396
(defvar cargo-compilation-regexps
1387
1397
'(" ^\\ s-+thread '[^']+' panicked at \\ ('[^']+', \\ ([^:]+\\ ):\\ ([0-9]+\\ )\\ )" 2 3 nil nil 1 )
1388
1398
" Specifications for matching panics in cargo test invocations.
1389
1399
See `compilation-error-regexp-alist' for help on their format." )
1390
1400
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
+
1391
1421
(eval-after-load 'compile
1392
1422
'(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 )
1393
1427
(add-to-list 'compilation-error-regexp-alist-alist
1394
1428
(cons 'rustc rustc-compilation-regexps))
1395
1429
(add-to-list 'compilation-error-regexp-alist 'rustc )
0 commit comments