about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorJustus K <justus.k@protonmail.com>2021-05-18 10:06:24 +0200
committerJustus K <justus.k@protonmail.com>2021-06-18 21:58:09 +0200
commit1f65f56461fa72df809fff43975a7e72f08fda44 (patch)
tree3467d490de695f02614249f972a3eba12651738a /src/librustdoc/html
parente0162a8a56d1c59e185e293f33c38d94a5a2d462 (diff)
downloadrust-1f65f56461fa72df809fff43975a7e72f08fda44.tar.gz
rust-1f65f56461fa72df809fff43975a7e72f08fda44.zip
rustdoc: Render `for<'_>` lifetimes in trait objects
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/format.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index a424932d83f..e4fb7384aff 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -646,11 +646,11 @@ fn primitive_link(
 
 /// Helper to render type parameters
 fn tybounds<'a, 'tcx: 'a>(
-    param_names: &'a Option<Vec<clean::GenericBound>>,
+    param_names: Option<&'a Vec<clean::GenericBound>>,
     cx: &'a Context<'tcx>,
 ) -> impl fmt::Display + 'a + Captures<'tcx> {
-    display_fn(move |f| match *param_names {
-        Some(ref params) => {
+    display_fn(move |f| match param_names {
+        Some(params) => {
             for param in params {
                 write!(f, " + ")?;
                 fmt::Display::fmt(&param.print(cx), f)?;
@@ -695,8 +695,27 @@ fn fmt_type<'cx>(
     match *t {
         clean::Generic(name) => write!(f, "{}", name),
         clean::ResolvedPath { did, ref param_names, ref path, is_generic } => {
-            if param_names.is_some() {
+            let generic_params = param_names.as_ref().map(|(_, x)| x);
+            let param_names = param_names.as_ref().map(|(x, _)| x);
+
+            if let Some(generic_params) = generic_params {
                 f.write_str("dyn ")?;
+
+                if !generic_params.is_empty() {
+                    if f.alternate() {
+                        write!(
+                            f,
+                            "for<{:#}> ",
+                            comma_sep(generic_params.iter().map(|g| g.print(cx)))
+                        )?;
+                    } else {
+                        write!(
+                            f,
+                            "for&lt;{}&gt; ",
+                            comma_sep(generic_params.iter().map(|g| g.print(cx)))
+                        )?;
+                    }
+                }
             }
             // Paths like `T::Output` and `Self::Output` should be rendered with all segments.
             resolved_path(f, did, path, is_generic, use_absolute, cx)?;
@@ -835,7 +854,7 @@ fn fmt_type<'cx>(
                         }
                     }
                 }
-                clean::ResolvedPath { param_names: Some(ref v), .. } if !v.is_empty() => {
+                clean::ResolvedPath { param_names: Some((ref v, _)), .. } if !v.is_empty() => {
                     write!(f, "{}{}{}(", amp, lt, m)?;
                     fmt_type(&ty, f, use_absolute, cx)?;
                     write!(f, ")")