mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Implemented basic enum const eval
This commit is contained in:
parent
f64c95600c
commit
997fc46efa
14 changed files with 227 additions and 17 deletions
|
@ -3527,6 +3527,86 @@ impl<const LEN: usize> Foo<LEN$0> {}
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_const_eval_variant() {
|
||||
// show hex for <10
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum E {
|
||||
/// This is a doc
|
||||
A$0 = 1 << 3,
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*A*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
A = 8
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
// show hex for >10
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum E {
|
||||
/// This is a doc
|
||||
A$0 = (1 << 3) + (1 << 2),
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*A*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
A = 12 (0xC)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
// enums in const eval
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
enum E {
|
||||
A = 1,
|
||||
/// This is a doc
|
||||
B$0 = E::A + 1,
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*B*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
B = 2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_const_eval() {
|
||||
// show hex for <10
|
||||
|
@ -3820,6 +3900,35 @@ fn foo() {
|
|||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
r#"
|
||||
enum E {
|
||||
/// This is a doc
|
||||
A = 3,
|
||||
}
|
||||
fn foo(e: E) {
|
||||
match e {
|
||||
E::A$0 => (),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*A*
|
||||
|
||||
```rust
|
||||
test::E
|
||||
```
|
||||
|
||||
```rust
|
||||
A = 3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue