]> git.lizzy.rs Git - rust.git/commitdiff
fix: don't drop leading comments in extern
authorCaleb Cartwright <caleb.cartwright@outlook.com>
Mon, 16 Nov 2020 18:39:26 +0000 (12:39 -0600)
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>
Mon, 16 Nov 2020 21:48:20 +0000 (15:48 -0600)
src/items.rs
tests/source/issue_4528.rs [new file with mode: 0644]
tests/target/issue_4528.rs [new file with mode: 0644]

index 01063b1f3bc88c2192d0c557ec5b49a7e63e377f..d9f3361d8a332c29c279f1af85fc8b46d24d8ab4 100644 (file)
@@ -161,14 +161,6 @@ enum BodyElement<'a> {
     ForeignItem(&'a ast::ForeignItem),
 }
 
-impl BodyElement<'_> {
-    pub(crate) fn span(&self) -> Span {
-        match self {
-            BodyElement::ForeignItem(fi) => fi.span(),
-        }
-    }
-}
-
 /// Represents a fn's signature.
 pub(crate) struct FnSig<'a> {
     decl: &'a ast::FnDecl,
@@ -277,9 +269,6 @@ fn format_item(&mut self, item: &Item<'_>) {
             self.block_indent = self.block_indent.block_indent(self.config);
 
             if !item.body.is_empty() {
-                // Advance to first item (statement or inner attribute)
-                // within the block.
-                self.last_pos = item.body[0].span().lo();
                 for item in &item.body {
                     self.format_body_element(item);
                 }
diff --git a/tests/source/issue_4528.rs b/tests/source/issue_4528.rs
new file mode 100644 (file)
index 0000000..85f6d8c
--- /dev/null
@@ -0,0 +1,8 @@
+#![allow(clippy::no_effect)]
+extern "C" {
+ // N.B., mutability can be easily incorrect in FFI calls -- as
+     // in C, the default is mutable pointers.
+    fn ffi(c: *mut u8);
+     fn int_ffi(c: *mut i32);
+}
\ No newline at end of file
diff --git a/tests/target/issue_4528.rs b/tests/target/issue_4528.rs
new file mode 100644 (file)
index 0000000..7828804
--- /dev/null
@@ -0,0 +1,8 @@
+#![allow(clippy::no_effect)]
+
+extern "C" {
+    // N.B., mutability can be easily incorrect in FFI calls -- as
+    // in C, the default is mutable pointers.
+    fn ffi(c: *mut u8);
+    fn int_ffi(c: *mut i32);
+}