]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/doc-cfg.rs
Rollup merge of #55563 - GuillaumeGomez:doc-search-sentence, r=QuietMisdreavus
[rust.git] / src / test / rustdoc / doc-cfg.rs
1 // Copyright 2017 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 #![feature(doc_cfg)]
12 #![feature(target_feature, cfg_target_feature)]
13
14 // @has doc_cfg/struct.Portable.html
15 // @!has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' ''
16 // @has - '//*[@id="method.unix_and_arm_only_function"]' 'fn unix_and_arm_only_function()'
17 // @has - '//*[@class="stab portability"]' 'This is supported on Unix and ARM only.'
18 pub struct Portable;
19
20 // @has doc_cfg/unix_only/index.html \
21 //  '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
22 //  'This is supported on Unix only.'
23 // @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AUnix\Z'
24 // @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AUnix and ARM\Z'
25 // @count - '//*[@class="stab portability"]' 3
26 #[doc(cfg(unix))]
27 pub mod unix_only {
28     // @has doc_cfg/unix_only/fn.unix_only_function.html \
29     //  '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
30     //  'This is supported on Unix only.'
31     // @count - '//*[@class="stab portability"]' 1
32     pub fn unix_only_function() {
33         content::should::be::irrelevant();
34     }
35
36     // @has doc_cfg/unix_only/trait.ArmOnly.html \
37     //  '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
38     //  'This is supported on Unix and ARM only.'
39     // @count - '//*[@class="stab portability"]' 3
40     #[doc(cfg(target_arch = "arm"))]
41     pub trait ArmOnly {
42         fn unix_and_arm_only_function();
43     }
44
45     impl ArmOnly for super::Portable {
46         fn unix_and_arm_only_function() {}
47     }
48 }
49
50 // tagging a function with `#[target_feature]` creates a doc(cfg(target_feature)) node for that
51 // item as well
52
53 // the portability header is different on the module view versus the full view
54 // @has doc_cfg/index.html
55 // @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\Aavx\Z'
56
57 // @has doc_cfg/fn.uses_target_feature.html
58 // @has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
59 //        'This is supported with target feature avx only.'
60 #[target_feature(enable = "avx")]
61 pub unsafe fn uses_target_feature() {
62     content::should::be::irrelevant();
63 }
64
65 // @has doc_cfg/fn.uses_cfg_target_feature.html
66 // @has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
67 //        'This is supported with target feature avx only.'
68 #[doc(cfg(target_feature = "avx"))]
69 pub fn uses_cfg_target_feature() {
70     uses_target_feature();
71 }