diff --git a/src/matches.rs b/src/matches.rs index c6b1712232656..b5ca49b38bca8 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -45,6 +45,7 @@ impl<'a> ArmWrapper<'a> { 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 index 0000000000000..a9f992ebd5c6f --- /dev/null +++ b/tests/target/issue-3974.rs @@ -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" + => {} + } +}