Skip to content

Commit ec356bb

Browse files
author
Alex Burka
committed
rustdoc: fix doctests with non-feature crate attrs
1 parent 28d6623 commit ec356bb

File tree

5 files changed

+117
-6
lines changed

5 files changed

+117
-6
lines changed

src/doc/book/documentation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ is documented, especially when you are working on a library. Rust allows you to
600600
to generate warnings or errors, when an item is missing documentation.
601601
To generate warnings you use `warn`:
602602

603-
```rust
603+
```rust,ignore
604604
#![warn(missing_docs)]
605605
```
606606

@@ -630,7 +630,7 @@ struct Hidden;
630630
You can control a few aspects of the HTML that `rustdoc` generates through the
631631
`#![doc]` version of the attribute:
632632

633-
```rust
633+
```rust,ignore
634634
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
635635
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
636636
html_root_url = "https://doc.rust-lang.org/")]

src/doc/book/using-rust-without-the-standard-library.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ don’t want to use the standard library via an attribute: `#![no_std]`.
1313
1414
To use `#![no_std]`, add it to your crate root:
1515

16-
```rust
16+
```rust,ignore
1717
#![no_std]
1818
1919
fn plus_one(x: i32) -> i32 {
@@ -29,7 +29,7 @@ use its features without an explicit import. By the same token, when using
2929
prelude](../core/prelude/v1/index.html). This means that a lot of code will Just
3030
Work:
3131

32-
```rust
32+
```rust,ignore
3333
#![no_std]
3434
3535
fn may_fail(failure: bool) -> Result<(), &'static str> {

src/librustc/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ them yourself.
557557
You can build a free-standing crate by adding `#![no_std]` to the crate
558558
attributes:
559559
560-
```
560+
```ignore
561561
#![no_std]
562562
```
563563

src/librustdoc/test.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ pub fn maketest(s: &str, cratename: Option<&str>, dont_insert_main: bool,
344344
prog
345345
}
346346

347+
// FIXME(aburka): use a real parser to deal with multiline attributes
347348
fn partition_source(s: &str) -> (String, String) {
348349
use rustc_unicode::str::UnicodeStr;
349350

@@ -354,7 +355,7 @@ fn partition_source(s: &str) -> (String, String) {
354355
for line in s.lines() {
355356
let trimline = line.trim();
356357
let header = trimline.is_whitespace() ||
357-
trimline.starts_with("#![feature");
358+
trimline.starts_with("#![");
358359
if !header || after_header {
359360
after_header = true;
360361
after.push_str(line);

src/test/rustdoc/issue-38129.rs

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:--test
12+
13+
// This file tests the source-partitioning behavior of rustdoc.
14+
// Each test contains some code that should be put into the generated
15+
// `fn main` and some attributes should be left outside (except the first
16+
// one, which has no attributes).
17+
// If the #![recursion_limit] attribute is incorrectly left inside,
18+
// then the tests will fail because the macro recurses 128 times.
19+
20+
/// ```
21+
/// assert_eq!(1 + 1, 2);
22+
/// ```
23+
pub fn simple() {}
24+
25+
/// ```
26+
/// #![recursion_limit = "1024"]
27+
/// macro_rules! recurse {
28+
/// (()) => {};
29+
/// (() $($rest:tt)*) => { recurse!($($rest)*); }
30+
/// }
31+
/// recurse!(() () () () () () () ()
32+
/// () () () () () () () ()
33+
/// () () () () () () () ()
34+
/// () () () () () () () ()
35+
/// () () () () () () () ()
36+
/// () () () () () () () ()
37+
/// () () () () () () () ()
38+
/// () () () () () () () ()
39+
/// () () () () () () () ()
40+
/// () () () () () () () ()
41+
/// () () () () () () () ()
42+
/// () () () () () () () ()
43+
/// () () () () () () () ()
44+
/// () () () () () () () ()
45+
/// () () () () () () () ()
46+
/// () () () () () () () ());
47+
/// assert_eq!(1 + 1, 2);
48+
/// ```
49+
pub fn non_feature_attr() {}
50+
51+
/// ```
52+
/// #![feature(core_intrinsics)]
53+
/// assert_eq!(1 + 1, 2);
54+
/// ```
55+
pub fn feature_attr() {}
56+
57+
/// ```
58+
/// #![feature(core_intrinsics)]
59+
/// #![recursion_limit = "1024"]
60+
/// macro_rules! recurse {
61+
/// (()) => {};
62+
/// (() $($rest:tt)*) => { recurse!($($rest)*); }
63+
/// }
64+
/// recurse!(() () () () () () () ()
65+
/// () () () () () () () ()
66+
/// () () () () () () () ()
67+
/// () () () () () () () ()
68+
/// () () () () () () () ()
69+
/// () () () () () () () ()
70+
/// () () () () () () () ()
71+
/// () () () () () () () ()
72+
/// () () () () () () () ()
73+
/// () () () () () () () ()
74+
/// () () () () () () () ()
75+
/// () () () () () () () ()
76+
/// () () () () () () () ()
77+
/// () () () () () () () ()
78+
/// () () () () () () () ()
79+
/// () () () () () () () ());
80+
/// assert_eq!(1 + 1, 2);
81+
/// ```
82+
pub fn both_attrs() {}
83+
84+
/// ```
85+
/// #![recursion_limit = "1024"]
86+
/// #![feature(core_intrinsics)]
87+
/// macro_rules! recurse {
88+
/// (()) => {};
89+
/// (() $($rest:tt)*) => { recurse!($($rest)*); }
90+
/// }
91+
/// recurse!(() () () () () () () ()
92+
/// () () () () () () () ()
93+
/// () () () () () () () ()
94+
/// () () () () () () () ()
95+
/// () () () () () () () ()
96+
/// () () () () () () () ()
97+
/// () () () () () () () ()
98+
/// () () () () () () () ()
99+
/// () () () () () () () ()
100+
/// () () () () () () () ()
101+
/// () () () () () () () ()
102+
/// () () () () () () () ()
103+
/// () () () () () () () ()
104+
/// () () () () () () () ()
105+
/// () () () () () () () ()
106+
/// () () () () () () () ());
107+
/// assert_eq!(1 + 1, 2);
108+
/// ```
109+
pub fn both_attrs_reverse() {}
110+

0 commit comments

Comments
 (0)