Skip to content

Commit c591475

Browse files
committedSep 25, 2024·
Add a few more tests, comments
1 parent 149bd87 commit c591475

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
 

‎compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+6
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>(
173173
))
174174
}
175175

176+
/// Given some where clause like `for<'b, 'c> <Self as Trait<'a_identity>>::Gat<'b>: Bound<'c>`,
177+
/// the mapping will map `'b` back to the GAT's `'b_identity`. Then we need to compress the
178+
/// remaining bound var `'c` to index 0.
179+
///
180+
/// This folder gives us: `for<'c> <Self as Trait<'a_identity>>::Gat<'b_identity>: Bound<'c>`,
181+
/// which is sufficient for an item bound for `Gat`, since all of the GAT's args are identity.
176182
struct MapAndCompressBoundVars<'tcx> {
177183
tcx: TyCtxt<'tcx>,
178184
/// How deep are we? Makes sure we don't touch the vars of nested binders.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Demonstrates a mostly-theoretical inference guidance now that we turn the where
2+
// clause on `Trait` into an item bound, given that we prefer item bounds somewhat
3+
// greedily in trait selection.
4+
5+
trait Bound<T> {}
6+
impl<T, U> Bound<T> for U {}
7+
8+
trait Trait
9+
where
10+
<<Self as Trait>::Assoc as Other>::Assoc: Bound<u32>,
11+
{
12+
type Assoc: Other;
13+
}
14+
15+
trait Other {
16+
type Assoc;
17+
}
18+
19+
fn impls_trait<T: Bound<U>, U>() -> Vec<U> { vec![] }
20+
21+
fn foo<T: Trait>() {
22+
let mut vec_u = impls_trait::<<<T as Trait>::Assoc as Other>::Assoc, _>();
23+
vec_u.sort();
24+
drop::<Vec<u8>>(vec_u);
25+
//~^ ERROR mismatched types
26+
}
27+
28+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/nested-associated-type-bound-incompleteness.rs:24:21
3+
|
4+
LL | drop::<Vec<u8>>(vec_u);
5+
| --------------- ^^^^^ expected `Vec<u8>`, found `Vec<u32>`
6+
| |
7+
| arguments to this function are incorrect
8+
|
9+
= note: expected struct `Vec<u8>`
10+
found struct `Vec<u32>`
11+
note: function defined here
12+
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ check-pass
2+
3+
trait Trait
4+
where
5+
for<'a> Self::Gat<'a>: OtherTrait,
6+
for<'a, 'b, 'c> <Self::Gat<'a> as OtherTrait>::OtherGat<'b>: HigherRanked<'c>,
7+
{
8+
type Gat<'a>;
9+
}
10+
11+
trait OtherTrait {
12+
type OtherGat<'b>;
13+
}
14+
15+
trait HigherRanked<'c> {}
16+
17+
fn lower_ranked<T: for<'b, 'c> OtherTrait<OtherGat<'b>: HigherRanked<'c>>>() {}
18+
19+
fn higher_ranked<T: Trait>()
20+
where
21+
for<'a> T::Gat<'a>: OtherTrait,
22+
for<'a, 'b, 'c> <T::Gat<'a> as OtherTrait>::OtherGat<'b>: HigherRanked<'c>,
23+
{
24+
}
25+
26+
fn test<T: Trait>() {
27+
lower_ranked::<T::Gat<'_>>();
28+
higher_ranked::<T>();
29+
}
30+
31+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.