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

Reflect proc-macro causes compile errors when using custom Result type #3004

Closed
kyunghoon opened this issue Oct 22, 2021 · 5 comments
Closed
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@kyunghoon
Copy link

Bevy version

v0.5.0

Operating system & version

MacOS 11.4

What you did

used the Reflect proc-macro

What you expected to happen

compile successfully

What actually happened

compile error, conflicting Result types

Additional information

the derive_reflect process macro is not hygienic, i prefer to use my own specialized Result type which only has one generic parameter. this macro mistakenly picks it up. fix is pretty easy, i could make a PR if quested.

@kyunghoon kyunghoon added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 22, 2021
@mockersf
Copy link
Member

Could you provide a code sample to reproduce the issue? If you identified the root cause, a PR would be nice 🙂

@alice-i-cecile alice-i-cecile added A-Reflection Runtime information about types S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Oct 22, 2021
@ThrashAbaddon
Copy link

@kyunghoon Do you have a code example that maintainers can use to reproduce the issue?

@MrGVSV
Copy link
Member

MrGVSV commented Oct 18, 2022

Sounds like this is due to the proc macro not specifying the fully qualified path to Result (i.e. ::core::result::Result). This seems like it would be a trivial fix and should probably be done for Option (::core::option::Option) as well.

@elbertronnie
Copy link
Contributor

I would like to solve this issue. But being new to Rust and this codebase, I wanted to clarify a few things:

  • I have to replace Result, Option and their respective variants which are inside quote! with its fully qualified name.
  • Do I have to do this in only bevy_reflect_derive crate or all the proc macros across the codebase?
  • Why were only Result and Option chosen? Is it because they are often specialized? Should I do the same for other members of core and std too (like Default or Vec)?

@MrGVSV
Copy link
Member

MrGVSV commented Nov 15, 2022

I would like to solve this issue. But being new to Rust and this codebase, I wanted to clarify a few things:

Awesome! Glad to have you on board! Contributing to something like Bevy is a great way to learn Rust, honestly. Feel free to shoot a message on Discord (#engine-dev or #reflection-dev are good places to start) if you need help.

I'd recommend maybe getting some feedback there first. I imagine there might be people opposed to this change as it adds verbosity for something that people "generally shouldn't do" like shadow the name of a type in Rust's prelude.

I have to replace Result, Option and their respective variants which are inside quote! with its fully qualified name.

Yep! Anywhere we generate code, we should probably be using the fully-qualified path, which is most often in the quote! macro.

For example, you would change quote!(Some(123)) to quote!(::core::option::Option::Some(123)).

Do I have to do this in only bevy_reflect_derive crate or all the proc macros across the codebase?

Possibly. It might be better to break things up as messing with a bunch of crates generally requires a lot more review. Maybe just start with bevy_reflect_derive?

Why were only Result and Option chosen? Is it because they are often specialized? Should I do the same for other members of core and std too (like Default or Vec)?

They were chosen because they were the first ones to come to mind :)

But yes, that list is not exhaustive. Vec, Box, etc. could also be included in this.

@bors bors bot closed this as completed in f9c52f9 Dec 5, 2022
ickshonpe pushed a commit to ickshonpe/bevy that referenced this issue Dec 6, 2022
# Objective

- Fixes bevyengine#3004 

## Solution

- Replaced all the types with their fully quallified names
- Replaced all trait methods and inherent methods on dyn traits with their fully qualified names
- Made a new file `fq_std.rs` that contains structs corresponding to commonly used Structs and Traits from `std`. These structs are replaced by their respective fully qualified names when used inside `quote!`
alradish pushed a commit to alradish/bevy that referenced this issue Jan 22, 2023
# Objective

- Fixes bevyengine#3004 

## Solution

- Replaced all the types with their fully quallified names
- Replaced all trait methods and inherent methods on dyn traits with their fully qualified names
- Made a new file `fq_std.rs` that contains structs corresponding to commonly used Structs and Traits from `std`. These structs are replaced by their respective fully qualified names when used inside `quote!`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

- Fixes bevyengine#3004 

## Solution

- Replaced all the types with their fully quallified names
- Replaced all trait methods and inherent methods on dyn traits with their fully qualified names
- Made a new file `fq_std.rs` that contains structs corresponding to commonly used Structs and Traits from `std`. These structs are replaced by their respective fully qualified names when used inside `quote!`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

6 participants