diff options
| author | bors <bors@rust-lang.org> | 2018-01-23 07:38:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-23 07:38:53 +0000 |
| commit | 48a7ea9c4095e3218df39832dfc51a456534ecc9 (patch) | |
| tree | f9b180716e6551ea716040850288b68bea67294f /src/test/rustdoc | |
| parent | 47a8eb7c4e24b61a8a9ab4eaff60ef65291aaa56 (diff) | |
| parent | 63811b66f676c1971b15452946bad35223b8c403 (diff) | |
| download | rust-48a7ea9c4095e3218df39832dfc51a456534ecc9.tar.gz rust-48a7ea9c4095e3218df39832dfc51a456534ecc9.zip | |
Auto merge of #47046 - Manishearth:intra-doc-links, r=eddyb,GuillaumeGomez,QuietMisdreavus,Manishearth
Implement RFC 1946 - intra-rustdoc links https://github.com/rust-lang/rfcs/pull/1946 https://github.com/rust-lang/rust/issues/43466 Note for reviewers: The plain line counts are a little inflated because of how the markdown link parsing was done. [Read the file diff with "whitespace only" changes removed](https://github.com/rust-lang/rust/pull/47046/files?w=1) to get a better view of what actually changed there. This pulls the name/path resolution mechanisms out of the compiler and runs it on the markdown in a crate's docs, so that links can be made to `SomeStruct` directly rather than finding the folder path to `struct.SomeStruct.html`. Check the `src/test/rustdoc/intra-paths.rs` test in this PR for a demo. The change was... a little invasive, but unlocks a really powerful mechanism for writing documentation that doesn't care about where an item was written to on the hard disk. Items included: - [x] Make work with the hoedown renderer - [x] Handle relative paths - [x] Parse out the "path ambiguities" qualifiers (`[crate foo]`, `[struct Foo]`, `[foo()]`, `[static FOO]`, `[foo!]`, etc) - [x] Resolve foreign macros - [x] Resolve local macros - [x] Handle the use of inner/outer attributes giving different resolution scopes (handling for non-modules pushed to different PR) Items not included: - [ ] Make sure cross-crate inlining works (blocked on refactor described in https://github.com/rust-lang/rust/pull/47046#issuecomment-354824520) - [ ] Implied Shortcut Reference Links (where just doing `[::std::iter::Iterator][]` without a reference anchor will resolve using the reference name rather than the link target) (requires modifying the markdown parser - blocked on Hoedown/Pulldown switch and https://github.com/google/pulldown-cmark/issues/121) - [ ] Handle enum variants and UFCS methods (Enum variants link to the enum page, associated methods don't link at all) - [ ] Emit more warnings/errors when things fail to resolve (linking to a value-namespaced item without a qualifier will emit an error, otherwise the link is just treated as a url, not a rust path) - [ ] Give better spans for resolution errors (currently the span for the first doc comment is used) - [ ] Check for inner doc comments on things that aren't modules I'm making the PR, but it should be noted that most of the work was done by Misdreavus :smile: (Editor's note: This has become a lie, check that commit log, Manish did a ton of work after this PR was opened `>_>`)
Diffstat (limited to 'src/test/rustdoc')
| -rw-r--r-- | src/test/rustdoc/intra-links.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/rustdoc/intra-links.rs b/src/test/rustdoc/intra-links.rs new file mode 100644 index 00000000000..aa6f5538754 --- /dev/null +++ b/src/test/rustdoc/intra-links.rs @@ -0,0 +1,60 @@ +// Copyright 2017 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. + +// @has intra_links/index.html +// @has - '//a/@href' '../intra_links/struct.ThisType.html' +// @has - '//a/@href' '../intra_links/enum.ThisEnum.html' +// @has - '//a/@href' '../intra_links/trait.ThisTrait.html' +// @has - '//a/@href' '../intra_links/type.ThisAlias.html' +// @has - '//a/@href' '../intra_links/union.ThisUnion.html' +// @has - '//a/@href' '../intra_links/fn.this_function.html' +// @has - '//a/@href' '../intra_links/constant.THIS_CONST.html' +// @has - '//a/@href' '../intra_links/static.THIS_STATIC.html' +// @has - '//a/@href' '../intra_links/macro.this_macro.html' +// @has - '//a/@href' '../intra_links/trait.SoAmbiguous.html' +// @has - '//a/@href' '../intra_links/fn.SoAmbiguous.html' +//! In this crate we would like to link to: +//! +//! * [`ThisType`](ThisType) +//! * [`ThisEnum`](ThisEnum) +//! * [`ThisTrait`](ThisTrait) +//! * [`ThisAlias`](ThisAlias) +//! * [`ThisUnion`](ThisUnion) +//! * [`this_function`](this_function()) +//! * [`THIS_CONST`](const@THIS_CONST) +//! * [`THIS_STATIC`](static@THIS_STATIC) +//! * [`this_macro`](this_macro!) +//! +//! In addition, there's some specifics we want to look at. There's [a trait called +//! SoAmbiguous][ambig-trait], but there's also [a function called SoAmbiguous][ambig-fn] too! +//! Whatever shall we do? +//! +//! [ambig-trait]: trait@SoAmbiguous +//! [ambig-fn]: SoAmbiguous() + +#[macro_export] +macro_rules! this_macro { + () => {}; +} + +pub struct ThisType; +pub enum ThisEnum { ThisVariant, } +pub trait ThisTrait {} +pub type ThisAlias = Result<(), ()>; +pub union ThisUnion { this_field: usize, } + +pub fn this_function() {} +pub const THIS_CONST: usize = 5usize; +pub static THIS_STATIC: usize = 5usize; + +pub trait SoAmbiguous {} + +#[allow(bad_style)] +pub fn SoAmbiguous() {} |
