Update derive attibute span to start after opening '('
Fixes 4984 When parsing derive attributes we're only concerned about the traits and comments listed between the opening and closing parentheses. Derive attribute spans currently start at the '#'. Span starts here | v #[derive(...)] After this update the derive spans start after the opening '('. Span starts here | V #[derive(...)]
This commit is contained in:
parent
f0f449d6ed
commit
40f4993c67
@ -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};
|
||||
|
||||
@ -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,
|
||||
);
|
||||
|
2
tests/source/issue-4984/minimum_example.rs
Normal file
2
tests/source/issue-4984/minimum_example.rs
Normal file
@ -0,0 +1,2 @@
|
||||
#[derive(/*Debug, */Clone)]
|
||||
struct Foo;
|
20
tests/source/issue-4984/multi_line_derive.rs
Normal file
20
tests/source/issue-4984/multi_line_derive.rs
Normal file
@ -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,
|
||||
}
|
2
tests/target/issue-4984/minimum_example.rs
Normal file
2
tests/target/issue-4984/minimum_example.rs
Normal file
@ -0,0 +1,2 @@
|
||||
#[derive(/*Debug, */ Clone)]
|
||||
struct Foo;
|
26
tests/target/issue-4984/multi_line_derive.rs
Normal file
26
tests/target/issue-4984/multi_line_derive.rs
Normal file
@ -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,
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user