diff options
| author | Lukas Wirth <me@lukaswirth.dev> | 2025-07-08 05:52:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-08 05:52:58 +0000 |
| commit | eed37be4195be6903ff4d7381fb38eda38febcee (patch) | |
| tree | 3cfe3dadd7275615f8225b1e396c48cb7c1e0008 | |
| parent | 0209f9e5f87a943b1461e883ff4b101cee6e2b1a (diff) | |
| parent | aa331b1c5f91562d8c1ad0875b5e0dc6668dc2b0 (diff) | |
| download | rust-eed37be4195be6903ff4d7381fb38eda38febcee.tar.gz rust-eed37be4195be6903ff4d7381fb38eda38febcee.zip | |
Merge pull request #20192 from ChayimFriedman2/link-type-panic
fix: Fix a case where the link type was `None`
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/doc_links.rs | 6 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/hover/tests.rs | 27 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs b/src/tools/rust-analyzer/crates/ide/src/doc_links.rs index f58202a4213..a5d9a10d2e5 100644 --- a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs index f63499aa0fd..c3afd7da2df 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs +++ b/src/tools/rust-analyzer/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. + "#]], + ); +} |
