Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Correct anchor for links to associated trait items #32461

Merged
merged 9 commits into from
Mar 29, 2016

Conversation

mitaa
Copy link
Contributor

@mitaa mitaa commented Mar 24, 2016

@@ -2085,7 +2085,13 @@ fn render_assoc_item(w: &mut fmt::Formatter, meth: &clean::Item,
let href = match link {
AssocItemLink::Anchor => anchor,
AssocItemLink::GotoSource(did) => {
href(did).map(|p| format!("{}{}", p.0, anchor)).unwrap_or(anchor)
// We're creating a link from an impl-item to the corresponding
// trait-item and need to map the anchored type accordingly.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. This is wrong for default methods ("provided methods")

pub trait Bar {
    // #method.bar
    fn bar(&self) {}
    // #tymethod.baz
    fn baz(&self);
}

pub struct Foo;

impl Bar for Foo {
    fn baz(&self) {}
}

@alexcrichton
Copy link
Member

Hm so right now we have a linkchecker script which ensures that all links point to valid locations. Perhaps we could extend that with checking anchors as well? It may be relatively easy enough to just grep for id="foo" in a page given an anchor that we see.

@mitaa mitaa force-pushed the rdoc-anchors branch 2 times, most recently from 5d3e500 to 23de1cc Compare March 25, 2016 02:28
@mitaa
Copy link
Contributor Author

mitaa commented Mar 25, 2016

Good idea, I've mostly got the linkchecker working, now I just need to somehow deal with redirect pages.
(going to push that onto this branch sometime today)

@alexcrichton
Copy link
Member

Nice! Feel free to ping me when that happens and I'll likely r+ :)

@mitaa mitaa force-pushed the rdoc-anchors branch 5 times, most recently from ea78484 to d742cda Compare March 26, 2016 20:50
mitaa added 7 commits March 27, 2016 00:20
These should always correspond to the values in `ItemType::to_static_str`
This adds checks to ensure that:
* link anchors refer to existing id's on the target page
* id's are unique within an html document
* page redirects are valid
Adding these "known" values to the table of used ids is only required
when embedding markdown into a rustdoc  html page and may yield
unexpected results when rendering a standalone `*.md` file.
@mitaa
Copy link
Contributor Author

mitaa commented Mar 27, 2016

(updated)

I've had to whitelist some cases in the same vein as #32130, and collections/string/String does not have the methods from Deref<Target=str> section for some reason breaking links to str methods on the same page (not sure what's up with that).

if file.ends_with("std/string/struct.String.html") {
return
if file.ends_with("std/string/struct.String.html") ||
file.ends_with("collections/string/struct.String.html") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the addition of these new ignores, can you be sure that issues are filed and these are tagged with a FIXME?

@alexcrichton
Copy link
Member

@bors: r+ 41916d8

Oh man this is exciting, thanks @mitaa!

@bors
Copy link
Contributor

bors commented Mar 27, 2016

⌛ Testing commit 41916d8 with merge a464b19...

@bors
Copy link
Contributor

bors commented Mar 27, 2016

💔 Test failed - auto-win-msvc-64-opt-rustbuild

mitaa added 2 commits March 28, 2016 16:00
Checking a redirect page during tree traversal before trying to actually
follow the redirect leads to retrieval of the redirect pages source
instead.
@mitaa mitaa force-pushed the rdoc-anchors branch 3 times, most recently from 7849e2f to 4e0abdb Compare March 28, 2016 15:07
@mitaa
Copy link
Contributor Author

mitaa commented Mar 28, 2016

(updated, should work now)

@alexcrichton
Copy link
Member

@bors: r+ 4e0abdb

@bors
Copy link
Contributor

bors commented Mar 29, 2016

⌛ Testing commit 4e0abdb with merge cad964a...

bors added a commit that referenced this pull request Mar 29, 2016
rustdoc: Correct anchor for links to associated trait items

fixes #28478

r? @alexcrichton
@bors bors merged commit 4e0abdb into rust-lang:master Mar 29, 2016
@mitaa mitaa deleted the rdoc-anchors branch March 29, 2016 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc generates bad fragments in links to trait methods
3 participants