Insert whitespaces into static & const bodies if they are expanded from macro on hover

Macro expansion erases whitespace information, and so we end with invalid Rust code.
This commit is contained in:
Chayim Refael Friedman 2022-09-04 13:26:00 +00:00
parent 989b09d20c
commit e295f0c29c
2 changed files with 77 additions and 3 deletions

View file

@ -5113,3 +5113,62 @@ fn f() {
"#]],
);
}
#[test]
fn static_const_macro_expanded_body() {
check(
r#"
macro_rules! m {
() => {
pub const V: i8 = {
let e = 123;
f(e) // Prevent const eval from evaluating this constant, we want to print the body's code.
};
};
}
m!();
fn main() { $0V; }
"#,
expect![[r#"
*V*
```rust
test
```
```rust
pub const V: i8 = {
let e = 123;
f(e)
}
```
"#]],
);
check(
r#"
macro_rules! m {
() => {
pub static V: i8 = {
let e = 123;
};
};
}
m!();
fn main() { $0V; }
"#,
expect![[r#"
*V*
```rust
test
```
```rust
pub static V: i8 = {
let e = 123;
}
```
"#]],
);
}