diff options
| author | kennytm <kennytm@gmail.com> | 2018-03-22 17:51:30 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-03-22 22:43:43 +0800 |
| commit | d7eda77692282c27013981e7a1309404125f3a8b (patch) | |
| tree | 458c675e6dcd0c29aa677a7ea3689c903d8a5a7c | |
| parent | 95967c7c722f76cc894752aa2ab4e5c7ef7aa284 (diff) | |
| parent | bac6484a315a805287b98adc3c9c0909579c8393 (diff) | |
| download | rust-d7eda77692282c27013981e7a1309404125f3a8b.tar.gz rust-d7eda77692282c27013981e7a1309404125f3a8b.zip | |
Rollup merge of #49189 - GuillaumeGomez:fix-implied-shortcut-links, r=QuietMisdreavus
Fix automatic urls with backticks Fixes #49164. r? @QuietMisdreavus
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 16 | ||||
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 4 | ||||
| -rw-r--r-- | src/test/rustdoc/check-styled-link.rs | 18 |
3 files changed, 28 insertions, 10 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b3ee685fb84..1a42b02140c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -942,7 +942,7 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes, select the {}", disambig1, kind1, disambig2, kind2)) - .emit(); + .emit(); } /// Given an enum variant's def, return the def of its enum and the associated fragment @@ -1087,6 +1087,7 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> { } } +#[derive(Debug)] enum PathKind { /// can be either value or type, not a macro Unknown, @@ -1095,7 +1096,7 @@ enum PathKind { /// values, functions, consts, statics, everything in the value namespace Value, /// types, traits, everything in the type namespace - Type + Type, } impl Clean<Attributes> for [ast::Attribute] { @@ -1104,12 +1105,13 @@ impl Clean<Attributes> for [ast::Attribute] { if UnstableFeatures::from_environment().is_nightly_build() { let dox = attrs.collapsed_doc_value().unwrap_or_else(String::new); - for link in markdown_links(&dox) { + for ori_link in markdown_links(&dox) { // bail early for real links - if link.contains('/') { + if ori_link.contains('/') { continue; } - let (def, fragment) = { + let link = ori_link.replace("`", ""); + let (def, fragment) = { let mut kind = PathKind::Unknown; let path_str = if let Some(prefix) = ["struct@", "enum@", "type@", @@ -1145,7 +1147,6 @@ impl Clean<Attributes> for [ast::Attribute] { continue; } - match kind { PathKind::Value => { if let Ok(def) = resolve(cx, path_str, true) { @@ -1219,9 +1220,8 @@ impl Clean<Attributes> for [ast::Attribute] { } }; - let id = register_def(cx, def); - attrs.links.push((link, id, fragment)); + attrs.links.push((ori_link, id, fragment)); } cx.sess().abort_if_errors(); diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 5ce3d57f82f..c09bd4cc84a 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -233,14 +233,14 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> { /// Make headings links with anchor ids and build up TOC. struct LinkReplacer<'a, 'b, I: Iterator<Item = Event<'a>>> { inner: I, - links: &'b [(String, String)] + links: &'b [(String, String)], } impl<'a, 'b, I: Iterator<Item = Event<'a>>> LinkReplacer<'a, 'b, I> { fn new(iter: I, links: &'b [(String, String)]) -> Self { LinkReplacer { inner: iter, - links + links, } } } diff --git a/src/test/rustdoc/check-styled-link.rs b/src/test/rustdoc/check-styled-link.rs new file mode 100644 index 00000000000..1633711e83d --- /dev/null +++ b/src/test/rustdoc/check-styled-link.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "foo"] + +pub struct Foo; + +// @has foo/struct.Bar.html '//a[@href="../foo/struct.Foo.html"]' 'Foo' + +/// Code-styled reference to [`Foo`]. +pub struct Bar; |
