Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting,
use crate::overflow;
use crate::rewrite::{Rewrite, RewriteContext};
use crate::shape::Shape;
use crate::source_map::SpanUtils;
use crate::types::{rewrite_path, PathContext};
use crate::utils::{count_newlines, mk_sp};

Expand Down Expand Up @@ -116,7 +117,9 @@ fn format_derive(
|span| span.lo(),
|span| span.hi(),
|span| Some(context.snippet(*span).to_owned()),
attr.span.lo(),
// We update derive attribute spans to start after the opening '('
// This helps us focus parsing to just what's inside #[derive(...)]
context.snippet_provider.span_after(attr.span, "("),
attr.span.hi(),
false,
);
Expand Down
2 changes: 2 additions & 0 deletions tests/source/issue-4984/minimum_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(/*Debug, */Clone)]
struct Foo;
20 changes: 20 additions & 0 deletions tests/source/issue-4984/multi_line_derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[derive(
/* ---------- Some really important comment that just had to go inside the derive --------- */
Debug, Clone, Eq, PartialEq,
)]
struct Foo {
a: i32,
b: T,
}

#[derive(
/*
Some really important comment that just had to go inside the derive.
Also had to be put over multiple lines
*/
Debug, Clone, Eq, PartialEq,
)]
struct Bar {
a: i32,
b: T,
}
8 changes: 8 additions & 0 deletions tests/source/issue-4984/multiple_comments_within.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[derive(
/* ---------- Some really important comment that just had to go inside the derive --------- */
Debug, Clone,/* Another comment */Eq, PartialEq,
)]
struct Foo {
a: i32,
b: T,
}
2 changes: 2 additions & 0 deletions tests/target/issue-4984/minimum_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(/*Debug, */ Clone)]
struct Foo;
26 changes: 26 additions & 0 deletions tests/target/issue-4984/multi_line_derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[derive(
/* ---------- Some really important comment that just had to go inside the derive --------- */
Debug,
Clone,
Eq,
PartialEq,
)]
struct Foo {
a: i32,
b: T,
}

#[derive(
/*
Some really important comment that just had to go inside the derive.
Also had to be put over multiple lines
*/
Debug,
Clone,
Eq,
PartialEq,
)]
struct Bar {
a: i32,
b: T,
}
11 changes: 11 additions & 0 deletions tests/target/issue-4984/multiple_comments_within.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[derive(
/* ---------- Some really important comment that just had to go inside the derive --------- */
Debug,
Clone,
/* Another comment */ Eq,
PartialEq,
)]
struct Foo {
a: i32,
b: T,
}
5 changes: 5 additions & 0 deletions tests/target/issue-4984/should_not_change.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Clone, Debug, Eq, PartialEq)]
struct Foo;

#[derive(Clone)]
struct Bar;