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

bevy_reflect: Disambiguate type bounds in where clauses. #8761

Merged
merged 4 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/bevy_reflect/bevy_reflect_derive/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,16 @@ pub(crate) fn extend_where_clause(
} else {
quote!()
};

// The nested parentheses here are required to properly scope HRTBs coming
// from field types to the type itself, as the compiler will scope them to
// the whole bound by default, resulting in a failure to prove trait
// adherence.
generic_where_clause.extend(quote! {
Themayu marked this conversation as resolved.
Show resolved Hide resolved
#(#active_types: #active_trait_bounds,)*
#(#ignored_types: #ignored_trait_bounds,)*
#((#active_types): #active_trait_bounds,)*
#((#ignored_types): #ignored_trait_bounds,)*
// Leave parameter bounds to the end for more sane error messages.
#(#parameter_types: #parameter_trait_bounds,)*
#((#parameter_types): #parameter_trait_bounds,)*
});
generic_where_clause
}
Expand Down
20 changes: 20 additions & 0 deletions crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,26 @@ mod tests {
assert!(info.is::<MyValue>());
}

#[test]
fn should_permit_higher_ranked_lifetimes() {
Themayu marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Reflect)]
struct TestStruct {
#[reflect(ignore)]
_hrl: for<'a> fn(&'a str) -> &'a str,
}

impl Default for TestStruct {
fn default() -> Self {
TestStruct {
_hrl: |input| input,
}
}
}

fn get_type_registration<T: GetTypeRegistration>() {}
get_type_registration::<TestStruct>();
}

#[test]
fn should_permit_valid_represented_type_for_dynamic() {
let type_info = <[i32; 2] as Typed>::type_info();
Expand Down