-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add tests related to normalization in implied bounds #118512
Merged
bors
merged 2 commits into
rust-lang:master
from
spastorino:add-implied-bounds-related-tests
Dec 9, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// aux-crate:bevy_ecs=bevy_ecs.rs | ||
// check-pass | ||
// Related to Bevy regression #118553 | ||
|
||
extern crate bevy_ecs; | ||
|
||
use bevy_ecs::*; | ||
|
||
fn handler<'a>(_: ParamSet<Query<&'a u8>>) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// check-pass | ||
// known-bug: #109628 | ||
|
||
trait Trait { | ||
type Assoc; | ||
} | ||
|
||
impl<X: 'static> Trait for (X,) { | ||
type Assoc = (); | ||
} | ||
|
||
struct Foo<T: Trait>(T) | ||
where | ||
T::Assoc: Clone; // any predicate using `T::Assoc` works here | ||
|
||
fn func1(foo: Foo<(&str,)>) { | ||
let _: &'static str = foo.0.0; | ||
} | ||
|
||
trait TestTrait {} | ||
|
||
impl<X> TestTrait for [Foo<(X,)>; 1] {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// check-pass | ||
// Related to Bevy regression #118553 | ||
|
||
pub trait QueryBase { | ||
type Db; | ||
} | ||
|
||
pub trait AsyncQueryFunction<'f>: // 'f is important | ||
QueryBase<Db = <Self as AsyncQueryFunction<'f>>::SendDb> // bound is important | ||
{ | ||
type SendDb; | ||
} | ||
|
||
pub struct QueryTable<'me, Q, DB> { | ||
_q: Option<Q>, | ||
_db: Option<DB>, | ||
_marker: Option<&'me ()>, | ||
} | ||
|
||
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>, | ||
{ | ||
pub fn get_async<'a>(&'a mut self) { | ||
panic!(); | ||
} | ||
} | ||
|
||
fn main() {} |
29 changes: 22 additions & 7 deletions
29
tests/ui/implied-bounds/normalization-nested.lifetime.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement | ||
--> $DIR/normalization-nested.rs:35:20 | ||
--> $DIR/normalization-nested.rs:35:28 | ||
| | ||
LL | pub fn test<'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 | ||
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: aborting due to 1 previous error | ||
error[E0759]: `fn` parameter has lifetime `'x` but it needs to satisfy a `'static` lifetime requirement | ||
--> $DIR/normalization-nested.rs:37:29 | ||
| | ||
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; | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0759`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/ui/implied-bounds/normalization-preserve-equality.borrowck.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/normalization-preserve-equality.rs:24:1 | ||
| | ||
LL | fn test_borrowck<'a, 'b>(_: (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>)) { | ||
| ^^^^^^^^^^^^^^^^^--^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | | | ||
| | | lifetime `'b` defined here | ||
| | lifetime `'a` defined here | ||
| requires that `'a` must outlive `'b` | ||
| | ||
= help: consider adding the following bound: `'a: 'b` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/normalization-preserve-equality.rs:24:1 | ||
| | ||
LL | fn test_borrowck<'a, 'b>(_: (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>)) { | ||
| ^^^^^^^^^^^^^^^^^--^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | | | ||
| | | lifetime `'b` defined here | ||
| | lifetime `'a` defined here | ||
| requires that `'b` must outlive `'a` | ||
| | ||
= help: consider adding the following bound: `'b: 'a` | ||
|
||
help: `'a` and `'b` must be the same: replace one with the other | ||
|
||
error: aborting due to 2 previous errors | ||
|
28 changes: 28 additions & 0 deletions
28
tests/ui/implied-bounds/normalization-preserve-equality.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Both revisions should pass. `borrowck` revision is a bug! | ||
// | ||
// revisions: wfcheck borrowck | ||
// [wfcheck] check-pass | ||
// [borrowck] check-fail | ||
// [borrowck] known-bug: #106569 | ||
|
||
struct Equal<'a, 'b>(&'a &'b (), &'b &'a ()); // implies 'a == 'b | ||
|
||
trait Trait { | ||
type Ty; | ||
} | ||
|
||
impl<'x> Trait for Equal<'x, 'x> { | ||
type Ty = (); | ||
} | ||
|
||
trait WfCheckTrait {} | ||
|
||
#[cfg(wfcheck)] | ||
impl<'a, 'b> WfCheckTrait for (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>) {} | ||
|
||
#[cfg(borrowck)] | ||
fn test_borrowck<'a, 'b>(_: (<Equal<'a, 'b> as Trait>::Ty, Equal<'a, 'b>)) { | ||
let _ = None::<Equal<'a, 'b>>; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// check-pass | ||
// Related to crater regressions on #118553 | ||
|
||
pub trait Debug {} | ||
|
||
pub trait Service { | ||
type Input; | ||
type Output; | ||
type Error; | ||
} | ||
|
||
pub struct ServiceChain<P, S> { | ||
prev: P, | ||
service: S, | ||
} | ||
impl<P: Service, S: Service<Input = P::Output>> Service for ServiceChain<P, S> | ||
where | ||
P::Error: 'static, | ||
S::Error: 'static, | ||
{ | ||
type Input = P::Input; | ||
type Output = S::Output; | ||
type Error = (); | ||
} | ||
|
||
pub struct ServiceChainBuilder<P: Service, S: Service<Input = P::Output>> { | ||
chain: ServiceChain<P, S>, | ||
} | ||
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> { | ||
panic!(); | ||
} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment where this comes from.