Skip to content

Commit c4aa735

Browse files
Add explanations for why we use Variant::Struct instead of Variant::Tuple for tuple structs in enums
1 parent fbf78e1 commit c4aa735

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/librustdoc/clean/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,12 @@ impl Clean<Variant> for hir::VariantData<'_> {
17301730
fn clean(&self, cx: &mut DocContext<'_>) -> Variant {
17311731
match self {
17321732
hir::VariantData::Struct(..) => Variant::Struct(self.clean(cx)),
1733+
// Important note here: `Variant::Tuple` is used on tuple structs which are not in an
1734+
// enum (so where converting from `ty::VariantDef`). In case we are in an enum, the kind
1735+
// is provided by the `Variant` wrapper directly, and since we need the fields' name
1736+
// (even for a tuple struct variant!), it's simpler to just store it as a
1737+
// `Variant::Struct` instead of a `Variant::Tuple` (otherwise it would force us to make
1738+
// a lot of changes when rendering them to generate the name as well).
17331739
hir::VariantData::Tuple(..) => Variant::Struct(self.clean(cx)),
17341740
hir::VariantData::Unit(..) => Variant::CLike,
17351741
}

0 commit comments

Comments
 (0)