Skip to content

Commit 4c98429

Browse files
committed
Add tests
1 parent fa83c10 commit 4c98429

8 files changed

+188
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// check-pass
2+
// compile-flags: -Ztrait-solver=next
3+
4+
// check that a goal such as `alias-eq(<T as TraitB>::Assoc<bool>, <T as TraitB>::Assoc<?0>)`
5+
// succeeds with a constraint that `?0 = bool`
6+
7+
// FIXME(deferred_projection_equality): add a test that this is true during coherence
8+
9+
trait TraitA {}
10+
11+
trait TraitB {
12+
type Assoc<T: ?Sized>;
13+
}
14+
15+
impl<T: TraitB> TraitA for (T, T::Assoc<bool>) {}
16+
17+
impl TraitB for i32 {
18+
type Assoc<T: ?Sized> = u32;
19+
}
20+
21+
fn needs_a<T: TraitA>() {}
22+
23+
fn bar<T: TraitB>() {
24+
needs_a::<(T, <T as TraitB>::Assoc<_>)>();
25+
}
26+
27+
fn main() {
28+
bar::<i32>();
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
// check that when computing `alias-eq(<() as Foo<u16, T>>::Assoc, <() as Foo<?0, T>>::Assoc)`
4+
// we do not infer `?0 = u8` via the `for<STOP> (): Foo<u8, STOP>` impl or `?0 = u16` by
5+
// relating substs as either could be a valid solution.
6+
7+
trait Foo<T, STOP> {
8+
type Assoc;
9+
}
10+
11+
impl<STOP> Foo<u8, STOP> for ()
12+
where
13+
(): Foo<u16, STOP>,
14+
{
15+
type Assoc = <() as Foo<u16, STOP>>::Assoc;
16+
}
17+
18+
impl Foo<u16, i8> for () {
19+
type Assoc = u8;
20+
}
21+
22+
impl Foo<u16, i16> for () {
23+
type Assoc = u16;
24+
}
25+
26+
fn output<T, U>() -> <() as Foo<T, U>>::Assoc
27+
where
28+
(): Foo<T, U>,
29+
{
30+
todo!()
31+
}
32+
33+
fn incomplete<T>()
34+
where
35+
(): Foo<u16, T>,
36+
{
37+
// `<() as Foo<u16, STOP>>::Assoc == <() as Foo<_, STOP>>::Assoc`
38+
let _: <() as Foo<u16, T>>::Assoc = output::<_, T>();
39+
//~^ error: type annotations needed
40+
41+
// let _: <() as Foo<u16, T>>::Assoc = output::<u8, T>(); // OK
42+
// let _: <() as Foo<u16, T>>::Assoc = output::<u16, T>(); // OK
43+
}
44+
45+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/alias_eq_dont_use_normalizes_to_if_substs_eq.rs:38:41
3+
|
4+
LL | let _: <() as Foo<u16, T>>::Assoc = output::<_, T>();
5+
| ^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `output`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-pass
2+
// compile-flags: -Ztrait-solver=next
3+
4+
// test that the new solver can handle `alias-eq(<i32 as TraitB>::Assoc, u32)`
5+
6+
trait TraitA {}
7+
8+
trait TraitB {
9+
type Assoc;
10+
}
11+
12+
impl<T: TraitB> TraitA for (T, T::Assoc) {}
13+
14+
impl TraitB for i32 {
15+
type Assoc = u32;
16+
}
17+
18+
fn needs_a<T: TraitA>() {}
19+
20+
fn main() {
21+
needs_a::<(i32, u32)>();
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
// check that a `alias-eq(<?0 as TraitB>::Assoc, <T as TraitB>::Assoc)` goal fails.
4+
5+
// FIXME(deferred_projection_equality): add a test that this is true during coherence
6+
7+
trait TraitB {
8+
type Assoc;
9+
}
10+
11+
fn needs_a<T: TraitB>() -> T::Assoc {
12+
unimplemented!()
13+
}
14+
15+
fn bar<T: TraitB>() {
16+
let _: <_ as TraitB>::Assoc = needs_a::<T>();
17+
//~^ error: type annotations needed
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/alias_eq_substs_eq_not_intercrate.rs:16:12
3+
|
4+
LL | let _: <_ as TraitB>::Assoc = needs_a::<T>();
5+
| ^^^^^^^^^^^^^^^^^^^^ cannot infer type for associated type `<_ as TraitB>::Assoc`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// [no_self_infer] check-pass
2+
// compile-flags: -Ztrait-solver=next
3+
// revisions: self_infer no_self_infer
4+
5+
// checks that the new solver is smart enough to infer `?0 = U` when solving:
6+
// `normalizes-to(<Vec<?0> as Trait>::Assoc, u8)`
7+
// with `normalizes-to(<Vec<U> as Trait>::Assoc, u8)` in the paramenv even when
8+
// there is a separate `Vec<T>: Trait` bound in the paramenv.
9+
//
10+
// FIXME(-Ztrait-solver=next)
11+
// This could also compile for `normalizes-to(<?0 as Trait>::Assoc, u8)` but
12+
// we currently immediately consider a goal ambiguous if the self type is an
13+
// inference variable.
14+
15+
trait Trait {
16+
type Assoc;
17+
}
18+
19+
fn foo<T: Trait<Assoc = u8>>(x: T) {}
20+
21+
#[cfg(self_infer)]
22+
fn unconstrained<T>() -> T {
23+
todo!()
24+
}
25+
26+
#[cfg(no_self_infer)]
27+
fn unconstrained<T>() -> Vec<T> {
28+
todo!()
29+
}
30+
31+
fn bar<T, U>()
32+
where
33+
Vec<T>: Trait,
34+
Vec<U>: Trait<Assoc = u8>,
35+
{
36+
foo(unconstrained())
37+
//[self_infer]~^ ERROR type annotations needed
38+
}
39+
40+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/normalizes_to_ignores_unnormalizable_candidate.rs:36:5
3+
|
4+
LL | foo(unconstrained())
5+
| ^^^ cannot infer type of the type parameter `T` declared on the function `foo`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | foo::<T>(unconstrained())
10+
| +++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)