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 implied bounds hack no longer works #164

Open
lcnr opened this issue Feb 18, 2025 · 2 comments · May be fixed by rust-lang/rust#137398
Open

bevy implied bounds hack no longer works #164

lcnr opened this issue Feb 18, 2025 · 2 comments · May be fixed by rust-lang/rust#137398

Comments

@lcnr
Copy link
Contributor

lcnr commented Feb 18, 2025

affected test

  • tests/ui/implied-bounds/bevy_world_query.rs

somewhat unsure about why this happens, but

// Needed due to <https://github.com/rust-lang/rust/pull/137253>.
#![crate_name = "bevy_ecs"]

pub trait WorldQuery {}
impl WorldQuery for &u8 {}

pub struct Query<Q: WorldQuery>(Q);

pub trait SystemParam {
    type State;
}
impl<Q: WorldQuery + 'static> SystemParam for Query<Q> {
    type State = ();
    // `Q: 'static` is required because we need the TypeId of Q ...
}

pub struct ParamSet<T: SystemParam>(T) where T::State: Sized;

fn handler<'a>(x: ParamSet<Query<&'a u8>>) {
    let _: ParamSet<_> = x;
}

fn ref_handler<'a>(_: &ParamSet<Query<&'a u8>>) {}

now errors with "the type &'a u8 does not fulfill the required lifetime"

@compiler-errors
Copy link
Member

In the implied bounds compat query, we use the "regular" wf with normalization:
https://github.com/rust-lang/rust/blob/ed49386d3aa3a445a9889707fd405df01723eced/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs#L180

That normalizes obligations using normalize_with_depth_to:
https://github.com/rust-lang/rust/blob/ed49386d3aa3a445a9889707fd405df01723eced/compiler/rustc_trait_selection/src/traits/wf.rs#L360

...Which instead of registering the type outlives obligation into the infcx's region storage (which when normalizing a <Query<&'a u8> as SystemParam>::State: Sized wf predicate, gives us &'a u8: 'static from the impl), it just puts it into the vec of wf clauses.

In the new solver, even if we were to use deeply_normalize on the wf predicate here:
https://github.com/rust-lang/rust/blob/ed49386d3aa3a445a9889707fd405df01723eced/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs#L209

...we would still need to manually take the type outlives obligation that has been registered as part of normalizing the type out of the infcx here:
https://github.com/rust-lang/rust/blob/ed49386d3aa3a445a9889707fd405df01723eced/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs#L253

@compiler-errors
Copy link
Member

I think it's doable, and the fallout is likely very small b/c it's just for the compat hack (which I recently even reduced the scope of rust-lang/rust#137253).

@lcnr lcnr moved this from unknown to done in -Znext-solver=globally Feb 22, 2025
@lcnr lcnr moved this from done to in progress in -Znext-solver=globally Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: in progress
Development

Successfully merging a pull request may close this issue.

2 participants