diff options
| author | ponyii <ponyii@protonmail.com> | 2023-08-15 20:26:42 +0400 |
|---|---|---|
| committer | ponyii <ponyii@protonmail.com> | 2023-08-15 20:26:42 +0400 |
| commit | fec5ff989025ee01f7659da28e95d0fe0feafa86 (patch) | |
| tree | 0416723a23873ce736872c8aa343e6a2f86c14c9 | |
| parent | d548146c3000985b493ca45c1f2faab2ae21ea41 (diff) | |
| download | rust-fec5ff989025ee01f7659da28e95d0fe0feafa86.tar.gz rust-fec5ff989025ee01f7659da28e95d0fe0feafa86.zip | |
start hovering default values of generic constants
| -rw-r--r-- | crates/hir/src/display.rs | 5 | ||||
| -rw-r--r-- | crates/ide/src/hover/tests.rs | 45 |
2 files changed, 49 insertions, 1 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index a701eb01192..ac171026d5d 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -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()))?; + } } } } diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 541cce8c5bf..d0f9f7b0e16 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -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> ``` "#]], ); |
