Rollup merge of #35234 - nrc:rustdoc-macros, r=steveklabnik

rustdoc: remove the `!` from macro URLs and titles

Because the `!` is part of a macro use, not the macro's name. E.g., you write `macro_rules! foo` not `macro_rules! foo!`, also `#[macro_import(foo)]`.

(Pulled out of #35020).
This commit is contained in:
Jonathan Turner 2016-08-20 07:09:33 -07:00 committed by GitHub
commit d5595d1f3e
10 changed files with 35 additions and 15 deletions

View File

@ -59,7 +59,7 @@ handling is reducing the amount of explicit case analysis the programmer has to
do while keeping code composable. do while keeping code composable.
Keeping code composable is important, because without that requirement, we Keeping code composable is important, because without that requirement, we
could [`panic`](../std/macro.panic!.html) whenever we could [`panic`](../std/macro.panic.html) whenever we
come across something unexpected. (`panic` causes the current task to unwind, come across something unexpected. (`panic` causes the current task to unwind,
and in most cases, the entire program aborts.) Here's an example: and in most cases, the entire program aborts.) Here's an example:
@ -944,7 +944,7 @@ macro_rules! try {
} }
``` ```
(The [real definition](../std/macro.try!.html) is a bit more (The [real definition](../std/macro.try.html) is a bit more
sophisticated. We will address that later.) sophisticated. We will address that later.)
Using the `try!` macro makes it very easy to simplify our last example. Since Using the `try!` macro makes it very easy to simplify our last example. Since
@ -1271,7 +1271,7 @@ macro_rules! try {
``` ```
This is not its real definition. Its real definition is This is not its real definition. Its real definition is
[in the standard library](../std/macro.try!.html): [in the standard library](../std/macro.try.html):
<span id="code-try-def"></span> <span id="code-try-def"></span>
@ -2178,7 +2178,7 @@ heuristics!
[`From`](../std/convert/trait.From.html) [`From`](../std/convert/trait.From.html)
and and
[`Error`](../std/error/trait.Error.html) [`Error`](../std/error/trait.Error.html)
impls to make the [`try!`](../std/macro.try!.html) impls to make the [`try!`](../std/macro.try.html)
macro more ergonomic. macro more ergonomic.
* If you're writing a library and your code can produce errors, define your own * If you're writing a library and your code can produce errors, define your own
error type and implement the error type and implement the

View File

@ -530,7 +530,7 @@ use string;
/// assert_eq!(s, "Hello, world!"); /// assert_eq!(s, "Hello, world!");
/// ``` /// ```
/// ///
/// [format!]: ../macro.format!.html /// [format!]: ../macro.format.html
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn format(args: Arguments) -> string::String { pub fn format(args: Arguments) -> string::String {
let mut output = string::String::new(); let mut output = string::String::new();

View File

@ -2803,7 +2803,7 @@ pub struct Macro {
impl Clean<Item> for doctree::Macro { impl Clean<Item> for doctree::Macro {
fn clean(&self, cx: &DocContext) -> Item { fn clean(&self, cx: &DocContext) -> Item {
let name = format!("{}!", self.name.clean(cx)); let name = self.name.clean(cx);
Item { Item {
name: Some(name.clone()), name: Some(name.clone()),
attrs: self.attrs.clean(cx), attrs: self.attrs.clean(cx),
@ -2814,8 +2814,10 @@ impl Clean<Item> for doctree::Macro {
def_id: cx.map.local_def_id(self.id), def_id: cx.map.local_def_id(self.id),
inner: MacroItem(Macro { inner: MacroItem(Macro {
source: format!("macro_rules! {} {{\n{}}}", source: format!("macro_rules! {} {{\n{}}}",
name.trim_right_matches('!'), self.matchers.iter().map(|span| name,
format!(" {} => {{ ... }};\n", span.to_src(cx))).collect::<String>()), self.matchers.iter().map(|span| {
format!(" {} => {{ ... }};\n", span.to_src(cx))
}).collect::<String>()),
imported_from: self.imported_from.clean(cx), imported_from: self.imported_from.clean(cx),
}), }),
} }

View File

@ -1426,6 +1426,16 @@ impl Context {
.open(&redir_dst) { .open(&redir_dst) {
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
} }
// If the item is a macro, redirect from the old macro URL (with !)
// to the new one (without).
// FIXME(#35705) remove this redirect.
if item_type == ItemType::Macro {
let redir_name = format!("{}.{}!.html", item_type, name);
let redir_dst = self.dst.join(redir_name);
let mut redirect_out = try_err!(File::create(&redir_dst), &redir_dst);
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
}
} }
} }
Ok(()) Ok(())

View File

@ -236,7 +236,7 @@
//! to read the line and print it, so we use `()`. //! to read the line and print it, so we use `()`.
//! //!
//! [result]: type.Result.html //! [result]: type.Result.html
//! [try]: ../macro.try!.html //! [try]: ../macro.try.html
//! //!
//! ## Platform-specific behavior //! ## Platform-specific behavior
//! //!
@ -957,8 +957,8 @@ pub trait Write {
/// explicitly be called. The [`write!`][write] macro should be favored to /// explicitly be called. The [`write!`][write] macro should be favored to
/// invoke this method instead. /// invoke this method instead.
/// ///
/// [formatargs]: ../macro.format_args!.html /// [formatargs]: ../macro.format_args.html
/// [write]: ../macro.write!.html /// [write]: ../macro.write.html
/// ///
/// This function internally uses the [`write_all`][writeall] method on /// This function internally uses the [`write_all`][writeall] method on
/// this trait and hence will continuously write data so long as no errors /// this trait and hence will continuously write data so long as no errors

View File

@ -175,7 +175,7 @@
//! [`atomic`]: sync/atomic/index.html //! [`atomic`]: sync/atomic/index.html
//! [`collections`]: collections/index.html //! [`collections`]: collections/index.html
//! [`for`]: ../book/loops.html#for //! [`for`]: ../book/loops.html#for
//! [`format!`]: macro.format!.html //! [`format!`]: macro.format.html
//! [`fs`]: fs/index.html //! [`fs`]: fs/index.html
//! [`io`]: io/index.html //! [`io`]: io/index.html
//! [`iter`]: iter/index.html //! [`iter`]: iter/index.html

View File

@ -27,7 +27,7 @@
/// assert!(!bool_val); /// assert!(!bool_val);
/// ``` /// ```
/// ///
/// [`assert!`]: macro.assert!.html /// [`assert!`]: macro.assert.html
/// [`if`]: ../book/if.html /// [`if`]: ../book/if.html
/// [`BitAnd`]: ops/trait.BitAnd.html /// [`BitAnd`]: ops/trait.BitAnd.html
/// [`BitOr`]: ops/trait.BitOr.html /// [`BitOr`]: ops/trait.BitOr.html

View File

@ -12,7 +12,7 @@
// ignore-cross-compile // ignore-cross-compile
// build-aux-docs // build-aux-docs
// @has issue_26606_macro/macro.make_item!.html // @has issue_26606_macro/macro.make_item.html
#[macro_use] #[macro_use]
extern crate issue_26606_macro; extern crate issue_26606_macro;

View File

@ -8,10 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// @has macros/macro.my_macro!.html //pre 'macro_rules! my_macro {' // @has macros/macro.my_macro.html //pre 'macro_rules! my_macro {'
// @has - //pre '() => { ... };' // @has - //pre '() => { ... };'
// @has - //pre '($a:tt) => { ... };' // @has - //pre '($a:tt) => { ... };'
// @has - //pre '($e:expr) => { ... };' // @has - //pre '($e:expr) => { ... };'
// @has macros/macro.my_macro!.html
// @has - //a 'macro.my_macro.html'
#[macro_export] #[macro_export]
macro_rules! my_macro { macro_rules! my_macro {
() => []; () => [];

View File

@ -42,3 +42,9 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[metadata]
"checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11"
"checksum matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "15305656809ce5a4805b1ff2946892810992197ce1270ff79baded852187942e"
"checksum unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c1f7ceb96afdfeedee42bade65a0d585a6a0106f681b6749c8ff4daa8df30b3f"
"checksum unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "26643a2f83bac55f1976fb716c10234485f9202dcd65cfbdf9da49867b271172"
"checksum url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afe9ec54bc4db14bc8744b7fed060d785ac756791450959b2248443319d5b119"