Skip to content

Commit d5595d1

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#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 rust-lang#35020).
2 parents 99867ee + 301401e commit d5595d1

File tree

10 files changed

+35
-15
lines changed

10 files changed

+35
-15
lines changed

src/doc/book/error-handling.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ handling is reducing the amount of explicit case analysis the programmer has to
5959
do while keeping code composable.
6060

6161
Keeping code composable is important, because without that requirement, we
62-
could [`panic`](../std/macro.panic!.html) whenever we
62+
could [`panic`](../std/macro.panic.html) whenever we
6363
come across something unexpected. (`panic` causes the current task to unwind,
6464
and in most cases, the entire program aborts.) Here's an example:
6565

@@ -944,7 +944,7 @@ macro_rules! try {
944944
}
945945
```
946946

947-
(The [real definition](../std/macro.try!.html) is a bit more
947+
(The [real definition](../std/macro.try.html) is a bit more
948948
sophisticated. We will address that later.)
949949

950950
Using the `try!` macro makes it very easy to simplify our last example. Since
@@ -1271,7 +1271,7 @@ macro_rules! try {
12711271
```
12721272

12731273
This is not its real definition. Its real definition is
1274-
[in the standard library](../std/macro.try!.html):
1274+
[in the standard library](../std/macro.try.html):
12751275

12761276
<span id="code-try-def"></span>
12771277

@@ -2178,7 +2178,7 @@ heuristics!
21782178
[`From`](../std/convert/trait.From.html)
21792179
and
21802180
[`Error`](../std/error/trait.Error.html)
2181-
impls to make the [`try!`](../std/macro.try!.html)
2181+
impls to make the [`try!`](../std/macro.try.html)
21822182
macro more ergonomic.
21832183
* If you're writing a library and your code can produce errors, define your own
21842184
error type and implement the

src/libcollections/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ use string;
530530
/// assert_eq!(s, "Hello, world!");
531531
/// ```
532532
///
533-
/// [format!]: ../macro.format!.html
533+
/// [format!]: ../macro.format.html
534534
#[stable(feature = "rust1", since = "1.0.0")]
535535
pub fn format(args: Arguments) -> string::String {
536536
let mut output = string::String::new();

src/librustdoc/clean/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,7 +2803,7 @@ pub struct Macro {
28032803

28042804
impl Clean<Item> for doctree::Macro {
28052805
fn clean(&self, cx: &DocContext) -> Item {
2806-
let name = format!("{}!", self.name.clean(cx));
2806+
let name = self.name.clean(cx);
28072807
Item {
28082808
name: Some(name.clone()),
28092809
attrs: self.attrs.clean(cx),
@@ -2814,8 +2814,10 @@ impl Clean<Item> for doctree::Macro {
28142814
def_id: cx.map.local_def_id(self.id),
28152815
inner: MacroItem(Macro {
28162816
source: format!("macro_rules! {} {{\n{}}}",
2817-
name.trim_right_matches('!'), self.matchers.iter().map(|span|
2818-
format!(" {} => {{ ... }};\n", span.to_src(cx))).collect::<String>()),
2817+
name,
2818+
self.matchers.iter().map(|span| {
2819+
format!(" {} => {{ ... }};\n", span.to_src(cx))
2820+
}).collect::<String>()),
28192821
imported_from: self.imported_from.clean(cx),
28202822
}),
28212823
}

src/librustdoc/html/render.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,16 @@ impl Context {
14261426
.open(&redir_dst) {
14271427
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
14281428
}
1429+
1430+
// If the item is a macro, redirect from the old macro URL (with !)
1431+
// to the new one (without).
1432+
// FIXME(#35705) remove this redirect.
1433+
if item_type == ItemType::Macro {
1434+
let redir_name = format!("{}.{}!.html", item_type, name);
1435+
let redir_dst = self.dst.join(redir_name);
1436+
let mut redirect_out = try_err!(File::create(&redir_dst), &redir_dst);
1437+
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
1438+
}
14291439
}
14301440
}
14311441
Ok(())

src/libstd/io/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
//! to read the line and print it, so we use `()`.
237237
//!
238238
//! [result]: type.Result.html
239-
//! [try]: ../macro.try!.html
239+
//! [try]: ../macro.try.html
240240
//!
241241
//! ## Platform-specific behavior
242242
//!
@@ -957,8 +957,8 @@ pub trait Write {
957957
/// explicitly be called. The [`write!`][write] macro should be favored to
958958
/// invoke this method instead.
959959
///
960-
/// [formatargs]: ../macro.format_args!.html
961-
/// [write]: ../macro.write!.html
960+
/// [formatargs]: ../macro.format_args.html
961+
/// [write]: ../macro.write.html
962962
///
963963
/// This function internally uses the [`write_all`][writeall] method on
964964
/// this trait and hence will continuously write data so long as no errors

src/libstd/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
//! [`atomic`]: sync/atomic/index.html
176176
//! [`collections`]: collections/index.html
177177
//! [`for`]: ../book/loops.html#for
178-
//! [`format!`]: macro.format!.html
178+
//! [`format!`]: macro.format.html
179179
//! [`fs`]: fs/index.html
180180
//! [`io`]: io/index.html
181181
//! [`iter`]: iter/index.html

src/libstd/primitive_docs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/// assert!(!bool_val);
2828
/// ```
2929
///
30-
/// [`assert!`]: macro.assert!.html
30+
/// [`assert!`]: macro.assert.html
3131
/// [`if`]: ../book/if.html
3232
/// [`BitAnd`]: ops/trait.BitAnd.html
3333
/// [`BitOr`]: ops/trait.BitOr.html

src/test/rustdoc/issue-26606.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// ignore-cross-compile
1313
// build-aux-docs
1414

15-
// @has issue_26606_macro/macro.make_item!.html
15+
// @has issue_26606_macro/macro.make_item.html
1616
#[macro_use]
1717
extern crate issue_26606_macro;
1818

src/test/rustdoc/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// @has macros/macro.my_macro!.html //pre 'macro_rules! my_macro {'
11+
// @has macros/macro.my_macro.html //pre 'macro_rules! my_macro {'
1212
// @has - //pre '() => { ... };'
1313
// @has - //pre '($a:tt) => { ... };'
1414
// @has - //pre '($e:expr) => { ... };'
15+
// @has macros/macro.my_macro!.html
16+
// @has - //a 'macro.my_macro.html'
1517
#[macro_export]
1618
macro_rules! my_macro {
1719
() => [];

src/tools/linkchecker/Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)