about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-06-09 12:04:03 +0900
committerGitHub <noreply@github.com>2021-06-09 12:04:03 +0900
commit606feba5bbfa61ef9562fd2f583833ed5c13ffdc (patch)
treee88bf1670e03fe13197c73408a9a523897d4a3b6 /src/librustdoc/html
parent3bc822155807e3915a5455f8d08a06d0a8698086 (diff)
parentf7117f8c177c63d6aadfb569550839b4add617a9 (diff)
Rollup merge of #85957 - BoxyUwU:rustdoc-const-generic-defaults, r=oli-obk
Display defaults on const params- rustdoc

previously rustdoc would render this struct declaration:
`pub struct Foo<const N: usize = 10>;`
as:
`pub struct Foo<const N: usize>;`
this PR changes it to render correctly
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/format.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index d5213fd7711..918a5cb5094 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -177,12 +177,22 @@ impl clean::GenericParamDef {
 
                 Ok(())
             }
-            clean::GenericParamDefKind::Const { ref ty, .. } => {
+            clean::GenericParamDefKind::Const { ref ty, ref default, .. } => {
                 if f.alternate() {
-                    write!(f, "const {}: {:#}", self.name, ty.print(cx))
+                    write!(f, "const {}: {:#}", self.name, ty.print(cx))?;
                 } else {
-                    write!(f, "const {}:&nbsp;{}", self.name, ty.print(cx))
+                    write!(f, "const {}:&nbsp;{}", self.name, ty.print(cx))?;
                 }
+
+                if let Some(default) = default {
+                    if f.alternate() {
+                        write!(f, " = {:#}", default)?;
+                    } else {
+                        write!(f, "&nbsp;=&nbsp;{}", default)?;
+                    }
+                }
+
+                Ok(())
             }
         })
     }