Skip to content

Commit 012537b

Browse files
committed
remove byte-compiler warnings and prevent future ones
1 parent 5e51aaa commit 012537b

File tree

2 files changed

+81
-66
lines changed

2 files changed

+81
-66
lines changed

run_rust_emacs_tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,13 @@ $( $EMACS -batch --eval "(require 'ert)" > /dev/null 2>&1 ) || {
3131
exit 3
3232
};
3333

34+
warnings="$( $EMACS -Q -batch -f batch-byte-compile rust-mode.el 2>&1 | grep -v '^Wrote ' )"
35+
if [ -n "$warnings" ]; then
36+
echo "Byte-compilation failed:"
37+
echo "$warnings"
38+
exit 4
39+
else
40+
echo "Byte-compilation passed."
41+
fi
42+
3443
$EMACS -batch -l rust-mode.el -l rust-mode-tests.el -f ert-run-tests-batch-and-exit

rust-mode.el

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
;;; Code:
1212

1313
(eval-when-compile (require 'misc)
14-
(require 'rx))
14+
(require 'rx)
15+
(require 'compile))
16+
17+
(defvar electric-pair-inhibit-predicate)
1518

1619
;; for GNU Emacs < 24.3
1720
(eval-when-compile
@@ -20,6 +23,70 @@
2023
"Set variable VAR to value VAL in current buffer."
2124
(list 'set (list 'make-local-variable (list 'quote var)) val))))
2225

26+
(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
27+
28+
(defconst rust-re-non-standard-string
29+
(rx
30+
(or
31+
;; Raw string: if it matches, it ends up with the starting character
32+
;; of the string as group 1, any ending backslashes as group 4, and
33+
;; the ending character as either group 5 or group 6.
34+
(seq
35+
;; The "r" starts the raw string. Capture it as group 1 to mark it as such syntactically:
36+
(group "r")
37+
38+
;; Then either:
39+
(or
40+
;; a sequence at least one "#" (followed by quote). Capture all
41+
;; but the last "#" as group 2 for this case.
42+
(seq (group (* "#")) "#\"")
43+
44+
;; ...or a quote without any "#". Capture it as group 3. This is
45+
;; used later to match the opposite quote only if this capture
46+
;; occurred
47+
(group "\""))
48+
49+
;; The contents of the string:
50+
(*? anything)
51+
52+
;; If there are any backslashes at the end of the string, capture
53+
;; them as group 4 so we can suppress the normal escape syntax
54+
;; parsing:
55+
(group (* "\\"))
56+
57+
;; Then the end of the string--the backreferences ensure that we
58+
;; only match the kind of ending that corresponds to the beginning
59+
;; we had:
60+
(or
61+
;; There were "#"s - capture the last one as group 5 to mark it as
62+
;; the end of the string:
63+
(seq "\"" (backref 2) (group "#"))
64+
65+
;; No "#"s - capture the ending quote (using a backref to group 3,
66+
;; so that we can't match a quote if we had "#"s) as group 6
67+
(group (backref 3))
68+
69+
;; If the raw string wasn't actually closed, go all the way to the end
70+
string-end))
71+
72+
;; Character literal: match the beginning ' of a character literal
73+
;; as group 7, and the ending one as group 8
74+
(seq
75+
(group "'")
76+
(or
77+
(seq
78+
"\\"
79+
(or
80+
(: "U" (= 8 xdigit))
81+
(: "u" (= 4 xdigit))
82+
(: "x" (= 2 xdigit))
83+
(any "'nrt0\"\\")))
84+
(not (any "'\\"))
85+
)
86+
(group "'"))
87+
)
88+
))
89+
2390
(defun rust-looking-back-str (str)
2491
"Like `looking-back' but for fixed strings rather than regexps (so that it's not so slow)"
2592
(let ((len (length str)))
@@ -145,8 +212,6 @@
145212
(backward-up-list)
146213
(back-to-indentation))))
147214

148-
(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
149-
150215
(defun rust-align-to-method-chain ()
151216
(save-excursion
152217
;; for method-chain alignment to apply, we must be looking at
@@ -420,6 +485,9 @@
420485
("fn" . font-lock-function-name-face)
421486
("static" . font-lock-constant-face)))))
422487

488+
(defvar font-lock-beg)
489+
(defvar font-lock-end)
490+
423491
(defun rust-font-lock-extend-region ()
424492
"Extend the region given by `font-lock-beg' and `font-lock-end'
425493
to include the beginning of a string or comment if it includes
@@ -490,68 +558,6 @@
490558
(set-match-data (nth 1 ret-list))
491559
(nth 0 ret-list))))
492560

493-
(defconst rust-re-non-standard-string
494-
(rx
495-
(or
496-
;; Raw string: if it matches, it ends up with the starting character
497-
;; of the string as group 1, any ending backslashes as group 4, and
498-
;; the ending character as either group 5 or group 6.
499-
(seq
500-
;; The "r" starts the raw string. Capture it as group 1 to mark it as such syntactically:
501-
(group "r")
502-
503-
;; Then either:
504-
(or
505-
;; a sequence at least one "#" (followed by quote). Capture all
506-
;; but the last "#" as group 2 for this case.
507-
(seq (group (* "#")) "#\"")
508-
509-
;; ...or a quote without any "#". Capture it as group 3. This is
510-
;; used later to match the opposite quote only if this capture
511-
;; occurred
512-
(group "\""))
513-
514-
;; The contents of the string:
515-
(*? anything)
516-
517-
;; If there are any backslashes at the end of the string, capture
518-
;; them as group 4 so we can suppress the normal escape syntax
519-
;; parsing:
520-
(group (* "\\"))
521-
522-
;; Then the end of the string--the backreferences ensure that we
523-
;; only match the kind of ending that corresponds to the beginning
524-
;; we had:
525-
(or
526-
;; There were "#"s - capture the last one as group 5 to mark it as
527-
;; the end of the string:
528-
(seq "\"" (backref 2) (group "#"))
529-
530-
;; No "#"s - capture the ending quote (using a backref to group 3,
531-
;; so that we can't match a quote if we had "#"s) as group 6
532-
(group (backref 3))
533-
534-
;; If the raw string wasn't actually closed, go all the way to the end
535-
string-end))
536-
537-
;; Character literal: match the beginning ' of a character literal
538-
;; as group 7, and the ending one as group 8
539-
(seq
540-
(group "'")
541-
(or
542-
(seq
543-
"\\"
544-
(or
545-
(: "U" (= 8 xdigit))
546-
(: "u" (= 4 xdigit))
547-
(: "x" (= 2 xdigit))
548-
(any "'nrt0\"\\")))
549-
(not (any "'\\"))
550-
)
551-
(group "'"))
552-
)
553-
))
554-
555561
(defun rust-look-for-non-standard-string (bound)
556562
;; Find a raw string or character literal, but only if it's not in the middle
557563
;; of another string or a comment.
@@ -769,7 +775,7 @@
769775
;; Otherwise, if the ident: appeared with anything other than , or {
770776
;; before it, it can't be part of a struct initializer and therefore
771777
;; must be denoting a type.
772-
nil
778+
(t nil)
773779
))
774780
))
775781

0 commit comments

Comments
 (0)