Skip to content

Commit 07216f6

Browse files
committed
add tests for the check and enhanced alias bound assembly
1 parent 354f5ca commit 07216f6

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//@ check-pass
2+
//@ compile-flags: -Znext-solver
3+
4+
// If the rhs of a projection predicate is generic, then we imply item bounds of the associated
5+
// types on it.
6+
7+
trait Trait {
8+
type Assoc: Copy;
9+
}
10+
11+
trait Explicit {}
12+
impl<T: Trait<Assoc = U>, U: Copy> Explicit for T {}
13+
14+
fn assert_explicit<T: Explicit>() {}
15+
fn imply_copy<T: Trait<Assoc = U>, U>() {
16+
assert_explicit::<T>();
17+
}
18+
19+
20+
trait BoundA {}
21+
22+
trait HasBoundA {
23+
type AssocA: BoundA;
24+
}
25+
26+
trait BoundB {}
27+
trait HasBoundB {
28+
type AssocB: BoundB;
29+
}
30+
31+
fn imply_both<T, U>()
32+
where
33+
T: HasBoundA<AssocA = U> + HasBoundB<AssocB = U>,
34+
{
35+
assert_both::<U>();
36+
}
37+
38+
fn assert_both<T: BoundA + BoundB>() {}
39+
40+
fn main() {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Projection predicate's WFedness requires that the rhs term satisfy all item bounds defined on the
2+
// associated type.
3+
// Generic types have those bounds implied.
4+
5+
trait Required {}
6+
7+
trait AssocHasBound {
8+
type Assoc: Required;
9+
}
10+
11+
trait Trait<T> {
12+
type Assoc1: AssocHasBound<Assoc = i32>;
13+
//~^ ERROR: the trait bound `i32: Required` is not satisfied [E0277]
14+
type Assoc2: AssocHasBound<Assoc = T>;
15+
type Assoc3: AssocHasBound<Assoc = Self::DummyAssoc>;
16+
type DummyAssoc;
17+
}
18+
19+
fn some_func<T1, T2, U>()
20+
where
21+
T1: AssocHasBound<Assoc = i32>,
22+
//~^ ERROR: type annotations needed [E0284]
23+
T1: AssocHasBound<Assoc = U>,
24+
{}
25+
26+
fn opaque_with_concrete_assoc(_: impl AssocHasBound<Assoc = i32>) {}
27+
//~^ ERROR: the trait bound `i32: Required` is not satisfied [E0277]
28+
29+
fn opaque_with_generic_assoc<T>(_: impl AssocHasBound<Assoc = T>) {}
30+
31+
fn main() {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0284]: type annotations needed
2+
--> $DIR/wf-item-bounds-on-projection.rs:21:23
3+
|
4+
LL | T1: AssocHasBound<Assoc = i32>,
5+
| ^^^^^^^^^^^ cannot infer type
6+
|
7+
= note: cannot satisfy `<T1 as AssocHasBound>::Assoc == _`
8+
9+
error[E0277]: the trait bound `i32: Required` is not satisfied
10+
--> $DIR/wf-item-bounds-on-projection.rs:26:53
11+
|
12+
LL | fn opaque_with_concrete_assoc(_: impl AssocHasBound<Assoc = i32>) {}
13+
| ^^^^^^^^^^^ the trait `Required` is not implemented for `i32`
14+
|
15+
help: this trait has no implementations, consider adding one
16+
--> $DIR/wf-item-bounds-on-projection.rs:5:1
17+
|
18+
LL | trait Required {}
19+
| ^^^^^^^^^^^^^^
20+
21+
error[E0277]: the trait bound `i32: Required` is not satisfied
22+
--> $DIR/wf-item-bounds-on-projection.rs:12:32
23+
|
24+
LL | type Assoc1: AssocHasBound<Assoc = i32>;
25+
| ^^^^^^^^^^^ the trait `Required` is not implemented for `i32`
26+
|
27+
help: this trait has no implementations, consider adding one
28+
--> $DIR/wf-item-bounds-on-projection.rs:5:1
29+
|
30+
LL | trait Required {}
31+
| ^^^^^^^^^^^^^^
32+
33+
error: aborting due to 3 previous errors
34+
35+
Some errors have detailed explanations: E0277, E0284.
36+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)