Description
Feature Name
Support documenting tuple return value elements individually
Description
Currently, return value documentation in DocC applies to the entire return value as a whole. This makes sense for functions and methods that return a single value but for functions and methods that return tuples (especially tuples with named elements) it mean that the same paragraph has to describe both values and describe the tuple structure in the content.
For example, the quotientAndRemainder(dividingBy:)
method in Swift documents its return value as:
A tuple containing the quotient and remainder of this value divided by
rhs
. The remainder has the same sign aslhs
.
Similarly, code in DocC itself uses the "a pair of ..." phrase to describe tuple return values:
/// ...
/// - Returns: A pair of the parsed path components and a flag that indicate if the documentation link is absolute or not.
static func parse(path: String) -> (components: [PathComponent], isAbsolute: Bool)
/// ...
/// - Returns: A pair of the matching elements and the remaining elements, that didn't match.
func categorize<Result>(where matches: (Element) -> Result?) -> (matching: [Result], remainder: [Element])
In cases like this it could be helpful to be able to document each element of the tuple return value individually using a syntax similar to the way parameters are documented. For example:
/// ...
/// - Returns:
/// - quotient: the quotient of this value divided by `rhs`.
/// - remainder: the remainder of this value divided by `rhs` with the same sign as the original value.
func quotientAndRemainder(dividingBy rhs: Self) -> (quotient: Self, remainder: Self)
/// ...
/// - Returns:
/// - component: the parsed path components.
/// - isAbsolute: a flag that indicate if the documentation link is absolute or not.
static func parse(path: String) -> (components: [PathComponent], isAbsolute: Bool)
/// ...
/// - Returns:
/// - matching: the elements that match the predicate.
/// - remainder: the elements that don't match the predicate.
func categorize<Result>(where matches: (Element) -> Result?) -> (matching: [Result], remainder: [Element])
Note: It's possible to write documentation markup like this today but the list items in the return value aren't presented the same as the items for the parameter documentation:

DocC already knows how many elements the tuple return value contains, so it should be possible to raise warnings if the return value documentation describes too many or too few individual return values.
It's important that this is an additive change so that existing documentation for tuple return value don't change behavior or result in warnings.
In some cases the developer might also prefer to continue to document all tuple elements of the return value together. That should continue to be supported.
Motivation
See the description above for example use cases of documenting tuple return value elements individually.
Importance
This is a fairly unimportant enhancement. It doesn't enable any new use-cases and the markup for this is already supported but it doesn't render as well as it could on the page.
Alternatives Considered
No response