Skip to content

Commit 22a5d95

Browse files
authored
fix: don't unwrap on url parsing for location.filename (#499)
and one minor cleanup
1 parent 60f9d38 commit 22a5d95

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

api/src/docs.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,22 +812,21 @@ impl HrefResolver for DocResolver {
812812
}
813813

814814
fn resolve_usage(&self, current_resolve: UrlResolveKind) -> Option<String> {
815-
let file = current_resolve
815+
let (is_main, path) = current_resolve
816816
.get_file()
817-
.map(|short_path| &*short_path.path)
817+
.map(|short_path| (short_path.is_main, &*short_path.path))
818818
.unwrap_or_default();
819819

820820
Some(format!(
821821
"@{}/{}{}",
822822
self.scope,
823823
self.package,
824-
if file == "." { "" } else { file }
824+
if is_main { "" } else { path }
825825
))
826826
}
827827

828828
fn resolve_source(&self, location: &Location) -> Option<String> {
829-
let url =
830-
Url::parse(&location.filename).expect("filename was generated with Url");
829+
let url = Url::parse(&location.filename).ok()?;
831830
Some(format!(
832831
"/@{}/{}/{}{}#L{}",
833832
self.scope,

0 commit comments

Comments
 (0)