-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Trait bounds not properly propagated in #[derive(SmartPointer)]
#127647
Comments
Note this is a pretty incomplete feature so there may be some things that just haven't gotten updated yet, but it is good to have the bug report. @rustbot label +F-derive_smart_pointer +T-compiler -needs-triage |
Thank you for catching this. It looks like we will need this to be fixed before we can use the macro for its intended purpose with linked lists, as the relevant smart pointer is defined with a trait bound: #[repr(transparent)]
pub struct ListArc<T, const ID: u64 = 0>
where
T: ListArcSafe<ID> + ?Sized,
{
arc: Arc<T>,
} It would make sense to add a test that ensures that the relevant parts of the linked list example compiles. (link 1, link 2). |
Oh, I've just noticed that when you expand the macro the bounds are not applied to the |
cc @Darksonn I have one open question. There could be more convoluted bounds that involves the pointee type like the following. #[derive(SmartPointer)]
#[repr(transparent)]
pub struct Ptr<#[pointee] T>
where
T: Trait<T>,
{ .. }
pub trait Trait<U> { .. } For now, #127681 does not rewrite |
This is what I have in the RFC:
Does that work? |
Okay #127681 is updated, so that given a So now
Tests are added for these cases. |
… r=compiler-errors derive(SmartPointer): rewrite bounds in where and generic bounds Fix rust-lang#127647 Due to the `Unsize` bounds, we need to commute the bounds on the pointee type to the new self type. cc `@Darksonn`
… r=compiler-errors derive(SmartPointer): rewrite bounds in where and generic bounds Fix rust-lang#127647 Due to the `Unsize` bounds, we need to commute the bounds on the pointee type to the new self type. cc ``@Darksonn``
Rollup merge of rust-lang#127681 - dingxiangfei2009:smart-ptr-bounds, r=compiler-errors derive(SmartPointer): rewrite bounds in where and generic bounds Fix rust-lang#127647 Due to the `Unsize` bounds, we need to commute the bounds on the pointee type to the new self type. cc ```@Darksonn```
When deriving
SmartPointer
on a struct with additional bounds the resultingimpl
is missing a bound resulting in a compile error. This behavior was not explicitly mentioned inSmartPointer
RFC, so I assume it's a bug. See #123430I tried this code: (playground)
I expected to see this happen: the code compiles and provides a smart pointer that executes
on_drop
when the smart pointer is dropped.Instead, this happened: compile error:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: