diff options
| author | bors <bors@rust-lang.org> | 2022-06-19 14:51:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-19 14:51:28 +0000 |
| commit | 68d0b29098ed75f50dabc7d07b96c70caab5c182 (patch) | |
| tree | 4aab4e2b4b5778738a08618abb7670c0221ff637 /src/librustdoc/html | |
| parent | 67404f7200c13deec255ffe1146e1d2c9d0d3028 (diff) | |
| parent | 6a2a56da451a357141bc8c929045ec2aafa3421f (diff) | |
| download | rust-68d0b29098ed75f50dabc7d07b96c70caab5c182.tar.gz rust-68d0b29098ed75f50dabc7d07b96c70caab5c182.zip | |
Auto merge of #98255 - Dylan-DPC:rollup-hr129rg, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #98105 (rustdoc: remove tuple link on round braces) - #98136 (Rename `impl_constness` to `constness`) - #98146 (Remove --memory-init-file flag when linking with Emscripten) - #98219 (Skip late bound regions in GATSubstCollector) - #98233 (Remove accidental uses of `&A: Allocator`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/format.rs | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 0c0920ae63e..5baa53d5554 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -23,6 +23,8 @@ use rustc_span::symbol::kw; use rustc_span::{sym, Symbol}; use rustc_target::spec::abi::Abi; +use itertools::Itertools; + use crate::clean::{ self, types::ExternalLocation, utils::find_nearest_parent_module, ExternalCrate, ItemId, PrimitiveType, @@ -874,20 +876,42 @@ fn fmt_type<'cx>( match &typs[..] { &[] => primitive_link(f, PrimitiveType::Unit, "()", cx), &[ref one] => { - primitive_link(f, PrimitiveType::Tuple, "(", cx)?; - // Carry `f.alternate()` into this display w/o branching manually. - fmt::Display::fmt(&one.print(cx), f)?; - primitive_link(f, PrimitiveType::Tuple, ",)", cx) + if let clean::Generic(name) = one { + primitive_link(f, PrimitiveType::Tuple, &format!("({name},)"), cx) + } else { + write!(f, "(")?; + // Carry `f.alternate()` into this display w/o branching manually. + fmt::Display::fmt(&one.print(cx), f)?; + write!(f, ",)") + } } many => { - primitive_link(f, PrimitiveType::Tuple, "(", cx)?; - for (i, item) in many.iter().enumerate() { - if i != 0 { - write!(f, ", ")?; + let generic_names: Vec<Symbol> = many + .iter() + .filter_map(|t| match t { + clean::Generic(name) => Some(*name), + _ => None, + }) + .collect(); + let is_generic = generic_names.len() == many.len(); + if is_generic { + primitive_link( + f, + PrimitiveType::Tuple, + &format!("({})", generic_names.iter().map(|s| s.as_str()).join(", ")), + cx, + ) + } else { + write!(f, "(")?; + for (i, item) in many.iter().enumerate() { + if i != 0 { + write!(f, ", ")?; + } + // Carry `f.alternate()` into this display w/o branching manually. + fmt::Display::fmt(&item.print(cx), f)?; } - fmt::Display::fmt(&item.print(cx), f)?; + write!(f, ")") } - primitive_link(f, PrimitiveType::Tuple, ")", cx) } } } |
