From 134e0a4e874e7a739b4e96c987c6b520f8da37ff Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 2 Sep 2024 16:51:18 +0200 Subject: [PATCH] fix: lifetime hint panic in non generic defs --- crates/ide/src/inlay_hints/lifetime.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/ide/src/inlay_hints/lifetime.rs b/crates/ide/src/inlay_hints/lifetime.rs index 653e3a6ef1..2163c959b1 100644 --- a/crates/ide/src/inlay_hints/lifetime.rs +++ b/crates/ide/src/inlay_hints/lifetime.rs @@ -389,7 +389,9 @@ fn hints_( } (None, allocated_lifetimes) => on_missing_gpl(acc, allocated_lifetimes), } - ctx.lifetime_stacks.last_mut().unwrap().extend(allocated_lifetimes); + if let Some(stack) = ctx.lifetime_stacks.last_mut() { + stack.extend(allocated_lifetimes); + } Some(()) } @@ -542,6 +544,22 @@ fn fn_trait(a: &impl Fn(&()) -> &()) {} // ^^ for<'1> //^'1 // ^'1 +"#, + ); + } + + #[test] + fn hints_in_non_gen_defs() { + check_with_config( + InlayHintsConfig { + lifetime_elision_hints: LifetimeElisionHints::Always, + ..TEST_CONFIG + }, + r#" +const _: fn(&()) -> &(); + //^^ for<'0> + //^'0 + //^'0 "#, ); }