From 793e1573d4415453abdd99a95e68f4cb983c35c2 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Mon, 7 Jul 2025 20:44:18 +0300 Subject: [PATCH] Fix a case where the link type was `None` Which caused a panic. --- crates/ide/src/doc_links.rs | 6 +++--- crates/ide/src/hover/tests.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index f58202a421..a5d9a10d2e 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -505,7 +505,7 @@ fn map_links<'e>( Event::End(Tag::Link(link_type, target, _)) => { in_link = false; Event::End(Tag::Link( - end_link_type.unwrap_or(link_type), + end_link_type.take().unwrap_or(link_type), end_link_target.take().unwrap_or(target), CowStr::Borrowed(""), )) @@ -514,7 +514,7 @@ fn map_links<'e>( let (link_type, link_target_s, link_name) = callback(&end_link_target.take().unwrap(), &s, range, end_link_type.unwrap()); end_link_target = Some(CowStr::Boxed(link_target_s.into())); - if !matches!(end_link_type, Some(LinkType::Autolink)) { + if !matches!(end_link_type, Some(LinkType::Autolink)) && link_type.is_some() { end_link_type = link_type; } Event::Text(CowStr::Boxed(link_name.into())) @@ -523,7 +523,7 @@ fn map_links<'e>( let (link_type, link_target_s, link_name) = callback(&end_link_target.take().unwrap(), &s, range, end_link_type.unwrap()); end_link_target = Some(CowStr::Boxed(link_target_s.into())); - if !matches!(end_link_type, Some(LinkType::Autolink)) { + if !matches!(end_link_type, Some(LinkType::Autolink)) && link_type.is_some() { end_link_type = link_type; } Event::Code(CowStr::Boxed(link_name.into())) diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index f63499aa0f..c3afd7da2d 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -10958,3 +10958,30 @@ fn bar$0() -> Foo { "#]], ); } + +#[test] +fn regression_20190() { + check( + r#" +struct Foo; + +/// [`foo` bar](Foo). +fn has_docs$0() {} + "#, + expect![[r#" + *has_docs* + + ```rust + ra_test_fixture + ``` + + ```rust + fn has_docs() + ``` + + --- + + [`foo` bar](https://docs.rs/ra_test_fixture/*/ra_test_fixture/struct.Foo.html). + "#]], + ); +}