Ergonomics initiative discussion: Allowing owned values where references are expected

I'm still really confused; but I think most of all I'm looking for an explanation about why my request is not part of completing the the initiative Allowing owned values where references are expected, which is the feeling that I get from phrases like "starting a separate thread", "it's a separate thing", "a separate feature". My guess is that I do not understand the true scope of the initiative.

  • If my request falls under the initiative, but is impossible to fix, I'd like to know that.
  • If my request falls under the initiative, but we don't care to address it (at least this year), I'd like to know that.
  • If my request has nothing to do with the initiative as worded, I'd like to understand why not. I'd then like to help rephrase the initiative to help avoid anyone else from being confused in the same way, and to help set expectations for the eventual feature.

With that request made, I'll attempt to restate my position to reduce any confusion I might have introduced. Using the previous code, this is my understanding of the state of the world with the initial proposal.

free function

struct Thing;

fn foo(_: &Thing) {}

fn currently_does_not_work_but_would_with_the_proposal(thing: Thing) {
    foo(thing);
}

fn currently_does_not_work_but_would_with_the_proposal_also(thing: Thing) {
    Some(thing).map(|t| foo(t));
}

fn would_not_work_even_with_the_proposal(thing: Thing) {
    Some(thing).map(foo);
}

We will be able to transfer ownership of objects to methods expecting references.

method

struct Thing;

impl Thing {
    fn foo(&self) {}
}

fn currently_works(thing: Thing) {
    thing.foo();
}

fn currently_works_also(thing: Thing) {
    Some(thing).map(|t| t.foo());
}

fn currently_does_not_work_but_would_with_the_proposal(thing: Thing) {
    Some(thing).map(|t| Thing::foo(t));
}

fn would_not_work_even_with_the_proposal(thing: Thing) {
    Some(thing).map(Thing::foo);
}

This is a place where an owned value is already allowed to act as if it is a reference (map(|t| t.foo()), but not when using a different syntax that appears equivalent (map(Thing::foo)). The proposal will make it even closer (map(|t| Thing::foo(t))) which means the fact that the non-functional syntax is even harder to explain.

2 Likes