about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2021-07-27 13:52:15 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2021-07-27 13:52:15 +0200
commitc4aa73525bbfef6895612599170a5b297e1625ba (patch)
treef8cbf9486ddd7f09b00ca40568be6705e6fa8e96
parentfbf78e1f9cc80ba5a68078c3cf2cb4d03aa7b00c (diff)
downloadrust-c4aa73525bbfef6895612599170a5b297e1625ba.tar.gz
rust-c4aa73525bbfef6895612599170a5b297e1625ba.zip
Add explanations for why we use Variant::Struct instead of Variant::Tuple for tuple structs in enums
-rw-r--r--src/librustdoc/clean/mod.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index a5ad8dfeb6b..cf837024a8e 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1730,6 +1730,12 @@ impl Clean<Variant> for hir::VariantData<'_> {
     fn clean(&self, cx: &mut DocContext<'_>) -> Variant {
         match self {
             hir::VariantData::Struct(..) => Variant::Struct(self.clean(cx)),
+            // Important note here: `Variant::Tuple` is used on tuple structs which are not in an
+            // enum (so where converting from `ty::VariantDef`). In case we are in an enum, the kind
+            // is provided by the `Variant` wrapper directly, and since we need the fields' name
+            // (even for a tuple struct variant!), it's simpler to just store it as a
+            // `Variant::Struct` instead of a `Variant::Tuple` (otherwise it would force us to make
+            // a lot of changes when rendering them to generate the name as well).
             hir::VariantData::Tuple(..) => Variant::Struct(self.clean(cx)),
             hir::VariantData::Unit(..) => Variant::CLike,
         }