# \[Pre-RFC\] Implementation of \`From\<&()\>\` for \`()\`

**URL:** <https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839>\
**Category:** language design\
**Created:** [December 20, 2025, 2:06pm UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839 "2025-12-20T14:06:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcmah309](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mcmah309/32/13721_2.png) [@mcmah309](https://internals.rust-lang.org/u/mcmah309)\
**Post date:** [December 20, 2025, 2:06pm UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/1 "2025-12-20T14:06:02Z")

</div>

## [Pre-RFC] Implementation of `From<&()>` for `()`

### Summary

Implement `From<&()>` (and potentially `From<&mut ()>`) for the unit type `()`. This would allow the question mark operator (`?`) to automatically "unwrap" references to unit types, smoothing over ergonomics when working with `Result`.

### Motivation

A common pattern in Rust is to reference a `Result` to avoid moving out of a value, often via `.as_ref()`. This transforms a `Result<T, E>` into a `Result<&T, &E>`.

When the error type is the unit type `()`, the resulting type is `Result<&T, &()>`. However, because `&()` does not implement `Into<()>`, the following code fails to compile:

```rust
fn handle_data(result: &Result<Data, ()>) -> Result<(), ()> {
    let data = result.as_ref()?; // Error: the trait `From<&()>` is not implemented for `()`
    Ok(())
}

```

Currently, developers must resort to awkward workarounds:

1. `result.as_ref().map_err(|_| ())?`
2. `result.as_ref().map_err(|&e| e)?`
3. Converting to an `Option` via `.ok()?`, which loses the semantic intent that the operation was a `Result`.

Given that `()` is a zero sized type and carries no information, a reference to it is logically equivalent to the value itself.

### Proposed Guide-level Explanation

We add an implementation to `core` that allows `&()` to be converted into `()`. Because the `?` operator uses `From::from` for error conversion, this allows `Result<T, &()>` to be used in functions returning `Result<_, ()>`.

### Proposed Change

```rust
impl From<&()> for () {
    #[inline]
    fn from(_: &()) -> Self {
        ()
    }
}

impl From<&mut ()> for () {
    #[inline]
    fn from(_: &mut ()) -> Self {
        ()
    }
}

```

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jrose/32/9591_2.png) [@jrose](https://internals.rust-lang.org/u/jrose)\
**Post date:** [December 20, 2025, 6:46pm UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/2 "2025-12-20T18:46:06Z")

</div>

Why do you have Results using () as their error type? I feel like it’s more common to use a unit struct if there’s really nothing you have to say about the failure, but that doesn’t compose. Without that, the motivation seems kind of weak, even though I don’t see any _harm_ in it.

---

<div class="post-metadata">

**Author:** ![CodesInChaos](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/codesinchaos/32/5211_2.png) [@CodesInChaos](https://internals.rust-lang.org/u/CodesInChaos)\
**Post date:** [December 20, 2025, 9:25pm UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/3 "2025-12-20T21:25:33Z")

</div>

Why do you call this a _blanket_ implementation? This is an implementation for a concrete type, not a generic parameter.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [December 21, 2025, 11:19am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/4 "2025-12-21T11:19:40Z")

</div>

`()` is not a good error type, so I don't think making it easier to use `Result<_, ()>` is a good motivation.

The `From` could be added by libraries generating error boilerplate, e.g.

```rust
#[derive(Error, Copy)]
struct Why;

```

could make `&Why` work too.

---

<div class="post-metadata">

**Author:** ![pitaj](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pitaj/32/11262_2.png) [@pitaj](https://internals.rust-lang.org/u/pitaj)\
**Post date:** [December 21, 2025, 7:15pm UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/5 "2025-12-21T19:15:35Z")

</div>

Yeah it would be good to see some real-world code where you're using `()` as the Err type.

---

<div class="post-metadata">

**Author:** ![zackw](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zackw/32/2071_2.png) [@zackw](https://internals.rust-lang.org/u/zackw)\
**Post date:** [December 22, 2025, 12:32am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/6 "2025-12-22T00:32:16Z")

</div>

I have an (incomplete) project that uses `Result<(), ()>` all over the place, behind a type alias:

```rust
//! The style in this application is to log errors (i.e. report them
//! to the console) as close as possible to the point where they occur,
//! and then pass to higher layers only an indication that the error
//! happened. Those higher layers expect to get a [`LoggedStatus`],
//! which is a type alias for `Result<(), ()>`. We also provide the
//! more general [`LoggedResult<S>`] which is `Result<S, ()>`.

```

> **[~zackw/root-scaffold (main): src/errors/mod.rs - sourcehut git](https://git.sr.ht/~zackw/root-scaffold/tree/main/item/src/errors/mod.rs#L11)**

---

<div class="post-metadata">

**Author:** ![mcmah309](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mcmah309/32/13721_2.png) [@mcmah309](https://internals.rust-lang.org/u/mcmah309)\
**Post date:** [December 22, 2025, 1:03am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/7 "2025-12-22T01:03:03Z")

</div>

Bad phrasing on my part. Thank you for the feedback I changed it.

---

<div class="post-metadata">

**Author:** ![mcmah309](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mcmah309/32/13721_2.png) [@mcmah309](https://internals.rust-lang.org/u/mcmah309)\
**Post date:** [December 22, 2025, 1:13am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/8 "2025-12-22T01:13:10Z")

</div>

I have the exact same use case as @zackw . My use case is a gui application, I handle the error by logging as soon as I know for sure know how to handle it and then maybe present the user with a popup message. I don't want to lose the fact that this is a `Result` and higher up in the call stack (which is usually just one level - page rendering) should not attempt to log or understand the error, just know that an error occurred. So yes there really is nothing to say about the failure, which is the motivation for using.

---

<div class="post-metadata">

**Author:** ![mcmah309](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mcmah309/32/13721_2.png) [@mcmah309](https://internals.rust-lang.org/u/mcmah309)\
**Post date:** [December 22, 2025, 1:20am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/9 "2025-12-22T01:20:49Z")

</div>

See my reply here [[Pre-RFC] Implementation of `From\<&()\>` for `()` - #8 by mcmah309](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/8)

But regardless if you believe the motivation in the use case is sound. It is more about if it makes sense for `&()` to be converted into `()` through a `From` implementation. I.e. does `&()` carry some significance or disconnect that converting into a `()` would not make sense. Since `()` signifies no meaningful value, `&()` a reference to no meaningful value should therefore be easily convertible to `()`. But maybe I could have highlighted that more in the original post.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [December 22, 2025, 3:24am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/10 "2025-12-22T03:24:03Z")

</div>

> [@zackw](#):
>
> ```rust
> //! The style in this application is to log errors (i.e. report them
> //! to the console) as close as possible to the point where they occur,
> //! and then pass to higher layers only an indication that the error
> //! happened. Those higher layers expect to get a [`LoggedStatus`],
> //! which is a type alias for `Result<(), ()>`. We also provide the
> //! more general [`LoggedResult<S>`] which is `Result<S, ()>`.
> 
> ```

Rustc has an approach for this that helps avoid mistakes which, I think, also discourages using `()` for this.

Basically, it has a ZST `struct ErrorReported {}` that's only constructable via something like `ErrorReported::i_solumnly_swear_i_actually_did_report_one()`, but _is_ `Copy`.

That way if you use the normal error reporting paths it gives you back the `ErrorReported` you need, which you put in your `Err`. But also if you've already reported one, you can return that `Err(ErrorReported)` as many times as needed.

But that means if you _don't_ already have an `ErrorReported`, you can't accidentally just `Err(())` thinking that you actually reported one. It means having in instance is a type-level "proof" of having reported something. That way you don't need to be super careful that everyone follows the convention; you just rely on the type checker. (And the easy code review of noticing that someone called `i_solumnly_swear_i_actually_did_report_one` when they shouldn't have.)

TL/DR: use a unit struct error if you want, but don't use `()`.

---

<div class="post-metadata">

**Author:** ![zackw](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zackw/32/2071_2.png) [@zackw](https://internals.rust-lang.org/u/zackw)\
**Post date:** [December 22, 2025, 3:59am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/11 "2025-12-22T03:59:21Z")

</div>

If I ever get back to that project I'll think about using this suggestion. There's pretty tricky error handling code in several places and it _might_ make it easier to be sure it's correct.

---

<div class="post-metadata">

**Author:** ![zirconium-n](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zirconium-n/32/9078_2.png) [@zirconium-n](https://internals.rust-lang.org/u/zirconium-n)\
**Post date:** [December 22, 2025, 7:20am UTC](https://internals.rust-lang.org/t/pre-rfc-implementation-of-from-for/23839/12 "2025-12-22T07:20:34Z")

</div>

Side point, but I do want a help method `as_ref_ok` sometimes:

```rust
impl <T, E> Result<T, E> {
  fn as_ref_ok(self) -> Result<&T, E> {
    match self {
      Result::Ok(t) => Result::Ok(&t),
      Result::Err(e) => Result::Err(e),
    }
  }
}

```

...then I realize the ownership does not workout.

Adding `E: Copy` works but it look weird.

```rust
impl<T, E> Result<T, E> {
    fn as_ref_ok(&self) -> Result<&T, E>
    where
        E: Copy,
    {
        match self {
            Result::Ok(t) => Result::Ok(t),
            Result::Err(e) => Result::Err(*e),
        }
    }
}

```
