# Ergonomics initiative discussion: Allowing owned values where references are expected

**URL:** <https://internals.rust-lang.org/t/ergonomics-initiative-discussion-allowing-owned-values-where-references-are-expected/5161>\
**Category:** language design\
**Created:** [April 29, 2017, 2:53pm UTC](https://internals.rust-lang.org/t/ergonomics-initiative-discussion-allowing-owned-values-where-references-are-expected/5161 "2017-04-29T14:53:37Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![aturon](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/aturon/32/3272_2.png) [@aturon](https://internals.rust-lang.org/u/aturon)\
**Post date:** [May 4, 2017, 12:36pm UTC](https://internals.rust-lang.org/t/ergonomics-initiative-discussion-allowing-owned-values-where-references-are-expected/5161/22 "2017-05-04T12:36:17Z")

</div>

> [@shepmaster](#):
>
> It seems like both of you are operating with the knowledge that there's already a planned implementation for how to address this ergonomic initiative, we plan on no further improvements, and my example will not be solved by that implementation.

A bit of background: Rust makes a distinction between _coercion_ and _subtyping_. Coercions only apply at the "top level" of a type -- so you can go from `&&T` to `&T`, but not `Vec<&&T>` to `Vec<&T>`. Subtyping comes in with lifetimes, and triggers at all levels: you can go from `&[&'static T]` to `&[&'a T]`.

Now, consider what it would take to allow coercions to apply deeply; in a case like `Vec<&&T>` above, you would actually have to create a new vector, because you're changing the elements in a significant way. Even if we could give you the tools to tell Rust how to do this, it's not the kind of thing we would generally want to happen as part of an implicit coercion, I think.

However, there might be potential to apply coercions in more places than today, without applying them arbitrarily deeply. Here's how I would think of it:

- The `AsRef` proposal is about adding a new coercion based on `AsRef`, which fits into our existing coercion story.
- Separately, as a distinct ergonomics improvement, we should ask whether there are situations where we can apply coercions at the function level _in general_. It seems quite plausible -- it would effectively be sugar for writing a closure that simply calls the function (i.e., `|x| f(x)`), which _would_ apply coercions.

I'd suggest starting a separate thread on that extension, and linking to it from the Ergonomics Roadmap tracker.

---

_[View the full topic](https://internals.rust-lang.org/t/ergonomics-initiative-discussion-allowing-owned-values-where-references-are-expected/5161)._
