Skip to content

Commit

Permalink
Add explanations for why we use Variant::Struct instead of Variant::T…
Browse files Browse the repository at this point in the history
…uple for tuple structs in enums
  • Loading branch information
GuillaumeGomez committed Jul 27, 2021
1 parent fbf78e1 commit c4aa735
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit c4aa735

Please sign in to comment.