Skip to content

fix: start hovering default values of generic constants #15463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/hir/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ fn write_generic_params(
delim(f)?;
write!(f, "const {}: ", name.display(f.db.upcast()))?;
c.ty.hir_fmt(f)?;

if let Some(default) = &c.default {
f.write_str(" = ")?;
write!(f, "{}", default.display(f.db.upcast()))?;
}
}
}
}
Expand Down
45 changes: 44 additions & 1 deletion crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3335,7 +3335,50 @@ struct S$0T<const C: usize = 1, T = Foo>(T);
```

```rust
struct ST<const C: usize, T = Foo>
struct ST<const C: usize = 1, T = Foo>
```
"#]],
);
}

#[test]
fn const_generic_default_value() {
check(
r#"
struct Foo;
struct S$0T<const C: usize = {40 + 2}, T = Foo>(T);
"#,
expect![[r#"
*ST*

```rust
test
```

```rust
struct ST<const C: usize = {const}, T = Foo>
```
"#]],
);
}

#[test]
fn const_generic_default_value_2() {
check(
r#"
struct Foo;
const VAL = 1;
struct S$0T<const C: usize = VAL, T = Foo>(T);
"#,
expect![[r#"
*ST*

```rust
test
```

```rust
struct ST<const C: usize = VAL, T = Foo>
```
"#]],
);
Expand Down