Skip to content

Commit 9a1fc3c

Browse files
authored
Merge pull request #20192 from ChayimFriedman2/link-type-panic
fix: Fix a case where the link type was `None`
2 parents 778e08d + 793e157 commit 9a1fc3c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

crates/ide/src/doc_links.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ fn map_links<'e>(
505505
Event::End(Tag::Link(link_type, target, _)) => {
506506
in_link = false;
507507
Event::End(Tag::Link(
508-
end_link_type.unwrap_or(link_type),
508+
end_link_type.take().unwrap_or(link_type),
509509
end_link_target.take().unwrap_or(target),
510510
CowStr::Borrowed(""),
511511
))
@@ -514,7 +514,7 @@ fn map_links<'e>(
514514
let (link_type, link_target_s, link_name) =
515515
callback(&end_link_target.take().unwrap(), &s, range, end_link_type.unwrap());
516516
end_link_target = Some(CowStr::Boxed(link_target_s.into()));
517-
if !matches!(end_link_type, Some(LinkType::Autolink)) {
517+
if !matches!(end_link_type, Some(LinkType::Autolink)) && link_type.is_some() {
518518
end_link_type = link_type;
519519
}
520520
Event::Text(CowStr::Boxed(link_name.into()))
@@ -523,7 +523,7 @@ fn map_links<'e>(
523523
let (link_type, link_target_s, link_name) =
524524
callback(&end_link_target.take().unwrap(), &s, range, end_link_type.unwrap());
525525
end_link_target = Some(CowStr::Boxed(link_target_s.into()));
526-
if !matches!(end_link_type, Some(LinkType::Autolink)) {
526+
if !matches!(end_link_type, Some(LinkType::Autolink)) && link_type.is_some() {
527527
end_link_type = link_type;
528528
}
529529
Event::Code(CowStr::Boxed(link_name.into()))

crates/ide/src/hover/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10958,3 +10958,30 @@ fn bar$0() -> Foo {
1095810958
"#]],
1095910959
);
1096010960
}
10961+
10962+
#[test]
10963+
fn regression_20190() {
10964+
check(
10965+
r#"
10966+
struct Foo;
10967+
10968+
/// [`foo` bar](Foo).
10969+
fn has_docs$0() {}
10970+
"#,
10971+
expect![[r#"
10972+
*has_docs*
10973+
10974+
```rust
10975+
ra_test_fixture
10976+
```
10977+
10978+
```rust
10979+
fn has_docs()
10980+
```
10981+
10982+
---
10983+
10984+
[`foo` bar](https://docs.rs/ra_test_fixture/*/ra_test_fixture/struct.Foo.html).
10985+
"#]],
10986+
);
10987+
}

0 commit comments

Comments
 (0)