                  (concat (file-name-directory filename) (file-name-nondirectory tmpfile))
                tmpfile)))
         (while (search-forward-regexp
-                (concat "^\\(" (regexp-quote (go--file-local-name truefile))
+                (concat "^\\(" (regexp-quote (file-local-name truefile))
                         "\\):")
                 nil t)
           (replace-match (file-name-nondirectory filename) t t nil 1)))

;;;###autoload
(add-to-list 'auto-mode-alist '("go\\.mod\\'" . go-dot-mod-mode))

;; Polyfills for functions added in Emacs 26.  Remove these once we don’t
;; support Emacs 25 any more.
(defalias 'go--file-local-name
  (if (fboundp 'file-local-name) #'file-local-name
    (lambda (file) (or (file-remote-p file 'localname) file))))

(defalias 'go--make-nearby-temp-file
  (if (fboundp 'make-nearby-temp-file) #'make-nearby-temp-file
    (lambda (prefix &optional dir-flag suffix)
      (let ((temporary-file-directory (go--temporary-file-directory)))
        (make-temp-file prefix dir-flag suffix)))))

(defalias 'go--temporary-file-directory
  (if (fboundp 'temporary-file-directory) #'temporary-file-directory
    (lambda ()
      (let ((remote (file-remote-p default-directory)))
        (if remote
            ;; Assume that /tmp is a temporary directory on the remote host.
            ;; This won’t work on Windows.
            (concat remote "/tmp")
          temporary-file-directory)))))


;; The following functions were copied (and modified) from rust-mode.el.
;;
;; Copyright (c) 2015 The Rust Project Developers

The tool used can be set via ‘gofmt-command’ (default: gofmt) and additional
arguments can be set as a list via ‘gofmt-args’."
  (interactive)
  (let ((tmpfile (make-nearby-temp-file "gofmt" nil ".go"))
        (patchbuf (get-buffer-create "*Gofmt patch*"))
        (errbuf (if gofmt-show-errors (get-buffer-create "*Gofmt Errors*")))
        (coding-system-for-read 'utf-8)
