Skip to content

Commit 7e2533f

Browse files
authored
Fix rustc-compilation-regexps: match error messages with dashes. (#331)
1 parent 6dca073 commit 7e2533f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

rust-mode-tests.el

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,40 @@ impl Two<'a> {
31373137
(let ((default-directory test-dir))
31383138
(should (equal (expand-file-name (rust-buffer-project)) manifest-file))))))
31393139

3140+
(ert-deftest compilation-regexp-dashes ()
3141+
(with-temp-buffer
3142+
;; should match
3143+
(insert "error found a -> b\n --> file1.rs:12:34\n\n")
3144+
(insert "error[E1234]: found a -> b\n --> file2.rs:12:34\n\n")
3145+
(insert "warning found a -> b\n --> file3.rs:12:34\n\n")
3146+
;; should not match
3147+
(insert "werror found a -> b\n --> file4.rs:12:34\n\n")
3148+
3149+
(goto-char (point-min))
3150+
(let ((matches nil))
3151+
(while (re-search-forward (car rustc-compilation-regexps) nil t)
3152+
(push
3153+
(mapcar (lambda (r)
3154+
(let ((match-pos
3155+
(nth (cdr r) rustc-compilation-regexps)))
3156+
(if (eq :is-warning (car r))
3157+
(compilation-face match-pos)
3158+
(match-string match-pos))))
3159+
;; see compilation-error-regexp-alist
3160+
'((:file . 1)
3161+
(:line . 2)
3162+
(:column . 3)
3163+
(:is-warning . 4)
3164+
(:mouse-highlight . 5)))
3165+
matches))
3166+
(setq matches (reverse matches))
3167+
3168+
(should (equal
3169+
'(("file1.rs" "12" "34" compilation-error "file1.rs:12:34")
3170+
("file2.rs" "12" "34" compilation-error "file2.rs:12:34")
3171+
("file3.rs" "12" "34" compilation-warning "file3.rs:12:34"))
3172+
matches)))))
3173+
31403174
;; If electric-pair-mode is available, load it and run the tests that use it. If not,
31413175
;; no error--the tests will be skipped.
31423176
(require 'elec-pair nil t)

rust-mode.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,8 @@ Return the created process."
16401640
(defvar rustc-compilation-regexps
16411641
(let ((file "\\([^\n]+\\)")
16421642
(start-line "\\([0-9]+\\)")
1643-
(start-col "\\([0-9]+\\)"))
1644-
(let ((re (concat "^\\(?:error\\|\\(warning\\)\\)[^-]+--> \\(" file ":" start-line ":" start-col "\\)")))
1643+
(start-col "\\([0-9]+\\)"))
1644+
(let ((re (concat "^\\(?:error\\|\\(warning\\)\\)[^\0]+?--> \\(" file ":" start-line ":" start-col "\\)")))
16451645
(cons re '(3 4 5 (1) 2))))
16461646
"Specifications for matching errors in rustc invocations.
16471647
See `compilation-error-regexp-alist' for help on their format.")

0 commit comments

Comments
 (0)