Skip to content

Commit b8b8247

Browse files
committed
Use rustfmt's normalize_doc_attributes, to mostly preserve behavior re. doc comments.
1 parent 45a5087 commit b8b8247

File tree

70 files changed

+872
-809
lines changed

Some content is hidden

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

70 files changed

+872
-809
lines changed

src/ir/comment.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ fn make_indent(indent: usize) -> String {
3838
iter::repeat(' ').take(indent * RUST_INDENTATION).collect()
3939
}
4040

41+
/// For a comment like `/// foo`, proc_macro2 will turn it into
42+
/// `#[doc = " foo"]`, and rustfmt into `/// foo`, so prevent this by removing
43+
/// the first space of the comment if present.
44+
///
45+
/// This is a bit hacky.
46+
fn format_line(line: &str) -> &str {
47+
if line.starts_with(" ") {
48+
&line[1..]
49+
} else {
50+
line
51+
}
52+
}
53+
4154
/// Preprocesses multiple single line comments.
4255
///
4356
/// Handles lines starting with both `//` and `///`.
@@ -52,7 +65,7 @@ fn preprocess_single_lines(comment: &str, indent: usize) -> String {
5265
.map(|l| {
5366
let indent = if is_first { "" } else { &*indent };
5467
is_first = false;
55-
format!("{}///{}", indent, l)
68+
format!("{}///{}", indent, format_line(l))
5669
})
5770
.collect();
5871
lines.join("\n")
@@ -73,7 +86,7 @@ fn preprocess_multi_line(comment: &str, indent: usize) -> String {
7386
.map(|line| {
7487
let indent = if is_first { "" } else { &*indent };
7588
is_first = false;
76-
format!("{}///{}", indent, line)
89+
format!("{}///{}", indent, format_line(line))
7790
})
7891
.collect();
7992

@@ -97,16 +110,16 @@ mod test {
97110

98111
#[test]
99112
fn processes_single_lines_correctly() {
100-
assert_eq!(preprocess("/// hello", 0), "/// hello");
101-
assert_eq!(preprocess("// hello", 0), "/// hello");
102-
assert_eq!(preprocess("// hello", 0), "/// hello");
113+
assert_eq!(preprocess("/// hello", 0), "///hello");
114+
assert_eq!(preprocess("// hello", 0), "///hello");
115+
assert_eq!(preprocess("// hello", 0), "/// hello");
103116
}
104117

105118
#[test]
106119
fn processes_multi_lines_correctly() {
107120
assert_eq!(
108121
preprocess("/** hello \n * world \n * foo \n */", 0),
109-
"/// hello\n/// world\n/// foo"
122+
"///hello\n///world\n///foo"
110123
);
111124

112125
assert_eq!(

tests/expectations/tests/accessors.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#[derive(Debug, Default, Copy, Clone)]
1212
pub struct SomeAccessors {
1313
pub mNoAccessor: ::std::os::raw::c_int,
14-
#[doc = " <div rustbindgen accessor></div>"]
14+
/// <div rustbindgen accessor></div>
1515
pub mBothAccessors: ::std::os::raw::c_int,
16-
#[doc = " <div rustbindgen accessor=\"unsafe\"></div>"]
16+
/// <div rustbindgen accessor="unsafe"></div>
1717
pub mUnsafeAccessors: ::std::os::raw::c_int,
18-
#[doc = " <div rustbindgen accessor=\"immutable\"></div>"]
18+
/// <div rustbindgen accessor="immutable"></div>
1919
pub mImmutableAccessor: ::std::os::raw::c_int,
2020
}
2121
#[test]
@@ -95,7 +95,7 @@ impl SomeAccessors {
9595
&self.mImmutableAccessor
9696
}
9797
}
98-
#[doc = " <div rustbindgen accessor></div>"]
98+
/// <div rustbindgen accessor></div>
9999
#[repr(C)]
100100
#[derive(Debug, Default, Copy, Clone)]
101101
pub struct AllAccessors {
@@ -153,7 +153,7 @@ impl AllAccessors {
153153
&mut self.mAlsoBothAccessors
154154
}
155155
}
156-
#[doc = " <div rustbindgen accessor=\"unsafe\"></div>"]
156+
/// <div rustbindgen accessor="unsafe"></div>
157157
#[repr(C)]
158158
#[derive(Debug, Default, Copy, Clone)]
159159
pub struct AllUnsafeAccessors {
@@ -215,16 +215,16 @@ impl AllUnsafeAccessors {
215215
&mut self.mAlsoBothAccessors
216216
}
217217
}
218-
#[doc = " <div rustbindgen accessor></div>"]
218+
/// <div rustbindgen accessor></div>
219219
#[repr(C)]
220220
#[derive(Debug, Default, Copy, Clone)]
221221
pub struct ContradictAccessors {
222222
pub mBothAccessors: ::std::os::raw::c_int,
223-
#[doc = " <div rustbindgen accessor=\"false\"></div>"]
223+
/// <div rustbindgen accessor="false"></div>
224224
pub mNoAccessors: ::std::os::raw::c_int,
225-
#[doc = " <div rustbindgen accessor=\"unsafe\"></div>"]
225+
/// <div rustbindgen accessor="unsafe"></div>
226226
pub mUnsafeAccessors: ::std::os::raw::c_int,
227-
#[doc = " <div rustbindgen accessor=\"immutable\"></div>"]
227+
/// <div rustbindgen accessor="immutable"></div>
228228
pub mImmutableAccessor: ::std::os::raw::c_int,
229229
}
230230
#[test]
@@ -310,7 +310,7 @@ impl ContradictAccessors {
310310
&self.mImmutableAccessor
311311
}
312312
}
313-
#[doc = " <div rustbindgen accessor replaces=\"Replaced\"></div>"]
313+
/// <div rustbindgen accessor replaces="Replaced"></div>
314314
#[repr(C)]
315315
#[derive(Debug, Default, Copy, Clone)]
316316
pub struct Replaced {
@@ -349,7 +349,7 @@ impl Replaced {
349349
&mut self.mAccessor
350350
}
351351
}
352-
#[doc = " <div rustbindgen accessor></div>"]
352+
/// <div rustbindgen accessor></div>
353353
#[repr(C)]
354354
#[derive(Debug, Default, Copy, Clone)]
355355
pub struct Wrapper {

tests/expectations/tests/annotation_hide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " <div rustbindgen opaque></div>"]
10+
/// <div rustbindgen opaque></div>
1111
#[repr(C)]
1212
#[derive(Debug, Default, Copy, Clone)]
1313
pub struct D {

tests/expectations/tests/array-of-zero-sized-types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " This should get an `_address` byte."]
10+
/// This should get an `_address` byte.
1111
#[repr(C)]
1212
#[derive(Debug, Default, Copy, Clone)]
1313
pub struct Empty {
@@ -26,8 +26,8 @@ fn bindgen_test_layout_Empty() {
2626
concat!("Alignment of ", stringify!(Empty))
2727
);
2828
}
29-
#[doc = " This should not get an `_address` byte, since each `Empty` gets one, meaning"]
30-
#[doc = " that this object is addressable."]
29+
/// This should not get an `_address` byte, since each `Empty` gets one, meaning
30+
/// that this object is addressable.
3131
#[repr(C)]
3232
#[derive(Debug, Default, Copy, Clone)]
3333
pub struct HasArrayOfEmpty {

tests/expectations/tests/blacklist-and-impl-debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
pub struct BlacklistMe(u8);
1111

12-
#[doc = " Because this type contains a blacklisted type, it should not derive Debug."]
12+
/// Because this type contains a blacklisted type, it should not derive Debug.
1313
#[repr(C)]
1414
pub struct ShouldManuallyImplDebug {
1515
pub a: BlacklistMe,

tests/expectations/tests/class_use_as.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " <div rustbindgen=\"true\" replaces=\"whatever\"></div>"]
10+
/// <div rustbindgen="true" replaces="whatever"></div>
1111
#[repr(C)]
1212
#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)]
1313
pub struct whatever {

tests/expectations/tests/comment-indent.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
pub mod root {
1212
#[allow(unused_imports)]
1313
use self::super::root;
14-
#[doc = " This is a multi-line doc comment."]
15-
#[doc = ""]
16-
#[doc = " This class is really really interesting, look!"]
14+
/// This is a multi-line doc comment.
15+
///
16+
/// This class is really really interesting, look!
1717
#[repr(C)]
1818
#[derive(Debug, Default, Copy, Clone)]
1919
pub struct Foo {
2020
pub _address: u8,
2121
}
22-
#[doc = " This nested class is also a multi-line doc comment."]
23-
#[doc = ""]
24-
#[doc = " This class is not so interesting, but worth a bit of docs too!"]
22+
/// This nested class is also a multi-line doc comment.
23+
///
24+
/// This class is not so interesting, but worth a bit of docs too!
2525
#[repr(C)]
2626
#[derive(Debug, Default, Copy, Clone)]
2727
pub struct Foo_Bar {
@@ -56,18 +56,18 @@ pub mod root {
5656
pub mod test {
5757
#[allow(unused_imports)]
5858
use self::super::super::root;
59-
#[doc = " I\'m in a namespace, and thus I may be on a rust module, most of the time."]
60-
#[doc = " My documentation is pretty extensive, I guess."]
59+
/// I'm in a namespace, and thus I may be on a rust module, most of the time.
60+
/// My documentation is pretty extensive, I guess.
6161
#[repr(C)]
6262
#[derive(Debug, Default, Copy, Clone)]
6363
pub struct Baz {
64-
#[doc = " This member is plain awesome, just amazing."]
65-
#[doc = ""]
66-
#[doc = " It also has super-extensive docs, with even a nice ascii-art diagram."]
67-
#[doc = ""]
68-
#[doc = " +------+ +-------+"]
69-
#[doc = " | foo | ----> | bar |"]
70-
#[doc = " +------+ +-------+"]
64+
/// This member is plain awesome, just amazing.
65+
///
66+
/// It also has super-extensive docs, with even a nice ascii-art diagram.
67+
///
68+
/// +------+ +-------+
69+
/// | foo | ----> | bar |
70+
/// +------+ +-------+
7171
pub member: ::std::os::raw::c_int,
7272
}
7373
#[test]
@@ -93,9 +93,9 @@ pub mod root {
9393
)
9494
);
9595
}
96-
#[doc = " I\'m in an inline namespace, and as such I shouldn\'t get generated inside"]
97-
#[doc = " a rust module, except when the relevant option is specified. Also, this"]
98-
#[doc = " comment shouldn\'t be misaligned."]
96+
/// I'm in an inline namespace, and as such I shouldn't get generated inside
97+
/// a rust module, except when the relevant option is specified. Also, this
98+
/// comment shouldn't be misaligned.
9999
#[repr(C)]
100100
#[derive(Debug, Default, Copy, Clone)]
101101
pub struct InInlineNS {

tests/expectations/tests/constify-enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ pub enum nsCSSPropertyID {
1919
eCSSProperty_b = 1,
2020
eCSSPropertyAlias_aa = 2,
2121
eCSSPropertyAlias_bb = 3,
22-
#[doc = "< <div rustbindgen constant></div>"]
22+
/// < <div rustbindgen constant></div>
2323
eCSSProperty_COUNT_unexistingVariantValue = 4,
2424
}

tests/expectations/tests/contains-vs-inherits-zero-sized.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " This should get an `_address` byte."]
10+
/// This should get an `_address` byte.
1111
#[repr(C)]
1212
#[derive(Debug, Default, Copy, Clone)]
1313
pub struct Empty {
@@ -26,8 +26,8 @@ fn bindgen_test_layout_Empty() {
2626
concat!("Alignment of ", stringify!(Empty))
2727
);
2828
}
29-
#[doc = " This should not get an `_address` byte, so `sizeof(Inherits)` should be"]
30-
#[doc = " `1`."]
29+
/// This should not get an `_address` byte, so `sizeof(Inherits)` should be
30+
/// `1`.
3131
#[repr(C)]
3232
#[derive(Debug, Default, Copy, Clone)]
3333
pub struct Inherits {
@@ -56,8 +56,8 @@ fn bindgen_test_layout_Inherits() {
5656
)
5757
);
5858
}
59-
#[doc = " This should not get an `_address` byte, but contains `Empty` which *does* get"]
60-
#[doc = " one, so `sizeof(Contains)` should be `1 + 1`."]
59+
/// This should not get an `_address` byte, but contains `Empty` which *does* get
60+
/// one, so `sizeof(Contains)` should be `1 + 1`.
6161
#[repr(C)]
6262
#[derive(Debug, Default, Copy, Clone)]
6363
pub struct Contains {

tests/expectations/tests/convert-cpp-comment-to-rust.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
)]
99

1010
pub type mbedtls_mpi_uint = ::std::os::raw::c_uint;
11-
#[doc = " \\brief MPI structure"]
11+
/// \brief MPI structure
1212
#[repr(C)]
1313
#[derive(Debug, Copy, Clone)]
1414
pub struct mbedtls_mpi {
15-
#[doc = "< integer sign"]
15+
/// < integer sign
1616
pub s: ::std::os::raw::c_int,
17-
#[doc = "< total # of limbs"]
17+
/// < total # of limbs
1818
pub n: ::std::os::raw::c_ulong,
19-
#[doc = "< pointer to limbs"]
19+
/// < pointer to limbs
2020
pub p: *mut mbedtls_mpi_uint,
2121
}
2222
#[test]

tests/expectations/tests/derive-bitfield-method-same-name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ where
8989
}
9090
}
9191
}
92-
#[doc = " Because this struct have array larger than 32 items"]
93-
#[doc = " and --with-derive-partialeq --impl-partialeq --impl-debug is provided,"]
94-
#[doc = " this struct should manually implement `Debug` and `PartialEq`."]
92+
/// Because this struct have array larger than 32 items
93+
/// and --with-derive-partialeq --impl-partialeq --impl-debug is provided,
94+
/// this struct should manually implement `Debug` and `PartialEq`.
9595
#[repr(C)]
9696
#[derive(Copy, Clone)]
9797
pub struct Foo {

tests/expectations/tests/derive-clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " This struct should derive `Clone`."]
10+
/// This struct should derive `Clone`.
1111
#[repr(C)]
1212
#[derive(Copy, Clone)]
1313
pub struct ShouldDeriveClone {

tests/expectations/tests/derive-clone_1_0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " Since builtin `Clone` impls were introduced in Rust 1.21 this struct"]
11-
#[doc = " should impl `Clone` \"manually\"."]
10+
/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct
11+
/// should impl `Clone` "manually".
1212
#[repr(C)]
1313
#[derive(Copy)]
1414
pub struct ShouldImplClone {

tests/expectations/tests/derive-default-and-blacklist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
pub struct BlacklistMe(u8);
1111

12-
#[doc = " Because this type contains a blacklisted type, it should not derive"]
13-
#[doc = " Default. Instead, we should emit a `mem::zeroed` implementation."]
12+
/// Because this type contains a blacklisted type, it should not derive
13+
/// Default. Instead, we should emit a `mem::zeroed` implementation.
1414
#[repr(C)]
1515
pub struct ShouldNotDeriveDefault {
1616
pub a: BlacklistMe,

tests/expectations/tests/derive-hash-and-blacklist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
pub struct BlacklistMe(u8);
1111

12-
#[doc = " Because this type contains a blacklisted type, it should not derive Hash."]
12+
/// Because this type contains a blacklisted type, it should not derive Hash.
1313
#[repr(C)]
1414
pub struct ShouldNotDeriveHash {
1515
pub a: BlacklistMe,

tests/expectations/tests/derive-hash-blacklisting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct Blacklisted<T> {
1414
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
1515
}
1616

17-
#[doc = " This would derive(Hash, Eq, PartialEq) if it didn\'t contain a blacklisted type,"]
18-
#[doc = " causing us to conservatively avoid deriving hash/Eq/PartialEq for it."]
17+
/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type,
18+
/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it.
1919
#[repr(C)]
2020
pub struct WhitelistedOne {
2121
pub a: Blacklisted<::std::os::raw::c_int>,
@@ -48,7 +48,7 @@ impl Default for WhitelistedOne {
4848
unsafe { ::std::mem::zeroed() }
4949
}
5050
}
51-
#[doc = " This can\'t derive(Hash/Eq) even if it didn\'t contain a blacklisted type."]
51+
/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type.
5252
#[repr(C)]
5353
pub struct WhitelistedTwo {
5454
pub b: Blacklisted<f32>,

tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd"]
10+
/// A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
1111
#[repr(C)]
1212
#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)]
1313
pub struct foo {

tests/expectations/tests/derive-hash-struct-with-float-array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
non_upper_case_globals
88
)]
99

10-
#[doc = " A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd"]
10+
/// A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd
1111
#[repr(C)]
1212
#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)]
1313
pub struct foo {

0 commit comments

Comments
 (0)