From 6818551c6f3a434752d0322fce03d594513b5ebd Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 18 Feb 2018 13:33:56 -0800 Subject: [PATCH 1/5] bump pulldown --- src/Cargo.lock | 8 ++++---- src/librustdoc/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index d8306c66daf84..7dc8374e3e8fd 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 09d0a0f610b7b..88b0f4486223c 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" From f60aeec5d564cf3ca0628db55abb8c62276e102f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 18 Feb 2018 13:37:52 -0800 Subject: [PATCH 2/5] Include shortcut links in markdown_links --- src/librustdoc/html/markdown.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index fedd802ce557f..bc7d1066ba45e 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -731,18 +731,30 @@ pub fn markdown_links(md: &str) -> Vec { 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)); - for ev in iter { - if let Event::Start(Tag::Link(dest, _)) = ev { - debug!("found link: {}", dest); - links.push(dest.into_owned()); + 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()); + } } } + let mut shortcut_links = shortcut_links.into_inner(); + links.extend(shortcut_links.drain(..)); + links } From 1d0ae9f174dd7fbefc268dc52fcac35627afa42d Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 18 Feb 2018 14:32:34 -0800 Subject: [PATCH 3/5] Generate shortcut links --- src/librustdoc/html/markdown.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index bc7d1066ba45e..66fe2280aef7e 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(); From a04c124078ae9142588363e54877b9a151fb2043 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 18 Feb 2018 14:55:48 -0800 Subject: [PATCH 4/5] Add test --- src/test/rustdoc/intra-links.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/rustdoc/intra-links.rs b/src/test/rustdoc/intra-links.rs index 4726323e11cef..c822d0f8b21b8 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; From 5fdc10c68b3b5a42b17555be18baf5d7d60d55e6 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 18 Feb 2018 15:44:24 -0800 Subject: [PATCH 5/5] Filter out non-macros in resolve_macro Fixes https://github.com/rust-lang/rust/issues/48341 --- src/librustdoc/clean/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7f51b8f68ae49..6accda1d85179 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1008,7 +1008,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 { - 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), @@ -1025,7 +1025,11 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option { 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 {