-
Notifications
You must be signed in to change notification settings - Fork 195
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
ash builder pattern is error prone #866
Comments
Real example of misuse: vulkano-rs/vulkano#2465 |
related: ash-rs/ash#866
It is also warned against in the API docs for every single |
darn I was a bit late then 😅 feel free to close it now or when the change is released. |
#602 doesn't really seem to prevent these mistakes, unless I misunderstand something. As an example, the code below compiles just fine (using the latest git commit 92084df): // Compiles fine but really shouldn't.
fn test() -> ash::vk::SubpassDescription<'static> {
ash::vk::SubpassDescription::default().color_attachments(&[
ash::vk::AttachmentReference {
attachment: 0,
layout: ash::vk::ImageLayout::UNDEFINED,
},
])
} |
@tomaka what is wrong about that example? The slice has a |
In your example, the array literal is getting promoted to having a static lifetime. Try using a dynamic value in it to prevent this, and observe that it will no longer compile. |
Many of the builder methods take references with lifetime, such as DeviceCreateInfoBuilder::queue_create_infos, but have a final
.build()
which returns something without a lifetime. This leads me to believe falsely the returned struct holds a copy of the passed arguments internally, thus not limited by the source lifetime. But this is not the case, ash converts the passed references to pointers, which means the passed arguments must live longer than the returned value.No where in documentation was this mentioned. And the API is designed in such a way that makes leveraging the borrow checker impossible. I suggest the return from builders should retain the lifetime of the builder.
The text was updated successfully, but these errors were encountered: