Skip to content

Commit a0bf3c9

Browse files
Ignore std doctests if not run on the right OS
1 parent 4bf4659 commit a0bf3c9

9 files changed

Lines changed: 107 additions & 54 deletions

File tree

library/std/src/os/wasi/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
//!
1212
//! # Examples
1313
//!
14-
//! ```no_run
14+
#![cfg_attr(target_os = "wasi", doc = "```no_run")]
15+
#![cfg_attr(not(target_os = "wasi"), doc = "```ignore (needs wasi)")]
1516
//! use std::fs::File;
1617
//! use std::os::wasi::prelude::*;
1718
//!

library/std/src/os/windows/ffi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ pub impl(self) trait OsStringExt {
7272
///
7373
/// # Examples
7474
///
75-
/// ```
75+
#[cfg_attr(windows, doc = "```no_run")]
76+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
7677
/// use std::ffi::OsString;
7778
/// use std::os::windows::prelude::*;
7879
///
@@ -104,7 +105,8 @@ pub impl(self) trait OsStrExt {
104105
///
105106
/// # Examples
106107
///
107-
/// ```
108+
#[cfg_attr(windows, doc = "```no_run")]
109+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
108110
/// use std::ffi::OsString;
109111
/// use std::os::windows::prelude::*;
110112
///

library/std/src/os/windows/fs.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ pub trait FileExt {
3131
///
3232
/// # Examples
3333
///
34-
/// ```no_run
34+
#[cfg_attr(windows, doc = "```no_run")]
35+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
3536
/// use std::io;
3637
/// use std::fs::File;
3738
/// use std::os::windows::prelude::*;
@@ -59,7 +60,8 @@ pub trait FileExt {
5960
///
6061
/// # Examples
6162
///
62-
/// ```no_run
63+
#[cfg_attr(windows, doc = "```no_run")]
64+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
6365
/// #![feature(core_io_borrowed_buf)]
6466
/// #![feature(read_buf_at)]
6567
///
@@ -104,7 +106,8 @@ pub trait FileExt {
104106
///
105107
/// # Examples
106108
///
107-
/// ```no_run
109+
#[cfg_attr(windows, doc = "```no_run")]
110+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
108111
/// use std::fs::File;
109112
/// use std::os::windows::prelude::*;
110113
///
@@ -151,7 +154,8 @@ pub trait OpenOptionsExt {
151154
///
152155
/// # Examples
153156
///
154-
/// ```no_run
157+
#[cfg_attr(windows, doc = "```no_run")]
158+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
155159
/// use std::fs::OpenOptions;
156160
/// use std::os::windows::prelude::*;
157161
///
@@ -176,7 +180,8 @@ pub trait OpenOptionsExt {
176180
///
177181
/// # Examples
178182
///
179-
/// ```no_run
183+
#[cfg_attr(windows, doc = "```no_run")]
184+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
180185
/// use std::fs::OpenOptions;
181186
/// use std::os::windows::prelude::*;
182187
///
@@ -202,7 +207,8 @@ pub trait OpenOptionsExt {
202207
///
203208
/// # Examples
204209
///
205-
/// ```no_run
210+
#[cfg_attr(windows, doc = "```no_run")]
211+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
206212
/// # #![allow(unexpected_cfgs)]
207213
/// # #[cfg(for_demonstration_only)]
208214
/// extern crate winapi;
@@ -240,7 +246,8 @@ pub trait OpenOptionsExt {
240246
///
241247
/// # Examples
242248
///
243-
/// ```no_run
249+
#[cfg_attr(windows, doc = "```no_run")]
250+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
244251
/// # #![allow(unexpected_cfgs)]
245252
/// # #[cfg(for_demonstration_only)]
246253
/// extern crate winapi;
@@ -282,7 +289,8 @@ pub trait OpenOptionsExt {
282289
283290
/// # Examples
284291
///
285-
/// ```no_run
292+
#[cfg_attr(windows, doc = "```no_run")]
293+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
286294
/// # #![allow(unexpected_cfgs)]
287295
/// # #[cfg(for_demonstration_only)]
288296
/// extern crate winapi;
@@ -377,7 +385,8 @@ impl OpenOptionsExt2 for OpenOptions {
377385
///
378386
/// # Example
379387
///
380-
/// ```no_run
388+
#[cfg_attr(windows, doc = "```no_run")]
389+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
381390
/// #![feature(windows_permissions_ext)]
382391
/// use std::fs::Permissions;
383392
/// use std::os::windows::fs::PermissionsExt;
@@ -440,7 +449,8 @@ pub trait MetadataExt {
440449
///
441450
/// # Examples
442451
///
443-
/// ```no_run
452+
#[cfg_attr(windows, doc = "```no_run")]
453+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
444454
/// use std::io;
445455
/// use std::fs;
446456
/// use std::os::windows::prelude::*;
@@ -470,7 +480,8 @@ pub trait MetadataExt {
470480
///
471481
/// # Examples
472482
///
473-
/// ```no_run
483+
#[cfg_attr(windows, doc = "```no_run")]
484+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
474485
/// use std::io;
475486
/// use std::fs;
476487
/// use std::os::windows::prelude::*;
@@ -505,7 +516,8 @@ pub trait MetadataExt {
505516
///
506517
/// # Examples
507518
///
508-
/// ```no_run
519+
#[cfg_attr(windows, doc = "```no_run")]
520+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
509521
/// use std::io;
510522
/// use std::fs;
511523
/// use std::os::windows::prelude::*;
@@ -538,7 +550,8 @@ pub trait MetadataExt {
538550
///
539551
/// # Examples
540552
///
541-
/// ```no_run
553+
#[cfg_attr(windows, doc = "```no_run")]
554+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
542555
/// use std::io;
543556
/// use std::fs;
544557
/// use std::os::windows::prelude::*;
@@ -561,7 +574,8 @@ pub trait MetadataExt {
561574
///
562575
/// # Examples
563576
///
564-
/// ```no_run
577+
#[cfg_attr(windows, doc = "```no_run")]
578+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
565579
/// use std::io;
566580
/// use std::fs;
567581
/// use std::os::windows::prelude::*;
@@ -700,7 +714,8 @@ impl FileTimesExt for fs::FileTimes {
700714
///
701715
/// # Examples
702716
///
703-
/// ```no_run
717+
#[cfg_attr(windows, doc = "```no_run")]
718+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
704719
/// use std::os::windows::fs;
705720
///
706721
/// fn main() -> std::io::Result<()> {
@@ -739,7 +754,8 @@ pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io:
739754
///
740755
/// # Examples
741756
///
742-
/// ```no_run
757+
#[cfg_attr(windows, doc = "```no_run")]
758+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
743759
/// use std::os::windows::fs;
744760
///
745761
/// fn main() -> std::io::Result<()> {

library/std/src/os/windows/io/handle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ pub trait AsHandle {
424424
///
425425
/// # Example
426426
///
427-
/// ```rust,no_run
427+
#[cfg_attr(windows, doc = "```no_run")]
428+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
428429
/// use std::fs::File;
429430
/// # use std::io;
430431
/// use std::os::windows::io::{AsHandle, BorrowedHandle};

library/std/src/os/windows/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
//!
99
//! # Examples
1010
//!
11-
//! ```no_run
11+
#![cfg_attr(windows, doc = "```no_run")]
12+
#![cfg_attr(not(windows), doc = "```ignore (needs windows)")]
1213
//! use std::fs::File;
1314
//! use std::os::windows::prelude::*;
1415
//!

library/std/src/os/windows/net/addr.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ impl SocketAddr {
7979
///
8080
/// With a pathname:
8181
///
82-
/// ```no_run
82+
#[cfg_attr(windows, doc = "```no_run")]
83+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
8384
/// #![feature(windows_unix_domain_sockets)]
8485
/// use std::os::windows::net::UnixListener;
8586
/// use std::path::Path;
@@ -104,7 +105,8 @@ impl SocketAddr {
104105
///
105106
/// # Examples
106107
///
107-
/// ```no_run
108+
#[cfg_attr(windows, doc = "```no_run")]
109+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
108110
/// #![feature(windows_unix_domain_sockets)]
109111
/// use std::os::windows::net::SocketAddr;
110112
/// use std::path::Path;
@@ -118,7 +120,8 @@ impl SocketAddr {
118120
///
119121
/// Creating a `SocketAddr` with a NULL byte results in an error.
120122
///
121-
/// ```no_run
123+
#[cfg_attr(windows, doc = "```no_run")]
124+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
122125
/// #![feature(windows_unix_domain_sockets)]
123126
/// use std::os::windows::net::SocketAddr;
124127
///
@@ -151,7 +154,8 @@ impl SocketAddr {
151154
///
152155
/// A named address:
153156
///
154-
/// ```no_run
157+
#[cfg_attr(windows, doc = "```no_run")]
158+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
155159
/// #![feature(windows_unix_domain_sockets)]
156160
/// use std::os::windows::net::UnixListener;
157161
///

library/std/src/os/windows/net/listener.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::{fmt, io};
1616
///
1717
/// # Examples
1818
///
19-
/// ```no_run
19+
#[cfg_attr(windows, doc = "```no_run")]
20+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
2021
/// #![feature(windows_unix_domain_sockets)]
2122
/// use std::thread;
2223
/// use std::os::windows::net::{UnixStream, UnixListener};
@@ -61,7 +62,8 @@ impl UnixListener {
6162
///
6263
/// # Examples
6364
///
64-
/// ```no_run
65+
#[cfg_attr(windows, doc = "```no_run")]
66+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
6567
/// #![feature(windows_unix_domain_sockets)]
6668
/// use std::os::windows::net::UnixListener;
6769
///
@@ -84,7 +86,8 @@ impl UnixListener {
8486
///
8587
/// # Examples
8688
///
87-
/// ```no_run
89+
#[cfg_attr(windows, doc = "```no_run")]
90+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
8891
/// #![feature(windows_unix_domain_sockets)]
8992
/// use std::os::windows::net::{UnixListener};
9093
///
@@ -122,7 +125,8 @@ impl UnixListener {
122125
///
123126
/// # Examples
124127
///
125-
/// ```no_run
128+
#[cfg_attr(windows, doc = "```no_run")]
129+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
126130
/// #![feature(windows_unix_domain_sockets)]
127131
/// use std::os::windows::net::UnixListener;
128132
///
@@ -148,7 +152,8 @@ impl UnixListener {
148152
///
149153
/// # Examples
150154
///
151-
/// ```no_run
155+
#[cfg_attr(windows, doc = "```no_run")]
156+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
152157
/// #![feature(windows_unix_domain_sockets)]
153158
/// use std::os::windows::net::UnixListener;
154159
///
@@ -170,7 +175,8 @@ impl UnixListener {
170175
///
171176
/// # Examples
172177
///
173-
/// ```no_run
178+
#[cfg_attr(windows, doc = "```no_run")]
179+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
174180
/// #![feature(windows_unix_domain_sockets)]
175181
/// use std::os::windows::net::UnixListener;
176182
///
@@ -194,7 +200,8 @@ impl UnixListener {
194200
///
195201
/// # Examples
196202
///
197-
/// ```no_run
203+
#[cfg_attr(windows, doc = "```no_run")]
204+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
198205
/// #![feature(windows_unix_domain_sockets)]
199206
/// use std::os::windows::net::UnixListener;
200207
///
@@ -212,7 +219,8 @@ impl UnixListener {
212219
///
213220
/// # Examples
214221
///
215-
/// ```no_run
222+
#[cfg_attr(windows, doc = "```no_run")]
223+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
216224
/// #![feature(windows_unix_domain_sockets)]
217225
/// use std::os::windows::net::UnixListener;
218226
///
@@ -236,7 +244,8 @@ impl UnixListener {
236244
///
237245
/// # Examples
238246
///
239-
/// ```no_run
247+
#[cfg_attr(windows, doc = "```no_run")]
248+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
240249
/// #![feature(windows_unix_domain_sockets)]
241250
/// use std::thread;
242251
/// use std::os::windows::net::{UnixStream, UnixListener};
@@ -272,7 +281,8 @@ impl UnixListener {
272281
///
273282
/// # Examples
274283
///
275-
/// ```no_run
284+
#[cfg_attr(windows, doc = "```no_run")]
285+
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]
276286
/// #![feature(windows_unix_domain_sockets)]
277287
/// use std::thread;
278288
/// use std::os::windows::net::{UnixStream, UnixListener};

0 commit comments

Comments
 (0)