Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate syntax idea for Return Type Notation #117375

Closed
zyansheep opened this issue Oct 30, 2023 · 4 comments
Closed

Alternate syntax idea for Return Type Notation #117375

zyansheep opened this issue Oct 30, 2023 · 4 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. F-return_type_notation `#[feature(return_type_notation)]` T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-async Working group: Async & await

Comments

@zyansheep
Copy link

zyansheep commented Oct 30, 2023

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?

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@Jules-Bertholet
Copy link
Contributor

@rustbot label C-discussion F-return_type_notation T-lang -needs-triage

@rustbot rustbot added C-discussion Category: Discussion or questions that doesn't represent real issues. F-return_type_notation `#[feature(return_type_notation)]` T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 30, 2023
@marmeladema
Copy link
Contributor

Been discussed a few times already, like here https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async/topic/Return-type.20notation.20alternatives

Not sure if this was really ever a potential usable solution because of issues with generics, lifetimes etc but from a syntax perspective, I agree that this looks less surprising / disruptive than the newly introduced RTN.

@traviscross traviscross added the WG-async Working group: Async & await label Oct 31, 2023
@zyansheep
Copy link
Author

For anyone who stumbles across this issue: Seems like there is already a proposal for something that would allow directly naming the outputs of a function, i.e. named function types :)
https://rust-lang.github.io/impl-trait-initiative/RFCs/named-function-types.html

@oli-obk
Copy link
Contributor

oli-obk commented Oct 31, 2023

The rust-lang/rust issues are usually not used for feature design discussions. I'm going to close this issue, as related topics have been linked and I'm not sure what we'd use this issue for from now on

@oli-obk oli-obk closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. F-return_type_notation `#[feature(return_type_notation)]` T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-async Working group: Async & await
Projects
None yet
Development

No branches or pull requests

6 participants