about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-02-21 16:29:52 +0100
committerGitHub <noreply@github.com>2018-02-21 16:29:52 +0100
commitfe1293f8a95d7a79ce2ef95bdc97241e92ffe5e5 (patch)
tree3158f7f3d3184760a41f03c607fac5cce56fef07 /src
parent27c6ff5c7ca6f23480f5676f94d06497cdab4b7a (diff)
parent5fdc10c68b3b5a42b17555be18baf5d7d60d55e6 (diff)
downloadrust-fe1293f8a95d7a79ce2ef95bdc97241e92ffe5e5.tar.gz
rust-fe1293f8a95d7a79ce2ef95bdc97241e92ffe5e5.zip
Rollup merge of #48335 - Manishearth:shortcut-links, r=QuietMisdreavus
Implement implied shortcut links for intra-rustdoc-links

cc https://github.com/rust-lang/rust/issues/43466

Needs https://github.com/google/pulldown-cmark/pull/126

r? @QuietMisdreavus
Diffstat (limited to 'src')
-rw-r--r--src/Cargo.lock8
-rw-r--r--src/librustdoc/Cargo.toml2
-rw-r--r--src/librustdoc/clean/mod.rs8
-rw-r--r--src/librustdoc/html/markdown.rs47
-rw-r--r--src/test/rustdoc/intra-links.rs12
5 files changed, 61 insertions, 16 deletions
diff --git a/src/Cargo.lock b/src/Cargo.lock
index d8306c66daf..7dc8374e3e8 100644
--- a/src/Cargo.lock
+++ b/src/Cargo.lock
@@ -1086,7 +1086,7 @@ dependencies = [
  "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1383,7 +1383,7 @@ dependencies = [
 
 [[package]]
 name = "pulldown-cmark"
-version = "0.1.0"
+version = "0.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2104,7 +2104,7 @@ dependencies = [
 name = "rustdoc"
 version = "0.0.0"
 dependencies = [
- "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -2886,7 +2886,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum pest 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a6dda33d67c26f0aac90d324ab2eb7239c819fc7b2552fe9faa4fe88441edc8"
 "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
 "checksum pulldown-cmark 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "378e941dbd392c101f2cb88097fa4d7167bc421d4b88de3ff7dbee503bc3233b"
-"checksum pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a656fdb8b6848f896df5e478a0eb9083681663e37dcb77dd16981ff65329fe8b"
+"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32"
 "checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4"
 "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45"
 "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml
index 09d0a0f610b..88b0f448622 100644
--- a/src/librustdoc/Cargo.toml
+++ b/src/librustdoc/Cargo.toml
@@ -10,5 +10,5 @@ path = "lib.rs"
 doctest = false
 
 [dependencies]
-pulldown-cmark = { version = "0.1.0", default-features = false }
+pulldown-cmark = { version = "0.1.2", default-features = false }
 tempdir = "0.3"
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index ff6d14f0457..4543b246b83 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1044,7 +1044,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
 
 /// Resolve a string as a macro
 fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
-    use syntax::ext::base::MacroKind;
+    use syntax::ext::base::{MacroKind, SyntaxExtension};
     use syntax::ext::hygiene::Mark;
     let segment = ast::PathSegment {
         identifier: ast::Ident::from_str(path_str),
@@ -1061,7 +1061,11 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
     let res = resolver
         .resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
     if let Ok(def) = res {
-        Some(def)
+        if let SyntaxExtension::DeclMacro(..) = *resolver.get_macro(def) {
+            Some(def)
+        } else {
+            None
+        }
     } else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
         Some(*def)
     } else {
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index fedd802ce55..66fe2280aef 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -591,7 +591,15 @@ impl<'a> fmt::Display for Markdown<'a> {
         opts.insert(OPTION_ENABLE_TABLES);
         opts.insert(OPTION_ENABLE_FOOTNOTES);
 
-        let p = Parser::new_ext(md, opts);
+        let replacer = |_: &str, s: &str| {
+            if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
+                Some((replace.clone(), s.to_owned()))
+            } else {
+                None
+            }
+        };
+
+        let p = Parser::new_with_broken_link_callback(md, opts, Some(&replacer));
 
         let mut s = String::with_capacity(md.len() * 3 / 2);
 
@@ -662,7 +670,16 @@ impl<'a> fmt::Display for MarkdownSummaryLine<'a> {
         // This is actually common enough to special-case
         if md.is_empty() { return Ok(()) }
 
-        let p = Parser::new(md);
+        let replacer = |_: &str, s: &str| {
+            if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
+                Some((replace.clone(), s.to_owned()))
+            } else {
+                None
+            }
+        };
+
+        let p = Parser::new_with_broken_link_callback(md, Options::empty(),
+                                                      Some(&replacer));
 
         let mut s = String::new();
 
@@ -731,18 +748,30 @@ pub fn markdown_links(md: &str) -> Vec<String> {
     opts.insert(OPTION_ENABLE_TABLES);
     opts.insert(OPTION_ENABLE_FOOTNOTES);
 
-    let p = Parser::new_ext(md, opts);
-
-    let iter = Footnotes::new(HeadingLinks::new(p, None));
     let mut links = vec![];
+    let shortcut_links = RefCell::new(vec![]);
+
+    {
+        let push = |_: &str, s: &str| {
+            shortcut_links.borrow_mut().push(s.to_owned());
+            None
+        };
+        let p = Parser::new_with_broken_link_callback(md, opts,
+            Some(&push));
+
+        let iter = Footnotes::new(HeadingLinks::new(p, None));
 
-    for ev in iter {
-        if let Event::Start(Tag::Link(dest, _)) = ev {
-            debug!("found link: {}", dest);
-            links.push(dest.into_owned());
+        for ev in iter {
+            if let Event::Start(Tag::Link(dest, _)) = ev {
+                debug!("found link: {}", dest);
+                links.push(dest.into_owned());
+            }
         }
     }
 
+    let mut shortcut_links = shortcut_links.into_inner();
+    links.extend(shortcut_links.drain(..));
+
     links
 }
 
diff --git a/src/test/rustdoc/intra-links.rs b/src/test/rustdoc/intra-links.rs
index 4726323e11c..c822d0f8b21 100644
--- a/src/test/rustdoc/intra-links.rs
+++ b/src/test/rustdoc/intra-links.rs
@@ -77,3 +77,15 @@ pub trait SoAmbiguous {}
 
 #[allow(bad_style)]
 pub fn SoAmbiguous() {}
+
+
+// @has - '//a/@href' '../intra_links/struct.ThisType.html'
+// @has - '//a/@href' '../intra_links/struct.ThisType.html#method.this_method'
+// @has - '//a/@href' '../intra_links/enum.ThisEnum.html'
+// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#ThisVariant.v'
+/// Shortcut links for:
+/// * [`ThisType`]
+/// * [`ThisType::this_method`]
+/// * [ThisEnum]
+/// * [ThisEnum::ThisVariant]
+pub struct SomeOtherType;