]> git.lizzy.rs Git - rust.git/commitdiff
Use correct span for match arms with the leading pipe and attributes (#3975)
authorSeiichi Uchida <seuchida@gmail.com>
Sat, 21 Dec 2019 15:31:59 +0000 (00:31 +0900)
committerCaleb Cartwright <caleb.cartwright@outlook.com>
Sat, 27 Jun 2020 17:55:15 +0000 (12:55 -0500)
src/matches.rs
tests/target/issue-3974.rs [new file with mode: 0644]

index c6b1712232656a22744eb8d62cb1bbb05747f938..b5ca49b38bca846f5309183335c49347cc185554 100644 (file)
@@ -45,6 +45,7 @@ fn new(arm: &'a ast::Arm, is_last: bool, beginning_vert: Option<BytePos>) -> Arm
 impl<'a> Spanned for ArmWrapper<'a> {
     fn span(&self) -> Span {
         if let Some(lo) = self.beginning_vert {
+            let lo = std::cmp::min(lo, self.arm.span().lo());
             mk_sp(lo, self.arm.span().hi())
         } else {
             self.arm.span()
diff --git a/tests/target/issue-3974.rs b/tests/target/issue-3974.rs
new file mode 100644 (file)
index 0000000..a9f992e
--- /dev/null
@@ -0,0 +1,10 @@
+fn emulate_foreign_item() {
+    match link_name {
+        // A comment here will duplicate the attribute
+        #[rustfmt::skip]
+        | "pthread_mutexattr_init"
+        | "pthread_mutexattr_settype"
+        | "pthread_mutex_init"
+        => {}
+    }
+}