This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,11 @@ fn write_generic_params(
366366 delim ( f) ?;
367367 write ! ( f, "const {}: " , name. display( f. db. upcast( ) ) ) ?;
368368 c. ty . hir_fmt ( f) ?;
369+
370+ if let Some ( default) = & c. default {
371+ f. write_str ( " = " ) ?;
372+ write ! ( f, "{}" , default . display( f. db. upcast( ) ) ) ?;
373+ }
369374 }
370375 }
371376 }
Original file line number Diff line number Diff line change @@ -3335,7 +3335,50 @@ struct S$0T<const C: usize = 1, T = Foo>(T);
33353335 ```
33363336
33373337 ```rust
3338- struct ST<const C: usize, T = Foo>
3338+ struct ST<const C: usize = 1, T = Foo>
3339+ ```
3340+ "# ] ] ,
3341+ ) ;
3342+ }
3343+
3344+ #[ test]
3345+ fn const_generic_default_value ( ) {
3346+ check (
3347+ r#"
3348+ struct Foo;
3349+ struct S$0T<const C: usize = {40 + 2}, T = Foo>(T);
3350+ "# ,
3351+ expect ! [ [ r#"
3352+ *ST*
3353+
3354+ ```rust
3355+ test
3356+ ```
3357+
3358+ ```rust
3359+ struct ST<const C: usize = {const}, T = Foo>
3360+ ```
3361+ "# ] ] ,
3362+ ) ;
3363+ }
3364+
3365+ #[ test]
3366+ fn const_generic_default_value_2 ( ) {
3367+ check (
3368+ r#"
3369+ struct Foo;
3370+ const VAL = 1;
3371+ struct S$0T<const C: usize = VAL, T = Foo>(T);
3372+ "# ,
3373+ expect ! [ [ r#"
3374+ *ST*
3375+
3376+ ```rust
3377+ test
3378+ ```
3379+
3380+ ```rust
3381+ struct ST<const C: usize = VAL, T = Foo>
33393382 ```
33403383 "# ] ] ,
33413384 ) ;
You can’t perform that action at this time.
0 commit comments