Skip to content

Commit 543ef7f

Browse files
authored
Rollup merge of #82593 - sunfishcode:wasi-docs, r=alexcrichton
Teach rustdoc how to display WASI. As a followup to [this comment] in #82420, this patch teaches rustdoc how to display WASI. [this comment]: #82420 (comment) r? `@alexcrichton`
2 parents 906e535 + e27eba3 commit 543ef7f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/librustdoc/clean/cfg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ impl<'a> fmt::Display for Display<'a> {
483483
"openbsd" => "OpenBSD",
484484
"redox" => "Redox",
485485
"solaris" => "Solaris",
486+
"wasi" => "WASI",
486487
"windows" => "Windows",
487488
_ => "",
488489
},

src/librustdoc/clean/cfg/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ fn test_render_long_html() {
367367
name_value_cfg("target_os", "macos").render_long_html(),
368368
"This is supported on <strong>macOS</strong> only."
369369
);
370+
assert_eq!(
371+
name_value_cfg("target_os", "wasi").render_long_html(),
372+
"This is supported on <strong>WASI</strong> only."
373+
);
370374
assert_eq!(
371375
name_value_cfg("target_pointer_width", "16").render_long_html(),
372376
"This is supported on <strong>16-bit</strong> only."

src/test/rustdoc/doc-cfg.rs

+32
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// @!has - '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' ''
66
// @has - '//*[@id="method.unix_and_arm_only_function"]' 'fn unix_and_arm_only_function()'
77
// @has - '//*[@class="stab portability"]' 'This is supported on Unix and ARM only.'
8+
// @has - '//*[@id="method.wasi_and_wasm32_only_function"]' 'fn wasi_and_wasm32_only_function()'
9+
// @has - '//*[@class="stab portability"]' 'This is supported on WASI and WebAssembly only.'
810
pub struct Portable;
911

1012
// @has doc_cfg/unix_only/index.html \
@@ -37,6 +39,36 @@ pub mod unix_only {
3739
}
3840
}
3941

42+
// @has doc_cfg/wasi_only/index.html \
43+
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
44+
// 'This is supported on WASI only.'
45+
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AWebAssembly\Z'
46+
// @count - '//*[@class="stab portability"]' 2
47+
#[doc(cfg(target_os = "wasi"))]
48+
pub mod wasi_only {
49+
// @has doc_cfg/wasi_only/fn.wasi_only_function.html \
50+
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
51+
// 'This is supported on WASI only.'
52+
// @count - '//*[@class="stab portability"]' 1
53+
pub fn wasi_only_function() {
54+
content::should::be::irrelevant();
55+
}
56+
57+
// @has doc_cfg/wasi_only/trait.Wasm32Only.html \
58+
// '//*[@id="main"]/*[@class="item-info"]/*[@class="stab portability"]' \
59+
// 'This is supported on WASI and WebAssembly only.'
60+
// @count - '//*[@class="stab portability"]' 1
61+
#[doc(cfg(target_arch = "wasm32"))]
62+
pub trait Wasm32Only {
63+
fn wasi_and_wasm32_only_function();
64+
}
65+
66+
#[doc(cfg(target_arch = "wasm32"))]
67+
impl Wasm32Only for super::Portable {
68+
fn wasi_and_wasm32_only_function() {}
69+
}
70+
}
71+
4072
// tagging a function with `#[target_feature]` creates a doc(cfg(target_feature)) node for that
4173
// item as well
4274

0 commit comments

Comments
 (0)