]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/source/doc-attrib.rs
Rollup merge of #107166 - petrochenkov:nooptable, r=oli-obk
[rust.git] / src / tools / rustfmt / tests / source / doc-attrib.rs
1 // rustfmt-wrap_comments: true
2 // rustfmt-normalize_doc_attributes: true
3
4 // Only doc = "" attributes should be normalized
5 #![doc = " Example doc attribute comment"]
6 #![doc = "          Example doc attribute comment with 10 leading spaces"]
7 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
8        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
9        html_root_url = "https://doc.rust-lang.org/nightly/",
10        html_playground_url = "https://play.rust-lang.org/", test(attr(deny(warnings))))]
11
12
13 // Long `#[doc = "..."]`
14 struct A { #[doc = " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] b: i32 }
15
16
17 #[doc = " The `nodes` and `edges` method each return instantiations of `Cow<[T]>` to leave implementers the freedom to create entirely new vectors or to pass back slices into internally owned vectors."]
18 struct B { b: i32 }
19
20
21 #[doc = " Level 1 comment"]
22 mod tests {
23     #[doc = " Level 2 comment"]
24     impl A {
25         #[doc = " Level 3 comment"]
26         fn f() {
27             #[doc = " Level 4 comment"]
28             fn g() {
29             }
30         }
31     }
32 }
33
34 struct C {
35     #[doc = " item doc attrib comment"]
36     // regular item comment
37     b: i32,
38
39     // regular item comment
40     #[doc = " item doc attrib comment"]
41     c: i32,
42 }
43
44 // non-regression test for regular attributes, from #2647
45 #[cfg(feature = "this_line_is_101_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")]
46 pub fn foo() {}
47
48 // path attrs
49 #[clippy::bar]
50 #[clippy::bar(a, b, c)]
51 pub fn foo() {}
52
53 mod issue_2620 {
54     #[derive(Debug, StructOpt)]
55 #[structopt(about = "Display information about the character on FF Logs")]
56 pub struct Params {
57   #[structopt(help = "The server the character is on")]
58   server: String,
59   #[structopt(help = "The character's first name")]
60   first_name: String,
61   #[structopt(help = "The character's last name")]
62   last_name: String,
63   #[structopt(
64     short = "j",
65     long = "job",
66     help = "The job to look at",
67     parse(try_from_str)
68   )]
69   job: Option<Job>
70 }
71 }
72
73 // non-regression test for regular attributes, from #2969
74 #[cfg(not(all(feature="std",
75               any(target_os = "linux", target_os = "android",
76                   target_os = "netbsd",
77                   target_os = "dragonfly",
78                   target_os = "haiku",
79                   target_os = "emscripten",
80                   target_os = "solaris",
81                   target_os = "cloudabi",
82                   target_os = "macos", target_os = "ios",
83                   target_os = "freebsd",
84                   target_os = "openbsd",
85                   target_os = "redox",
86                   target_os = "fuchsia",
87                   windows,
88                   all(target_arch = "wasm32", feature = "stdweb"),
89                   all(target_arch = "wasm32", feature = "wasm-bindgen"),
90               ))))]
91 type Os = NoSource;
92
93 // use cases from bindgen needing precise control over leading spaces
94 #[doc = " <div rustbindgen accessor></div>"]
95 #[repr(C)]
96 #[derive(Debug, Default, Copy, Clone)]
97 pub struct ContradictAccessors {
98     #[doc = "<foo>no leading spaces here</foo>"]
99     pub mBothAccessors: ::std::os::raw::c_int,
100     #[doc = " <div rustbindgen accessor=\"false\"></div>"]
101     pub mNoAccessors: ::std::os::raw::c_int,
102     #[doc = " <div rustbindgen accessor=\"unsafe\"></div>"]
103     pub mUnsafeAccessors: ::std::os::raw::c_int,
104     #[doc = " <div rustbindgen accessor=\"immutable\"></div>"]
105     pub mImmutableAccessor: ::std::os::raw::c_int,
106 }
107
108 #[doc = " \\brief          MPI structure"]
109 #[repr(C)]
110 #[derive(Debug, Copy, Clone)]
111 pub struct mbedtls_mpi {
112     #[doc = "<  integer sign"]
113     pub s: ::std::os::raw::c_int,
114     #[doc = "<  total # of limbs"]
115     pub n: ::std::os::raw::c_ulong,
116     #[doc = "<  pointer to limbs"]
117     pub p: *mut mbedtls_mpi_uint,
118 }