-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decide on name for derive(SmartPtr)
#129104
Comments
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 I'd rather we use terms we can fully define without confusion. This feels similar to the "object safe" debate in that one aspect. |
One option is to name it in relation to what it enables. For example: @rustbot label F-derive_smart_pointer |
My personal two cents :) #[repr(owned_pointer)] // this also implies `#[repr(transparent)]` somehow
struct MyBox<T: ?Sized>(Box<T>); |
@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 |
I like this principle...
...but neither of these is "self explanatory" to me. What it enables specifically is the possibility of |
It does two things. One, it allows coercions from 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 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();
} |
After discussion on Zulip, Alice and I would like to propose |
I'm going to go ahead and move to merge to move this up the lang priority @rfcbot fcp merge |
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. |
Is it just |
It's general unsizing, since this macro expands to an implementation of |
@rfcbot fcp cancel Canceling FCP because we are live discussing alternatives. |
@nikomatsakis proposal cancelled. |
Update: See here. I'm no longer proposing Maybe the logic below still argues for @rfcbot fcp merge We talked through this in the planning meeting today, and in the end, the proposal is:1 #[derive(UnsizeInner)] So I propose that for FCP merge. Read on for why. (Please see the footnote 1 for some description of the history of proposals.) We rejected We then considered First, and trivially, we'd earlier leaned toward saying Second, we'd just decided to call traits that are compatible with That left us with But there's a meaningful problem with using "dyn" here. The inner type can also be sliced, and that really has nothing to do with it being "dynable". So "dyn" here implies the wrong causality. The true causality is that the things are dynable because they can be unsized, and they can be sliced also because they can be unsized. On that basis, we considered Two observations at this point led to the penultimate solution:
That landed us on
...led to the ultimate proposal here: #[derive(UnsizeInner)] That is, we're asking to get back a type where we can act to unsize the inner type. (In terms of how it sounds, consider, comparably, e.g. That's where we landed. How did we do? What does the rest of the team think? Footnotes
|
Team member @traviscross 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. |
@nikomatsakis By extension, I suppose that we want to switch the attribute of the macro from |
@joshtriplett writes on Zulip:
While I think "referent" is a more elegant name, I don't feel super strongly about this. Looking at the (limited) votes on this comment, I see that @rust-lang/lang or @rust-lang/libs, others want to weigh in? (I recommend you leave an emoji on this comment.) |
@rfcbot resolve pointee-or-referent — oh, wait, I already did |
I checked @joshtriplett's box based on this Zulip comment. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
To reiterate, given the back and forth, what we're FCPing here is the decision to go with: #[derive(CoercePointee)] |
Sure, @rfcbot reviewed |
My only issue with struct Foo<T>(Box<T>);
fn coerce_pointee<'a>(x: Foo<&'static i32>, _: &'a i32) -> Foo<&'a i32> {
x
} Personally I prefer |
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 |
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. |
What name did we end up with? |
|
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. |
The intent is that this will not be in the prelude. |
…to-coerce-referent, r=compiler-errors Rename macro `SmartPointer` to `CoercePointee` As per resolution rust-lang#129104 we will rename the macro to better reflect the technical specification of the feature and clarify the communication. - `SmartPointer` is renamed to `CoerceReferent` - `#[pointee]` attribute is renamed to `#[referent]` - `#![feature(derive_smart_pointer)]` gate is renamed to `#![feature(derive_coerce_referent)]`. - Any mention of `SmartPointer` in the file names are renamed accordingly. r? `@compiler-errors` cc `@nikomatsakis` `@Darksonn`
…-coerce-referent, r=compiler-errors Rename macro `SmartPointer` to `CoercePointee` As per resolution rust-lang#129104 we will rename the macro to better reflect the technical specification of the feature and clarify the communication. - `SmartPointer` is renamed to `CoerceReferent` - `#[pointee]` attribute is renamed to `#[referent]` - `#![feature(derive_smart_pointer)]` gate is renamed to `#![feature(derive_coerce_referent)]`. - Any mention of `SmartPointer` in the file names are renamed accordingly. r? `@compiler-errors` cc `@nikomatsakis` `@Darksonn`
Should this be closed now that #131284 is merged? |
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:
derive(CoercePointee)
#123430The text was updated successfully, but these errors were encountered: