Skip to content

Commit 01fe7e2

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

File tree

2 files changed

+80
-66
lines changed

2 files changed

+80
-66
lines changed

run_rust_emacs_tests.sh

+9
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

+71-66
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
;;; Code:
1212

1313
(eval-when-compile (require 'misc)
14-
(require 'rx))
14+
(require 'rx)
15+
(require 'compile)
16+
(require 'elec-pair))
1517

1618
;; for GNU Emacs < 24.3
1719
(eval-when-compile
@@ -20,6 +22,70 @@
2022
"Set variable VAR to value VAL in current buffer."
2123
(list 'set (list 'make-local-variable (list 'quote var)) val))))
2224

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

148-
(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
149-
150214
(defun rust-align-to-method-chain ()
151215
(save-excursion
152216
;; for method-chain alignment to apply, we must be looking at
@@ -420,6 +484,9 @@
420484
("fn" . font-lock-function-name-face)
421485
("static" . font-lock-constant-face)))))
422486

487+
(defvar font-lock-beg)
488+
(defvar font-lock-end)
489+
423490
(defun rust-font-lock-extend-region ()
424491
"Extend the region given by `font-lock-beg' and `font-lock-end'
425492
to include the beginning of a string or comment if it includes
@@ -490,68 +557,6 @@
490557
(set-match-data (nth 1 ret-list))
491558
(nth 0 ret-list))))
492559

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-
555560
(defun rust-look-for-non-standard-string (bound)
556561
;; Find a raw string or character literal, but only if it's not in the middle
557562
;; of another string or a comment.
@@ -769,7 +774,7 @@
769774
;; Otherwise, if the ident: appeared with anything other than , or {
770775
;; before it, it can't be part of a struct initializer and therefore
771776
;; must be denoting a type.
772-
nil
777+
(t nil)
773778
))
774779
))
775780

0 commit comments

Comments
 (0)