Subject: bug#70396: 30.0.50; Eglot, rust-analyzer buffer formatting, and track changes errors

From: Stefan Monnier <[email-masked]>
Date: Mon, 15 Apr 2024 16:01:21 -0400

>> * Track changes errors (below).
>> * An `args-out-of-range` error in `replace-buffer-contents`.
>>
>> To reproduce:
>>
>> 1. Checkout `https://github.com/Stebalien/xattr/`. I can try for a
>>    minimal reproducer if necessary.
>> 2. Install rust-analyzer.
>> 2. Run `emacs -Q`
>> 3. `M-x find-file "src/sys/linux_macos.rs"`
>>    (https://github.com/Stebalien/xattr/blob/master/src/sys/linux_macos.rs).
>> 4. `M-x rust-ts-mode`
>> 5. `M-x eglot`
>> 6. `M-x eglot-format-buffer`

I could reproduce this in a C mode buffer (and hence save me the
trouble of installing more tools).
I pushed the patch below to `master` which should fix the problem.
Can you confirm it's fixed in your side as well?

        Stefan

diff --git a/lisp/emacs-lisp/track-changes.el b/lisp/emacs-lisp/track-changes.el
index 1bab7ca38fd..df4aad0d596 100644
--- a/lisp/emacs-lisp/track-changes.el
+++ b/lisp/emacs-lisp/track-changes.el
@@ -481,12 +481,12 @@
                 (funcall signal-if-disjoint end track-changes--before-beg)
               (funcall signal-if-disjoint track-changes--before-end beg)))
           (funcall reset))
-      (cl-assert (save-restriction
+      (save-restriction
                    (widen)
-                   (<= (point-min)
+        (cl-assert (<= (point-min)
                        track-changes--before-beg
                        track-changes--before-end
-                       (point-max))))
+                       (point-max)))
       (when (< beg track-changes--before-beg)
         (if (and track-changes--disjoint-trackers
                  (funcall signal-if-disjoint end track-changes--before-beg))
@@ -517,6 +517,6 @@
             (setf track-changes--before-end new-bend)
             (cl-callf concat track-changes--before-string
-              (buffer-substring-no-properties old-bend new-bend))))))))
+                (buffer-substring-no-properties old-bend new-bend)))))))))
 
 (defun track-changes--after (beg end len)
   (cl-assert track-changes--state)