@@ -720,9 +720,24 @@ fn generate_rustdoc_url(name: &str, version: &ReqVersion, path: &str) -> Escaped
720720fn generate_rustdoc_path_for_url (
721721 target_name : Option < & str > ,
722722 default_target : Option < & str > ,
723- doc_target : Option < & str > ,
724- inner_path : Option < & str > ,
723+ mut doc_target : Option < & str > ,
724+ mut inner_path : Option < & str > ,
725725) -> String {
726+ // if we have an "unparsed" set of params, we might have a part of
727+ // the inner path in `doc_target`. Thing is:
728+ // We don't know if that's a real target, or a part of the path,
729+ // But the "saner" default for this method is to treat it as part
730+ // of the path, not a potential doc target.
731+ let inner_path = if target_name. is_none ( )
732+ && default_target. is_none ( )
733+ && let ( Some ( doc_target) , Some ( inner_path) ) = ( doc_target. take ( ) , inner_path. as_mut ( ) )
734+ && !doc_target. is_empty ( )
735+ {
736+ Some ( format ! ( "{doc_target}/{inner_path}" ) )
737+ } else {
738+ inner_path. map ( |s| s. to_string ( ) )
739+ } ;
740+
726741 // first validate & fix the inner path to use.
727742 let result = if let Some ( path) = inner_path
728743 && !path. is_empty ( )
@@ -737,7 +752,7 @@ fn generate_rustdoc_path_for_url(
737752 // * it's not just "index.html"
738753 // * we have a slash in the path.
739754 path. to_string ( )
740- } else if ROOT_RUSTDOC_HTML_FILES . contains ( & path) {
755+ } else if ROOT_RUSTDOC_HTML_FILES . contains ( & path. as_str ( ) ) {
741756 // special case: some files are at the root of the rustdoc output,
742757 // without a trailing slash, and the routes are fine with that.
743758 // e.g. `/help.html`, `/settings.html`, `/all.html`, ...
@@ -1682,4 +1697,23 @@ mod tests {
16821697
16831698 assert_eq ! ( params. rustdoc_url( ) , expected_url) ;
16841699 }
1700+
1701+ #[ test]
1702+ fn test_item_with_semver_url ( ) {
1703+ // https://github.com/rust-lang/docs.rs/iss
1704+
1705+ let ver: Version = "0.14.0" . parse ( ) . unwrap ( ) ;
1706+ let params = RustdocParams :: new ( KRATE )
1707+ . with_page_kind ( PageKind :: Rustdoc )
1708+ . with_req_version ( ReqVersion :: Exact ( ver) )
1709+ . with_doc_target ( KRATE )
1710+ . with_inner_path ( "trait.Itertools.html" ) ;
1711+
1712+ dbg ! ( & params) ;
1713+
1714+ assert_eq ! (
1715+ params. rustdoc_url( ) ,
1716+ format!( "/{KRATE}/0.14.0/{KRATE}/trait.Itertools.html" )
1717+ )
1718+ }
16851719}
0 commit comments