Skip to content

Tracking Issue for core::cell::{Ref,RefMut}::try_map #143801

Open

Description

@GrigorenkoPV

Feature gate: #![feature(refcell_try_map)]

This is a tracking issue for core::cell::{Ref,RefMut}::try_map

Public API

impl<'b, T> Ref<'b, T> {
    pub fn try_map<U: ?Sized, E>(
        orig: Ref<'b, T>,
        f: impl FnOnce(&T) -> Result<&U, E>,
    ) -> Result<Ref<'b, U>, (Self, E)> ;
}

impl<'b, T> RefMut<'b, T> {
    pub fn try_map<U: ?Sized, E>(
        mut orig: RefMut<'b, T>,
        f: impl FnOnce(&mut T) -> Result<&mut U, E>,
    ) -> Result<RefMut<'b, U>, (Self, E)>;
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jul 11, 2025
  2. added a commit that references this issue on Aug 14, 2025
  3. added 3 commits that reference this issue on Aug 15, 2025
  4. added a commit that references this issue on Aug 15, 2025
  5. karolzwolak commented on Aug 24, 2025

    @karolzwolak
    Member

    Implementation PR is merged, so @rustbot label -S-tracking-unimplemented

  6. added
    needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.
    on Feb 14, 2026
  7. Mark-Simulacrum commented on Feb 14, 2026

    @Mark-Simulacrum
    Member

    Nominating for libs-api to consider whether an FCP is warranted or we have questions before starting it.

  8. Amanieu commented on Feb 24, 2026

    @Amanieu
    Member

    This was extensively discussed in last week's @rust-lang/libs-api meeting. There were concerns around the fact that the return value doesn't work with ? due to it being a tuple. Instead, the following signature was proposed:

    pub fn try_map<U, E>(
        orig: Ref<'b, T>,
        f: impl FnOnce(&T) -> Result<&U, E>,
    ) -> Result<Ref<'b, U>, TryMapError<'b, T, E>>
    
    impl From<TryMapError<E>> for E { ... }

    This would allow ? to work seamlessly since ? calls .into() on the error type.

  9. Amanieu commented on Feb 24, 2026

    @Amanieu
    Member

    Also, another thing that was discussed in the meeting is that we would like this API to also be provided on MutexGuard, RwLockReadGuard, RwLockWriteGuard and ReentrantLockGuard. Generally these should mirror the API of RefCell guards, since they basically work the same way except for working across threads.

  10. zachs18 commented on Jun 12, 2026

    @zachs18
    Contributor

    Instead, the following signature was proposed:

    From #153093 (comment) It seems like adding impl From<TryMapError<E>> for E { ... } causes type inference failures in some cases due to the single-impl rule no longer applying, e.g.

    use std::fmt;
    struct Foo;
    impl fmt::Debug for Foo {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            let mut w = |name: &str| { // can fix by -> fmt::Result on closure
                f.write_str(name)?;
                Ok(()) // compiler can no longer infer that E = fmt::Error
            };
            w("hello")?;
            Ok(())
        }
    }
    
    fn main() {
        dbg!(Foo);
    }
    error[E0282]: type annotations needed
     --> b.rs:7:13
      |
    7 |             Ok(()) // compiler can no longer infer that this is fmt::Result
      |             ^^ cannot infer type of the type parameter `E` declared on the enum `Result`
      |
    help: consider specifying the generic arguments
      |
    7 |             Ok::<(), E>(()) // compiler can no longer infer that this is fmt::Result
      |               +++++++++
    
    error: aborting due to 1 previous error

    Should a crater run be done?

  11. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions