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

Finalize unboxed closure feature gates for 1.0 #18875

Closed
3 of 4 tasks
nikomatsakis opened this issue Nov 11, 2014 · 6 comments · Fixed by #20869
Closed
3 of 4 tasks

Finalize unboxed closure feature gates for 1.0 #18875

nikomatsakis opened this issue Nov 11, 2014 · 6 comments · Fixed by #20869
Labels
A-closures Area: Closures (`|…| { … }`)
Milestone

Comments

@nikomatsakis
Copy link
Contributor

We do not expect to completely "unfeature-gate" unboxed closures for 1.0. We wish to reserve the flexibility to change a few aspects:

  1. Move to variadic generics in place of auto-tupling.
  2. Change the A and R arguments from input types to (possibly) associated types. (cc Make return type of the Fn traits an associated type #20871)
  3. Improve the coherence story with respect to fn-trait hierarchy. (cc Unable to manually implement FnOnce #18835)

To this end we will adjust the features to:

  • Disallow references to the Fn* traits using angle bracket notation
  • Disallow user impls of the Fn* traits
  • Disallow direct calls to foo.call()
  • Disallow parenthetical notation (Foo(A,B) -> C) from being used with anything other than the Fn* traits

In short, we permit unboxed closures to be used as if they are a language builtin, but disallow (for now) a lot of the more generic uses. We should be able to drop this feature gate shortly after 1.0.

cc @pcwalton

@nikomatsakis
Copy link
Contributor Author

Nominating for 1.0 or something. :)

@huonw huonw added the A-closures Area: Closures (`|…| { … }`) label Nov 12, 2014
@pnkfelix
Copy link
Member

P-backcompat-lang, 1.0.

@nikomatsakis
Copy link
Contributor Author

Note that some of this works today though it ought not, e.g. manually implementing Fn traits.

@bstrie
Copy link
Contributor

bstrie commented Nov 18, 2014

To expand on @nikomatsakis' comment, the following code fails to compile due to the lack of a feature that should be gated:

struct MemberFn<'a, T, R, A0> where T : 'a {
    fun: fn (&T, A0) -> R,
    obj: &'a T
}

impl<'a, T, R, A0> MemberFn<'a, T, R, A0> where T : 'a {
    fn new(o: &'a T, f: fn (&T, A0) -> R) -> MemberFn<'a, T, R, A0> {
        MemberFn {
            fun: f,
            obj: o
        }
    }
}

impl<'a, T, R, A0, Args> Fn<Args, R> for MemberFn<'a, T, R, A0> where Args : Tuple1<A0> {
   fn call(&self, args: Args) -> R {
        (self.fun)(self.obj, args.val0())
    }
}

fn main() {
    println!("Hello, world!")
}

The current solution is to put extern "rust-call" on the call function.

huonw added a commit to huonw/rust that referenced this issue Dec 6, 2014
detect UFCS drop and allow UFCS methods to have explicit type parameters.

Work towards rust-lang#18875.

Since code could previously call the methods & implement the traits
manually, this is a

[breaking-change]

Closes rust-lang#19586. Closes rust-lang#19375.
alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 9, 2014
detect UFCS drop and allow UFCS methods to have explicit type parameters.

Work towards rust-lang#18875.

Since code could previously call the methods & implement the traits
manually, this is a

[breaking-change]

Closes rust-lang#19586. Closes rust-lang#19375.
@nikomatsakis
Copy link
Contributor Author

This was done, or done enough.

@nikomatsakis
Copy link
Contributor Author

Oops, I totally overlooked that Fn<(),()> is still considered legal. It's important to adjust that too!

@nikomatsakis nikomatsakis modified the milestones: 1.0 beta, 1.0 Jan 10, 2015
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Jan 10, 2015
bors added a commit that referenced this issue Jan 10, 2015
Feature-gate `<>` syntax used with `Fn`. Fixes #18875.

r? @huonw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants