Skip to content

rustdoc: Incorrect html escaping when struct implements trait with generic type as target #46724

Closed
@yoursvivek

Description

@yoursvivek

For following sample crate named docfail html doc for sidebar doesn't escape angled brackets (<, >) for generic type as target.

// src/lib.rs
use std::ops::{Deref, DerefMut};
 
/// Title
#[derive(Debug, Clone)]
pub struct Title {
    name: String,
}
 
/// Title Collection
#[derive(Debug, Clone)]
pub struct TitleList {
    pub members: Vec<Title>,
}
 
impl TitleList {
    // Constructor
    pub fn new() -> Self {
        TitleList { members: Vec::new() }
    }
}
 
impl Deref for TitleList {
    type Target = Vec<Title>;
 
    fn deref(&self) -> &Self::Target {
        &self.members
    }
}
 
impl DerefMut for TitleList {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.members
    }
}

Following is rustdoc generates html compared with expected html (diff -u target/doc/docfail/struct.TitleList.html target/doc/docfail/expected_struct.TitleList.html). Notice changes in 32nd line 200th column.

--- target/doc/docfail/struct.TitleList.html	2017-12-14 13:01:13.000000000 +0530
+++ target/doc/docfail/expected_struct.TitleList.html	2017-12-14 12:28:43.000000000 +0530
@@ -29,7 +29,7 @@
 
     <nav class="sidebar">
         
-        <p class='location'>Struct TitleList</p><div class="block items"><ul><li><a href="#fields">Fields</a></li><li><a href="#methods">Methods</a></li><li><a href="#deref-methods">Methods from Deref&lt;Target=Vec<Title>&gt;</a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='index.html'>docfail</a></p><script>window.sidebarCurrent = {name: 'TitleList', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script>
+        <p class='location'>Struct TitleList</p><div class="block items"><ul><li><a href="#fields">Fields</a></li><li><a href="#methods">Methods</a></li><li><a href="#deref-methods">Methods from Deref&lt;Target=Vec&lt;Title&gt;&gt;</a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='index.html'>docfail</a></p><script>window.sidebarCurrent = {name: 'TitleList', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script>
     </nav>
 
     <nav class="sub">

In my case, as the generic struct is coincidently named Title the corresponding html (<Title>) throws browser bonkers and nothing but sidebar is visible.

Rustdoc version used: rustdoc 1.22.1 (05e2e1c41 2017-11-22)

Metadata

Metadata

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions