Correctly handle normalization in implied bounds

Special-case Bevy dependents to not error
This commit is contained in:
Ali MJ Al-Nasrawy 2023-12-10 20:13:21 -05:00 committed by Jack Huey
parent 6ae4cfbbb0
commit d96003dd2a
20 changed files with 375 additions and 170 deletions

View file

@ -1,18 +0,0 @@
// Related to Bevy regression #118553
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;

View file

@ -1,11 +1,26 @@
// aux-crate:bevy_ecs=bevy_ecs.rs
// check-pass
// Related to Bevy regression #118553
extern crate bevy_ecs;
// We currently special case bevy from erroring on incorrect implied bounds
// from normalization (issue #109628).
// Otherwise, we would expect this to hit that error.
use 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>(_: ParamSet<Query<&'a u8>>) {}
fn ref_handler<'a>(_: &ParamSet<Query<&'a u8>>) {}
fn main() {}

View file

@ -1,6 +1,3 @@
// check-pass
// known-bug: #109628
trait Trait {
type Assoc;
}
@ -14,11 +11,13 @@ where
T::Assoc: Clone; // any predicate using `T::Assoc` works here
fn func1(foo: Foo<(&str,)>) {
//~^ ERROR `&str` does not fulfill the required lifetime
let _: &'static str = foo.0.0;
}
trait TestTrait {}
impl<X> TestTrait for [Foo<(X,)>; 1] {}
//~^ ERROR `X` may not live long enough
fn main() {}

View file

@ -0,0 +1,26 @@
error[E0477]: the type `&str` does not fulfill the required lifetime
--> $DIR/from-trait-impl.rs:13:15
|
LL | fn func1(foo: Foo<(&str,)>) {
| ^^^^^^^^^^^^
|
= note: type must satisfy the static lifetime
error[E0310]: the parameter type `X` may not live long enough
--> $DIR/from-trait-impl.rs:20:23
|
LL | impl<X> TestTrait for [Foo<(X,)>; 1] {}
| ^^^^^^^^^^^^^^
| |
| the parameter type `X` must be valid for the static lifetime...
| ...so that the type `X` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
LL | impl<X: 'static> TestTrait for [Foo<(X,)>; 1] {}
| +++++++++
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0310, E0477.
For more information about an error, try `rustc --explain E0310`.

View file

@ -1,5 +1,5 @@
// check-pass
// Related to Bevy regression #118553
// Found in a crater run on #118553
pub trait QueryBase {
type Db;
@ -17,8 +17,7 @@ pub struct QueryTable<'me, Q, DB> {
_marker: Option<&'me ()>,
}
impl<'me, Q> QueryTable<'me, Q, <Q as QueryBase>::Db>
// projection is important
impl<'me, Q> QueryTable<'me, Q, <Q as QueryBase>::Db> // projection is important
// ^^^ removing 'me (and in QueryTable) gives a different error
where
Q: for<'f> AsyncQueryFunction<'f>,

View file

@ -1,33 +1,10 @@
error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/normalization-nested.rs:35:28
|
LL | pub fn test_wfcheck<'x>(_: Map<Vec<&'x ()>>) {}
| ^^^^^^^^^^^^^^^^
| |
| this data with lifetime `'x`...
| ...is used and required to live as long as `'static` here
|
note: `'static` lifetime requirement introduced by this bound
--> $DIR/normalization-nested.rs:33:14
|
LL | I::Item: 'static;
| ^^^^^^^
error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement
--> $DIR/normalization-nested.rs:37:29
error: lifetime may not live long enough
--> $DIR/normalization-nested.rs:38:5
|
LL | pub fn test_borrowck<'x>(_: Map<Vec<&'x ()>>, s: &'x str) -> &'static str {
| ^^^^^^^^^^^^^^^^
| |
| this data with lifetime `'x`...
| ...is used and required to live as long as `'static` here
|
note: `'static` lifetime requirement introduced by this bound
--> $DIR/normalization-nested.rs:33:14
|
LL | I::Item: 'static;
| ^^^^^^^
| -- lifetime `'x` defined here
LL | s
| ^ returning this value requires that `'x` must outlive `'static`
error: aborting due to 2 previous errors
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0759`.

View file

@ -1,5 +1,4 @@
// check-pass
// Related to crater regressions on #118553
// Found in a crater run on #118553
pub trait Debug {}
@ -30,6 +29,9 @@ impl<P: Service, S: Service<Input = P::Output>> ServiceChainBuilder<P, S> {
pub fn next<NS: Service<Input = S::Output>>(
self,
) -> ServiceChainBuilder<ServiceChain<P, S>, NS> {
//~^ the associated type
//~| the associated type
//~| the associated type
panic!();
}
}

View file

@ -0,0 +1,31 @@
error[E0310]: the associated type `<P as Service>::Error` may not live long enough
--> $DIR/sod_service_chain.rs:31:10
|
LL | ) -> ServiceChainBuilder<ServiceChain<P, S>, NS> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the associated type `<P as Service>::Error` must be valid for the static lifetime...
| ...so that the type `<P as Service>::Error` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
LL | ) -> ServiceChainBuilder<ServiceChain<P, S>, NS> where <P as Service>::Error: 'static {
| ++++++++++++++++++++++++++++++++++++
error[E0310]: the associated type `<S as Service>::Error` may not live long enough
--> $DIR/sod_service_chain.rs:31:10
|
LL | ) -> ServiceChainBuilder<ServiceChain<P, S>, NS> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the associated type `<S as Service>::Error` must be valid for the static lifetime...
| ...so that the type `<S as Service>::Error` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
LL | ) -> ServiceChainBuilder<ServiceChain<P, S>, NS> where <S as Service>::Error: 'static {
| ++++++++++++++++++++++++++++++++++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0310`.