-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Collect relevant item bounds from trait clauses for nested rigid projections #120752
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 hidden or 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/associated-type-bounds/nested-associated-type-bound-incompleteness.rs
This file contains hidden or 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 @@ | ||
// Demonstrates a mostly-theoretical inference guidance now that we turn the where | ||
// clause on `Trait` into an item bound, given that we prefer item bounds somewhat | ||
// greedily in trait selection. | ||
|
||
trait Bound<T> {} | ||
impl<T, U> Bound<T> for U {} | ||
|
||
trait Trait | ||
where | ||
<<Self as Trait>::Assoc as Other>::Assoc: Bound<u32>, | ||
{ | ||
type Assoc: Other; | ||
} | ||
|
||
trait Other { | ||
type Assoc; | ||
} | ||
|
||
fn impls_trait<T: Bound<U>, U>() -> Vec<U> { vec![] } | ||
|
||
fn foo<T: Trait>() { | ||
let mut vec_u = impls_trait::<<<T as Trait>::Assoc as Other>::Assoc, _>(); | ||
vec_u.sort(); | ||
drop::<Vec<u8>>(vec_u); | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn main() {} |
16 changes: 16 additions & 0 deletions
16
tests/ui/associated-type-bounds/nested-associated-type-bound-incompleteness.stderr
This file contains hidden or 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,16 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/nested-associated-type-bound-incompleteness.rs:24:21 | ||
| | ||
LL | drop::<Vec<u8>>(vec_u); | ||
| --------------- ^^^^^ expected `Vec<u8>`, found `Vec<u32>` | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected struct `Vec<u8>` | ||
found struct `Vec<u32>` | ||
note: function defined here | ||
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains hidden or 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 | ||
|
||
trait Trait | ||
where | ||
for<'a> Self::Gat<'a>: OtherTrait, | ||
for<'a, 'b, 'c> <Self::Gat<'a> as OtherTrait>::OtherGat<'b>: HigherRanked<'c>, | ||
{ | ||
type Gat<'a>; | ||
} | ||
|
||
trait OtherTrait { | ||
type OtherGat<'b>; | ||
} | ||
|
||
trait HigherRanked<'c> {} | ||
|
||
fn lower_ranked<T: for<'b, 'c> OtherTrait<OtherGat<'b>: HigherRanked<'c>>>() {} | ||
|
||
fn higher_ranked<T: Trait>() | ||
where | ||
for<'a> T::Gat<'a>: OtherTrait, | ||
for<'a, 'b, 'c> <T::Gat<'a> as OtherTrait>::OtherGat<'b>: HigherRanked<'c>, | ||
{ | ||
} | ||
|
||
fn test<T: Trait>() { | ||
lower_ranked::<T::Gat<'_>>(); | ||
higher_ranked::<T>(); | ||
} | ||
|
||
fn main() {} |
28 changes: 28 additions & 0 deletions
28
tests/ui/associated-types/imply-relevant-nested-item-bounds-2.rs
This file contains hidden or 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 @@ | ||
//@ check-pass | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
trait Trait | ||
where | ||
Self::Assoc: Clone, | ||
{ | ||
type Assoc; | ||
} | ||
|
||
fn foo<T: Trait>(x: &T::Assoc) -> T::Assoc { | ||
x.clone() | ||
} | ||
|
||
trait Trait2 | ||
where | ||
Self::Assoc: Iterator, | ||
<Self::Assoc as Iterator>::Item: Clone, | ||
{ | ||
type Assoc; | ||
} | ||
|
||
fn foo2<T: Trait2>(x: &<T::Assoc as Iterator>::Item) -> <T::Assoc as Iterator>::Item { | ||
x.clone() | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
tests/ui/associated-types/imply-relevant-nested-item-bounds-for-gat.rs
This file contains hidden or 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,19 @@ | ||
//@ check-pass | ||
|
||
// Test that `for<'a> Self::Gat<'a>: Debug` is implied in the definition of `Foo`, | ||
// just as it would be if it weren't a GAT but just a regular associated type. | ||
|
||
use std::fmt::Debug; | ||
|
||
trait Foo | ||
where | ||
for<'a> Self::Gat<'a>: Debug, | ||
{ | ||
type Gat<'a>; | ||
} | ||
|
||
fn test<T: Foo>(x: T::Gat<'static>) { | ||
println!("{:?}", x); | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.