mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
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:
parent
989b09d20c
commit
e295f0c29c
2 changed files with 77 additions and 3 deletions
|
@ -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;
|
||||
|
||||
}
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue