Skip to content
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

Derives ignore const generics #2037

Closed
TehPers opened this issue Apr 28, 2021 · 0 comments
Closed

Derives ignore const generics #2037

TehPers opened this issue Apr 28, 2021 · 0 comments
Labels
C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change

Comments

@TehPers
Copy link
Contributor

TehPers commented Apr 28, 2021

Bevy version

0.5

Operating system & version

Windows 10 (not sure this matters)

What you did

I tried deriving RenderResources and TypeUuid for a struct with const generics:

#[derive(Debug, RenderResources, TypeUuid)]
#[uuid = "d6cb24b8-4e4a-4bca-87c5-fa500618a8f0"]
struct Foo<const N: u32> {
    value: u32,
}

What you expected to happen

It should have included the const type parameters in the implementation.

What actually happened

It didn't include the const type parameters:

#[uuid = "d6cb24b8-4e4a-4bca-87c5-fa500618a8f0"]
struct Foo<const N: u32> {
    value: u32,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl<const N: u32> ::core::fmt::Debug for Foo<N> {
    /* <snip> */
}
static FOO_RENDER_RESOURCE_NAMES: &[&str] = &["Foo_value"];
static FOO_RENDER_RESOURCE_HINTS: &[Option<bevy_render::renderer::RenderResourceHints>] =
    &[None];
impl bevy_render::renderer::RenderResources for Foo {
    fn render_resources_len(&self) -> usize {
        1usize
    }
    fn get_render_resource(
        &self,
        index: usize,
    ) -> Option<&dyn bevy_render::renderer::RenderResource> {
        match index {
            0usize => Some(&self.value),
            _ => None,
        }
    }
    fn get_render_resource_name(&self, index: usize) -> Option<&str> {
        FOO_RENDER_RESOURCE_NAMES.get(index).copied()
    }
    fn get_render_resource_hints(
        &self,
        index: usize,
    ) -> Option<bevy_render::renderer::RenderResourceHints> {
        FOO_RENDER_RESOURCE_HINTS.get(index).and_then(|o| *o)
    }
    fn iter(&self) -> bevy_render::renderer::RenderResourceIterator {
        bevy_render::renderer::RenderResourceIterator::new(self)
    }
}
impl bevy_reflect::TypeUuid for Foo {
    const TYPE_UUID: bevy_reflect::Uuid = bevy_reflect::Uuid::from_bytes([
        0xD6, 0xCB, 0x24, 0xB8, 0x4E, 0x4A, 0x4B, 0xCA, 0x87, 0xC5, 0xFA, 0x50, 0x6, 0x18,
        0xA8, 0xF0,
    ]);
}
@TehPers TehPers added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 28, 2021
@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change and removed S-Needs-Triage This issue needs to be labelled labels Apr 29, 2021
@bors bors bot closed this as completed in b07db84 May 1, 2021
ostwilkens pushed a commit to ostwilkens/bevy that referenced this issue Jul 27, 2021
Fixes bevyengine#2037 (and then some)

Problem:
- `TypeUuid`, `RenderResource`, and `Bytes` derive macros did not properly handle generic structs. 

Solution:
- Rework the derive macro implementations to handle the generics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants