Skip to content

Commit 4cd0f76

Browse files
committed
Add #[smart_pointer::pointee]
1 parent 211abb3 commit 4cd0f76

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

text/3621-derive-smart-pointer.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ Point 1 and 2 are verified syntactically by the derive macro, whereas 3 and 4
264264
are verified semantically by the compiler when checking the generated
265265
[`DispatchFromDyn`] implementation as it does today.
266266

267+
The `#[pointee]` attribute may also be written as `#[smart_pointer::pointee]`.
268+
267269
## Expansion
268270

269271
The macro will expand to two implementations, one for
@@ -486,6 +488,30 @@ refcounted value with multiple lists. People have argued that it would be
486488
better to change this to a generic type instead of a const generic, so it would
487489
be useful to keep the option of having multiple generic types on the struct.
488490

491+
### Conflicts with third-party derive macros
492+
493+
The `#[pointee]` attribute could in principle conflict with other derive macros
494+
that also wish to annotate one of the parameters with an attribute called
495+
`#[pointee]`. To disambiguate such cases, we also allow the attribute to be
496+
spelled `#[smart_pointer::pointee]`.
497+
498+
It is an error to specify both `#[pointee]` and `#[smart_pointer::pointee]`, so
499+
both macros must support this kind of disambiguation.
500+
501+
Another way to avoid conflicts between `#[derive(SmartPointer)]` and third-party
502+
macros is to always assume that the first generic parameter is the pointee.
503+
This RFC does not propose that solution because:
504+
505+
* It prevents the pointee from having a default unless it is the only parameter,
506+
because parameters with a default must come last.
507+
* If logic such as "the first parameter" becomes commonplace in macro design,
508+
then it does not really solve the issue with conflicts: you could have two
509+
macros that both assume that the first parameter is special. And this kind of
510+
conflict will be more common than attribute conflicts, because the attribute
511+
will only conflict if both macros use an attribute of the same name.
512+
513+
The authors are not aware of any macros using a `#[pointee]` attribute today.
514+
489515
# Prior art
490516
[prior-art]: #prior-art
491517

0 commit comments

Comments
 (0)