mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Allow static initializers to be const evaluated
This commit is contained in:
parent
d1fbfc676b
commit
94c35f6138
7 changed files with 87 additions and 28 deletions
|
@ -486,13 +486,19 @@ pub(super) fn definition(
|
|||
}
|
||||
}
|
||||
Definition::Static(it) => {
|
||||
let source = it.source(db)?;
|
||||
let mut body = source.value.body()?.syntax().clone();
|
||||
if let Some(macro_file) = source.file_id.macro_file() {
|
||||
let span_map = db.expansion_span_map(macro_file);
|
||||
body = prettify_macro_expansion(db, body, &span_map, it.krate(db).into());
|
||||
let body = it.render_eval(db, edition);
|
||||
match body {
|
||||
Ok(it) => Some(it),
|
||||
Err(_) => {
|
||||
let source = it.source(db)?;
|
||||
let mut body = source.value.body()?.syntax().clone();
|
||||
if let Some(macro_file) = source.file_id.macro_file() {
|
||||
let span_map = db.expansion_span_map(macro_file);
|
||||
body = prettify_macro_expansion(db, body, &span_map, it.krate(db).into());
|
||||
}
|
||||
Some(body.to_string())
|
||||
}
|
||||
}
|
||||
Some(body.to_string())
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
|
|
@ -1544,7 +1544,7 @@ const foo$0: u32 = {
|
|||
```
|
||||
|
||||
```rust
|
||||
static foo: u32 = 456
|
||||
static foo: u32 = 456 (0x1C8)
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue