Skip to content

Alternate syntax idea for Return Type Notation #117375

Closed
@zyansheep

Description

@zyansheep

Tracking Issue: #109417

Hi, I'm new so let me know if this is not the right forum for this :), the tracking issue noted that it was not for discussion and that people should open up a separate issue.

I had an idea for a more consistent syntax for Return Type Notation. My thought process is as follows:

Given that we already have traits that auto-implement for all functions (FnOnce, Fn, FnMut), which all contain the associated type FnOnce::Output, why not just allow the ability to impose constraints on that associated type as a way to name the output of a function?
For Example:

// Current syntax
trait It {
  fn iter(&self) -> impl Iterator<Item = u32>;
}
fn twice<I: It<iter(): Clone>>(i: I) {}
// new syntax idea:
fn twice<I: It>(i: I)
where
  <I::iter as Fn>::Output: Clone
{}
// could even be shortened further:
fn twice<I: It<iter::Output: Clone>>(i: I) {}

Came up with this idea while watching Jon Gjengset's lecture about impl Traits, so I don't quite understand all the minutiae of the feature, only that this is a problem and it seems to require syntax changes. Is this idea semantically inconsistent? decent but needs modification? totally awesome? What you all think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.F-return_type_notation`#[feature(return_type_notation)]`T-langRelevant to the language teamWG-asyncWorking group: Async & await

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions