Skip to content

Commit 89f3830

Browse files
fix: don't drop leading comments in extern
1 parent 293d7d0 commit 89f3830

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Diff for: src/items.rs

-11
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ enum BodyElement<'a> {
161161
ForeignItem(&'a ast::ForeignItem),
162162
}
163163

164-
impl BodyElement<'_> {
165-
pub(crate) fn span(&self) -> Span {
166-
match self {
167-
BodyElement::ForeignItem(fi) => fi.span(),
168-
}
169-
}
170-
}
171-
172164
/// Represents a fn's signature.
173165
pub(crate) struct FnSig<'a> {
174166
decl: &'a ast::FnDecl,
@@ -277,9 +269,6 @@ impl<'a> FmtVisitor<'a> {
277269
self.block_indent = self.block_indent.block_indent(self.config);
278270

279271
if !item.body.is_empty() {
280-
// Advance to first item (statement or inner attribute)
281-
// within the block.
282-
self.last_pos = item.body[0].span().lo();
283272
for item in &item.body {
284273
self.format_body_element(item);
285274
}

Diff for: tests/source/issue_4528.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![allow(clippy::no_effect)]
2+
3+
extern "C" {
4+
// N.B., mutability can be easily incorrect in FFI calls -- as
5+
// in C, the default is mutable pointers.
6+
fn ffi(c: *mut u8);
7+
fn int_ffi(c: *mut i32);
8+
}

Diff for: tests/target/issue_4528.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![allow(clippy::no_effect)]
2+
3+
extern "C" {
4+
// N.B., mutability can be easily incorrect in FFI calls -- as
5+
// in C, the default is mutable pointers.
6+
fn ffi(c: *mut u8);
7+
fn int_ffi(c: *mut i32);
8+
}

0 commit comments

Comments
 (0)