Skip to content

Decide on name for derive(SmartPtr) #129104

Closed

Description

@traviscross

We need to resolve the open question on:

...regarding what name to use for the thing formerly known an #[derive(SmartPtr)] or #[derive(SmartPointer)].

Tracking:

Activity

  1. added
    T-langRelevant to the language team
    C-discussionCategory: Discussion or questions that doesn't represent real issues.
    I-lang-nominatedNominated for discussion during a lang team meeting.
    on Aug 14, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 14, 2024
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 14, 2024
  4. ChrisDenton commented on Aug 14, 2024

    @ChrisDenton
    Member

    I'll say I don't like the term "smart pointer" in Rust. It has a more specific meaning in C++ but porting that terminology over to Rust has been less than smooth. Like the Deref docs still imply that anything implementing the Deref trait is a "smart pointer" which is a bit of stretch on its own. But now #[derive(SmartPtr)] doesn't imply Deref and everything gets even more muddy.

    I'd rather we use terms we can fully define without confusion. This feels similar to the "object safe" debate in that one aspect.

  5. Darksonn commented on Aug 15, 2024

    @Darksonn
    Member

    One option is to name it in relation to what it enables. For example: #[derive(DynamicDispatch)] or #[derive(DynamicPtr)].

    @rustbot label F-derive_smart_pointer

  6. crlf0710 commented on Aug 31, 2024

    @crlf0710
    Member

    My personal two cents :)

    #[repr(owned_pointer)] // this also implies `#[repr(transparent)]` somehow
    struct MyBox<T: ?Sized>(Box<T>);
  7. Darksonn commented on Sep 26, 2024

    @Darksonn
    Member

    @crlf0710 Owned pointer is not good because it can be used with pointers that don't have ownership of the value.

    I propose to use the name #[derive(DynamicPtr)]. Any objections?

  8. nikomatsakis commented on Oct 2, 2024

    @nikomatsakis
    Contributor

    One option is to name it in relation to what it enables

    I like this principle...

    For example: #[derive(DynamicDispatch)] or #[derive(DynamicPtr)].

    ...but neither of these is "self explanatory" to me. What it enables specifically is the possibility of self: MyType<dyn Bar> appearing in traits and supporting dynamic dispatch, basically? Is that it? I am trying to page this back in.

  9. Darksonn commented on Oct 2, 2024

    @Darksonn
    Member

    It does two things. One, it allows coercions from MySmartPointer<ConcreteType> to MySmartPointer<dyn MyTrait>.

    fn main() {
        let ptr: MySmartPointer<i32> = MySmartPointer(Box::new(4));
    
        // This coercion would be an error without the derive.
        let ptr: MySmartPointer<dyn MyTrait> = ptr;
    }

    The other thing is that it makes self: MySmartPointer<Self> object-safe in traits.

    trait MyTrait {
        // Arbitrary self types is enough for this.
        fn func(self: MySmartPointer<Self>);
    }
    
    // But this requires #[derive(SmartPointer)].
    fn call_func(value: MySmartPointer<dyn MyTrait>) {
        value.func();
    }
  10. nikomatsakis commented on Oct 2, 2024

    @nikomatsakis
    Contributor

    After discussion on Zulip, Alice and I would like to propose derive(DynCapablePointer).

  11. nikomatsakis commented on Oct 2, 2024

    @nikomatsakis
    Contributor

    I'm going to go ahead and move to merge to move this up the lang priority

    @rfcbot fcp merge

  12. rfcbot commented on Oct 2, 2024

    @rfcbot

    Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged team members:

    No concerns currently listed.

    Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

    cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
    See this document for info about what commands tagged team members can give me.

  13. 70 remaining items

  14. tmandry commented on Oct 11, 2024

    @tmandry
    Member

    That's true. I think I'm okay with it because we still allow the other kinds of coercion that make sense for a pointer (your code sample already compiles, in other words). I can't think of another kind of coercion we would want to allow behind a pointer type that isn't either already allowed or covered by this derive.

    On a related note, I don't hate the idea of sticking with the already established CoerceUnsized, but I do think both CoercePointee and UnsizePointee are better and clearer, and I still prefer the first (which are are FCP'ing).

  15. added
    to-announceAnnounce this issue on triage meeting
    and removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Oct 19, 2024
  16. rfcbot commented on Oct 19, 2024

    @rfcbot

    The final comment period, with a disposition to merge, as per the review above, is now complete.

    As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

    This will be merged soon.

  17. Darksonn commented on Oct 22, 2024

    @Darksonn
    Member

    What name did we end up with?

  18. lqd commented on Oct 22, 2024

    @lqd
    Member

    CoercePointee, cf #129104 (comment) — though maybe whether the std::marker:: prefix is indeed required (from #129104 (comment)) could use one last clarification :3

  19. tmandry commented on Oct 23, 2024

    @tmandry
    Member

    I think it would still be required, I don't recall any discussion about the path and my understanding was that this would not be in the standard prelude to begin with.

  20. Darksonn commented on Oct 23, 2024

    @Darksonn
    Member

    The intent is that this will not be in the prelude.

  21. added a commit that references this issue on Oct 27, 2024
  22. added a commit that references this issue on Oct 27, 2024
  23. Darksonn commented on Nov 15, 2024

    @Darksonn
    Member

    Should this be closed now that #131284 is merged?

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-discussionCategory: Discussion or questions that doesn't represent real issues.F-derive_coerce_pointeeFeature: RFC 3621's oft-renamed implementationT-langRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions