   (rust-with-comment-fill-prefix
    (lambda () (comment-indent-new-line arg))))
 
+;;; Imenu support
+(defvar rust-imenu-generic-expression
+  (append (loop for item in
+                '("enum" "struct" "type" "mod" "fn")
+                collect `(nil ,(rust-re-item-def item) 1))
+          `(("Impl" ,(rust-re-item-def "impl") 1)))
+  "Value for `imenu-generic-expression' in Rust mode.
+
+Create a flat index of the item definitions in a Rust file.
+
+Imenu will show all the enums, structs, etc. at the same level.
+Implementations will be shown under the `Impl` subheading.
+Use idomenu (imenu with ido-mode) for best mileage.")
+
 ;; For compatibility with Emacs < 24, derive conditionally
 (defalias 'rust-parent-mode
   (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))

    ;; inferring it from the comment start.
    (let ((next-bol (line-beginning-position 2)))
      (while (save-excursion
              (end-of-line)
              (syntax-ppss-flush-cache 1)
              (and (nth 4 (syntax-ppss))
                   (save-excursion 
                     (beginning-of-line)
                     (looking-at paragraph-start))
                   (looking-at "[[:space:]]*$")
                   (nth 4 (syntax-ppss next-bol))))
        (goto-char next-bol)))

    (syntax-ppss-flush-cache 1)

           ;; If we're at the start of a comment, figure out what prefix
           ;; to use for the subsequent lines after it
           ((string-match (concat "[[:space:]]*" comment-start-skip) line-string)
            (rust-fill-prefix-for-comment-start
             (match-string 0 line-string))))))
       (fill-prefix
        (or line-comment-start
            fill-prefix)))
    (funcall body)))
