Skip to content

Commit 5752d8b

Browse files
committed
Auto merge of #42777 - kennytm:kill-ignore-doctest, r=<try>
Remove most "```ignore" doc tests. Unconditional ` ```ignore ` doc tests lead to outdated examples (e.g. #42729 (comment)). This PR tries to change all existing ` ```ignore ` tests into one of the following: * Add import and declarations to ensure the code is run-pass * If the code is not Rust, change to ` ```text `/` ```sh `/` ```json `/` ```dot ` * If the code is expected compile-fail, change to ` ```compile_fail ` * If the code is expected run-fail, change to ` ```should_panic ` * If the code can type-check but cannot link/run, change to ` ```no_run ` * Otherwise, add an explanation after the ` ```ignore ` The `--explain` handling is changed to cope with hidden lines from the error index. Tidy is changed to reject any unexplained ` ```ignore ` and ` ```rust,ignore `.
2 parents ab5bec2 + 513b962 commit 5752d8b

File tree

49 files changed

+552
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+552
-235
lines changed

src/liballoc/boxed.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
//! Recursive structures must be boxed, because if the definition of `Cons`
4343
//! looked like this:
4444
//!
45-
//! ```rust,ignore
45+
//! ```compile_fail,E0072
46+
//! # enum List<T> {
4647
//! Cons(T, List<T>),
48+
//! # }
4749
//! ```
4850
//!
4951
//! It wouldn't work. This is because the size of a `List` depends on how many

src/liballoc/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
//! There are a number of related macros in the `format!` family. The ones that
231231
//! are currently implemented are:
232232
//!
233-
//! ```ignore
233+
//! ```ignore (only-for-syntax-highlight)
234234
//! format! // described above
235235
//! write! // first argument is a &mut io::Write, the destination
236236
//! writeln! // same as write but appends a newline

src/liballoc/raw_vec.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ impl<T, A: Alloc> RawVec<T, A> {
244244
///
245245
/// # Examples
246246
///
247-
/// ```ignore
247+
/// ```
248+
/// # #![feature(alloc)]
249+
/// # extern crate alloc;
250+
/// # use std::ptr;
251+
/// # use alloc::raw_vec::RawVec;
248252
/// struct MyVec<T> {
249253
/// buf: RawVec<T>,
250254
/// len: usize,
@@ -261,6 +265,10 @@ impl<T, A: Alloc> RawVec<T, A> {
261265
/// self.len += 1;
262266
/// }
263267
/// }
268+
/// # fn main() {
269+
/// # let mut vec = MyVec { buf: RawVec::new(), len: 0 };
270+
/// # vec.push(1);
271+
/// # }
264272
/// ```
265273
#[inline(never)]
266274
#[cold]
@@ -440,13 +448,17 @@ impl<T, A: Alloc> RawVec<T, A> {
440448
///
441449
/// # Examples
442450
///
443-
/// ```ignore
451+
/// ```
452+
/// # #![feature(alloc)]
453+
/// # extern crate alloc;
454+
/// # use std::ptr;
455+
/// # use alloc::raw_vec::RawVec;
444456
/// struct MyVec<T> {
445457
/// buf: RawVec<T>,
446458
/// len: usize,
447459
/// }
448460
///
449-
/// impl<T> MyVec<T> {
461+
/// impl<T: Clone> MyVec<T> {
450462
/// pub fn push_all(&mut self, elems: &[T]) {
451463
/// self.buf.reserve(self.len, elems.len());
452464
/// // reserve would have aborted or panicked if the len exceeded
@@ -459,6 +471,10 @@ impl<T, A: Alloc> RawVec<T, A> {
459471
/// }
460472
/// }
461473
/// }
474+
/// # fn main() {
475+
/// # let mut vector = MyVec { buf: RawVec::new(), len: 0 };
476+
/// # vector.push_all(&[1, 3, 5, 7, 9]);
477+
/// # }
462478
/// ```
463479
pub fn reserve(&mut self, used_cap: usize, needed_extra_cap: usize) {
464480
unsafe {

src/liballoc/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ use boxed::Box;
124124
/// similar, but without the UTF-8 constraint. The second implication is that
125125
/// you cannot index into a `String`:
126126
///
127-
/// ```ignore
127+
/// ```compile_fail,E0277
128128
/// let s = "hello";
129129
///
130130
/// println!("The first letter of s is {}", s[0]); // ERROR!!!

src/liballoc/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ use Bound::{Excluded, Included, Unbounded};
156156
/// However be careful: if you try to access an index which isn't in the `Vec`,
157157
/// your software will panic! You cannot do this:
158158
///
159-
/// ```ignore
159+
/// ```should_panic
160160
/// let v = vec![0, 2, 4, 6];
161161
/// println!("{}", v[6]); // it will panic!
162162
/// ```

src/libcore/iter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
//! There's one more subtle bit here: the standard library contains an
212212
//! interesting implementation of [`IntoIterator`]:
213213
//!
214-
//! ```ignore
214+
//! ```ignore (only-for-syntax-highlight)
215215
//! impl<I: Iterator> IntoIterator for I
216216
//! ```
217217
//!

src/libcore/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ macro_rules! impls{
434434
/// example, here is a struct `Slice` that has two pointers of type `*const T`,
435435
/// presumably pointing into an array somewhere:
436436
///
437-
/// ```ignore
437+
/// ```compile_fail,E0392
438438
/// struct Slice<'a, T> {
439439
/// start: *const T,
440440
/// end: *const T,

src/libcore/mem.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,18 @@ pub fn align_of_val<T: ?Sized>(val: &T) -> usize {
328328
///
329329
/// Here's an example of how a collection might make use of needs_drop:
330330
///
331-
/// ```ignore
331+
/// ```
332332
/// #![feature(needs_drop)]
333333
/// use std::{mem, ptr};
334334
///
335-
/// pub struct MyCollection<T> { /* ... */ }
335+
/// pub struct MyCollection<T> {
336+
/// # data: [T; 1],
337+
/// /* ... */
338+
/// }
339+
/// # impl<T> MyCollection<T> {
340+
/// # fn iter_mut(&mut self) -> &mut [T] { &mut self.data }
341+
/// # fn free_buffer(&mut self) {}
342+
/// # }
336343
///
337344
/// impl<T> Drop for MyCollection<T> {
338345
/// fn drop(&mut self) {
@@ -575,7 +582,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
575582
/// `replace` allows consumption of a struct field by replacing it with another value.
576583
/// Without `replace` you can run into issues like these:
577584
///
578-
/// ```ignore
585+
/// ```compile_fail,E0507
579586
/// struct Buffer<T> { buf: Vec<T> }
580587
///
581588
/// impl<T> Buffer<T> {
@@ -645,7 +652,7 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
645652
///
646653
/// Borrows are based on lexical scope, so this produces an error:
647654
///
648-
/// ```ignore
655+
/// ```compile_fail,E0502
649656
/// let mut v = vec![1, 2, 3];
650657
/// let x = &v[0];
651658
///

src/libcore/ops/place.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ pub trait Place<Data: ?Sized> {
3838
///
3939
/// `PLACE <- EXPR` effectively desugars into:
4040
///
41-
/// ```rust,ignore
41+
/// ```
42+
/// # #![feature(placement_new_protocol, box_heap)]
43+
/// # use std::ops::{Placer, Place, InPlace};
44+
/// # #[allow(non_snake_case)]
45+
/// # fn main() {
46+
/// # let PLACE = std::boxed::HEAP;
47+
/// # let EXPR = 1;
4248
/// let p = PLACE;
4349
/// let mut place = Placer::make_place(p);
4450
/// let raw_place = Place::pointer(&mut place);
@@ -47,6 +53,7 @@ pub trait Place<Data: ?Sized> {
4753
/// std::ptr::write(raw_place, value);
4854
/// InPlace::finalize(place)
4955
/// }
56+
/// # ; }
5057
/// ```
5158
///
5259
/// The type of `PLACE <- EXPR` is derived from the type of `PLACE`;
@@ -89,14 +96,21 @@ pub trait InPlace<Data: ?Sized>: Place<Data> {
8996
///
9097
/// `box EXPR` effectively desugars into:
9198
///
92-
/// ```rust,ignore
99+
/// ```
100+
/// # #![feature(placement_new_protocol)]
101+
/// # use std::ops::{BoxPlace, Place, Boxed};
102+
/// # #[allow(non_snake_case)]
103+
/// # fn main() {
104+
/// # let EXPR = 1;
93105
/// let mut place = BoxPlace::make_place();
94106
/// let raw_place = Place::pointer(&mut place);
95107
/// let value = EXPR;
108+
/// # let _: Box<_> =
96109
/// unsafe {
97110
/// ::std::ptr::write(raw_place, value);
98111
/// Boxed::finalize(place)
99112
/// }
113+
/// # ; }
100114
/// ```
101115
///
102116
/// The type of `box EXPR` is supplied from its surrounding

src/libcore/ops/range.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use fmt;
2626
/// It does not have an `IntoIterator` implementation, so you can't use it in a
2727
/// `for` loop directly. This won't compile:
2828
///
29-
/// ```ignore
29+
/// ```compile_fail,E0277
3030
/// for i in .. {
3131
/// // ...
3232
/// }
@@ -184,7 +184,7 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
184184
/// It does not have an `IntoIterator` implementation, so you can't use it in a
185185
/// `for` loop directly. This won't compile:
186186
///
187-
/// ```ignore
187+
/// ```compile_fail,E0277
188188
/// for i in ..5 {
189189
/// // ...
190190
/// }
@@ -313,7 +313,8 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
313313
/// It does not have an `IntoIterator` implementation, so you can't use it in a
314314
/// `for` loop directly. This won't compile:
315315
///
316-
/// ```ignore
316+
/// ```compile_fail,E0277
317+
/// #![feature(inclusive_range_syntax)]
317318
/// for i in ...5 {
318319
/// // ...
319320
/// }

src/libcore/panicking.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
//! useful an upstream crate must define panicking for libcore to use. The current
1616
//! interface for panicking is:
1717
//!
18-
//! ```ignore
19-
//! fn panic_impl(fmt: fmt::Arguments, &(&'static str, u32)) -> !;
18+
//! ```
19+
//! # use std::fmt;
20+
//! fn panic_impl(fmt: fmt::Arguments, file_line: &(&'static str, u32)) -> !
21+
//! # { loop {} }
2022
//! ```
2123
//!
2224
//! This definition allows for panicking with any general message, but it does not

src/libcore/ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ impl<T: ?Sized> *const T {
408408
///
409409
/// Basic usage:
410410
///
411-
/// ```ignore
412-
/// let val: *const u8 = &10u8 as *const u8;
411+
/// ```
412+
/// let ptr: *const u8 = &10u8 as *const u8;
413413
///
414414
/// unsafe {
415-
/// if let Some(val_back) = val.as_ref() {
415+
/// if let Some(val_back) = ptr.as_ref() {
416416
/// println!("We got back the value: {}!", val_back);
417417
/// }
418418
/// }
@@ -570,11 +570,11 @@ impl<T: ?Sized> *mut T {
570570
///
571571
/// Basic usage:
572572
///
573-
/// ```ignore
574-
/// let val: *mut u8 = &mut 10u8 as *mut u8;
573+
/// ```
574+
/// let ptr: *mut u8 = &mut 10u8 as *mut u8;
575575
///
576576
/// unsafe {
577-
/// if let Some(val_back) = val.as_ref() {
577+
/// if let Some(val_back) = ptr.as_ref() {
578578
/// println!("We got back the value: {}!", val_back);
579579
/// }
580580
/// }

src/libgraphviz/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
//!
112112
//! Output from first example (in `example1.dot`):
113113
//!
114-
//! ```ignore
114+
//! ```dot
115115
//! digraph example1 {
116116
//! N0[label="N0"];
117117
//! N1[label="N1"];

0 commit comments

Comments
 (0)