Skip to content

Commit d3a7025

Browse files
authored
Merge pull request #292 from mookid/imenu-impl
imenu: handle lifetimes in impl blocks.
2 parents 12cb169 + b445737 commit d3a7025

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

rust-mode-tests.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,20 @@ extern \"rust-intrinsic\" fn five() {
30613061
"four"
30623062
"five"))))
30633063

3064+
(ert-deftest rust-test-imenu-impl-with-lifetime ()
3065+
(test-imenu
3066+
"
3067+
impl<'a> One<'a> {
3068+
fn one() {}
3069+
}
3070+
3071+
impl Two<'a> {
3072+
fn two() {}
3073+
}
3074+
"
3075+
'(("Impl" "One" "Two")
3076+
("Fn" "one" "two"))))
3077+
30643078
(when (executable-find rust-cargo-bin)
30653079
(ert-deftest rust-test-project-located ()
30663080
(lexical-let* ((test-dir (expand-file-name "test-project" default-directory))

rust-mode.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
(defconst rust-re-vis "pub")
4040
(defconst rust-re-unsafe "unsafe")
4141
(defconst rust-re-extern "extern")
42+
(defconst rust-re-generic
43+
(concat "<[[:space:]]*'" rust-re-ident "[[:space:]]*>"))
4244
(defconst rust-re-union
4345
(rx-to-string
4446
`(seq
@@ -561,7 +563,9 @@ buffer."
561563
(defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
562564
(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)"))
563565
(defun rust-re-item-def (itype)
564-
(concat (rust-re-word itype) "[[:space:]]+" (rust-re-grab rust-re-ident)))
566+
(concat (rust-re-word itype)
567+
(rust-re-shy rust-re-generic) "?"
568+
"[[:space:]]+" (rust-re-grab rust-re-ident)))
565569
(defun rust-re-item-def-imenu (itype)
566570
(concat "^[[:space:]]*"
567571
(rust-re-shy (concat (rust-re-word rust-re-vis) "[[:space:]]+")) "?"

0 commit comments

Comments
 (0)