Skip to content

Commit ba6e138

Browse files
Add more tests
1 parent dae4341 commit ba6e138

File tree

3 files changed

+190
-19
lines changed

3 files changed

+190
-19
lines changed

tests/ui/associated-type-bounds/duplicate.rs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
//@ check-pass
1+
//@ run-pass
22

3-
#![allow(type_alias_bounds)]
3+
#![feature(associated_const_equality, return_type_notation)]
4+
#![allow(dead_code, refining_impl_trait_internal, type_alias_bounds)]
45

56
use std::iter;
67
use std::mem::ManuallyDrop;
@@ -185,8 +186,46 @@ trait TRA3 {
185186

186187
trait Trait {
187188
type Gat<T>;
189+
190+
const ASSOC: i32;
191+
192+
fn foo() -> impl Sized;
193+
}
194+
195+
impl Trait for () {
196+
type Gat<T> = ();
197+
198+
const ASSOC: i32 = 3;
199+
200+
fn foo() {}
188201
}
189202

190203
trait Subtrait: Trait<Gat<u32> = u32, Gat<u64> = u64> {}
191204

192-
fn main() {}
205+
fn f<T: Trait<Gat<i32> = (), Gat<i64> = ()>>() {
206+
let _: T::Gat<i32> = ();
207+
let _: T::Gat<i64> = ();
208+
}
209+
210+
fn g<T: Trait<Gat<i32> = (), Gat<i64> = &'static str>>() {
211+
let _: T::Gat<i32> = ();
212+
let _: T::Gat<i64> = "";
213+
}
214+
215+
fn uncallable(_: impl Iterator<Item = i32, Item = u32>) {}
216+
217+
fn callable(_: impl Iterator<Item = i32, Item = i32>) {}
218+
219+
fn uncallable_const(_: impl Trait<ASSOC = 3, ASSOC = 4>) {}
220+
221+
fn callable_const(_: impl Trait<ASSOC = 3, ASSOC = 3>) {}
222+
223+
fn uncallable_rtn(_: impl Trait<foo(..): Trait<ASSOC = 3>, foo(..): Trait<ASSOC = 4>>) {}
224+
225+
fn callable_rtn(_: impl Trait<foo(..): Send, foo(..): Send, foo(..): Eq>) {}
226+
227+
fn main() {
228+
callable(iter::empty::<i32>());
229+
callable_const(());
230+
callable_rtn(());
231+
}

tests/ui/associated-type-bounds/duplicate_err.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![feature(type_alias_impl_trait)]
1+
#![feature(associated_const_equality, type_alias_impl_trait, return_type_notation)]
2+
#![allow(refining_impl_trait_internal)]
23

34
use std::iter;
45

@@ -37,4 +38,43 @@ fn mismatch_2() -> impl Iterator<Item: Copy, Item: Send> { //~ ERROR [E0277]
3738
iter::empty::<String>()
3839
}
3940

40-
fn main() {}
41+
trait Trait {
42+
type Gat<T>;
43+
44+
const ASSOC: i32;
45+
46+
fn foo() -> impl Sized;
47+
}
48+
49+
impl Trait for () {
50+
type Gat<T> = ();
51+
52+
const ASSOC: i32 = 3;
53+
54+
fn foo() {}
55+
}
56+
57+
impl Trait for u32 {
58+
type Gat<T> = ();
59+
60+
const ASSOC: i32 = 4;
61+
62+
fn foo() -> u32 {
63+
42
64+
}
65+
}
66+
67+
fn uncallable(_: impl Iterator<Item = i32, Item = u32>) {}
68+
69+
fn uncallable_const(_: impl Trait<ASSOC = 3, ASSOC = 4>) {}
70+
71+
fn uncallable_rtn(_: impl Trait<foo(..): Trait<ASSOC = 3>, foo(..): Trait<ASSOC = 4>>) {}
72+
73+
fn main() {
74+
uncallable(iter::empty::<u32>()); //~ ERROR [E0271]
75+
uncallable(iter::empty::<i32>()); //~ ERROR [E0271]
76+
uncallable_const(()); //~ ERROR [E0271]
77+
uncallable_const(4u32); //~ ERROR [E0271]
78+
uncallable_rtn(()); //~ ERROR [E0271]
79+
uncallable_rtn(17u32); //~ ERROR [E0271]
80+
}
Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/duplicate_err.rs:6:5
2+
--> $DIR/duplicate_err.rs:7:5
33
|
44
LL | iter::empty()
55
| ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty`
@@ -10,7 +10,7 @@ LL | iter::empty::<T>()
1010
| +++++
1111

1212
error[E0282]: type annotations needed
13-
--> $DIR/duplicate_err.rs:10:5
13+
--> $DIR/duplicate_err.rs:11:5
1414
|
1515
LL | iter::empty()
1616
| ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty`
@@ -21,7 +21,7 @@ LL | iter::empty::<T>()
2121
| +++++
2222

2323
error[E0282]: type annotations needed
24-
--> $DIR/duplicate_err.rs:14:5
24+
--> $DIR/duplicate_err.rs:15:5
2525
|
2626
LL | iter::empty()
2727
| ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty`
@@ -32,55 +32,55 @@ LL | iter::empty::<T>()
3232
| +++++
3333

3434
error: unconstrained opaque type
35-
--> $DIR/duplicate_err.rs:18:51
35+
--> $DIR/duplicate_err.rs:19:51
3636
|
3737
LL | type ETAI1<T: Iterator<Item: Copy, Item: Send>> = impl Copy;
3838
| ^^^^^^^^^
3939
|
4040
= note: `ETAI1` must be used in combination with a concrete type within the same crate
4141

4242
error: unconstrained opaque type
43-
--> $DIR/duplicate_err.rs:20:51
43+
--> $DIR/duplicate_err.rs:21:51
4444
|
4545
LL | type ETAI2<T: Iterator<Item: Copy, Item: Copy>> = impl Copy;
4646
| ^^^^^^^^^
4747
|
4848
= note: `ETAI2` must be used in combination with a concrete type within the same crate
4949

5050
error: unconstrained opaque type
51-
--> $DIR/duplicate_err.rs:22:57
51+
--> $DIR/duplicate_err.rs:23:57
5252
|
5353
LL | type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy;
5454
| ^^^^^^^^^
5555
|
5656
= note: `ETAI3` must be used in combination with a concrete type within the same crate
5757

5858
error: unconstrained opaque type
59-
--> $DIR/duplicate_err.rs:25:14
59+
--> $DIR/duplicate_err.rs:26:14
6060
|
6161
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363
|
6464
= note: `ETAI4` must be used in combination with a concrete type within the same crate
6565

6666
error: unconstrained opaque type
67-
--> $DIR/duplicate_err.rs:27:14
67+
--> $DIR/duplicate_err.rs:28:14
6868
|
6969
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
7070
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7171
|
7272
= note: `ETAI5` must be used in combination with a concrete type within the same crate
7373

7474
error: unconstrained opaque type
75-
--> $DIR/duplicate_err.rs:29:14
75+
--> $DIR/duplicate_err.rs:30:14
7676
|
7777
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
7878
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7979
|
8080
= note: `ETAI6` must be used in combination with a concrete type within the same crate
8181

8282
error[E0277]: `*const ()` cannot be sent between threads safely
83-
--> $DIR/duplicate_err.rs:32:18
83+
--> $DIR/duplicate_err.rs:33:18
8484
|
8585
LL | fn mismatch() -> impl Iterator<Item: Copy, Item: Send> {
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
@@ -90,14 +90,106 @@ LL | iter::empty::<*const ()>()
9090
= help: the trait `Send` is not implemented for `*const ()`
9191

9292
error[E0277]: the trait bound `String: Copy` is not satisfied
93-
--> $DIR/duplicate_err.rs:36:20
93+
--> $DIR/duplicate_err.rs:37:20
9494
|
9595
LL | fn mismatch_2() -> impl Iterator<Item: Copy, Item: Send> {
9696
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
9797
LL | iter::empty::<String>()
9898
| ----------------------- return type was inferred to be `std::iter::Empty<String>` here
9999

100-
error: aborting due to 11 previous errors
100+
error[E0271]: expected `Empty<u32>` to be an iterator that yields `i32`, but it yields `u32`
101+
--> $DIR/duplicate_err.rs:74:16
102+
|
103+
LL | uncallable(iter::empty::<u32>());
104+
| ---------- ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
105+
| |
106+
| required by a bound introduced by this call
107+
|
108+
note: required by a bound in `uncallable`
109+
--> $DIR/duplicate_err.rs:67:32
110+
|
111+
LL | fn uncallable(_: impl Iterator<Item = i32, Item = u32>) {}
112+
| ^^^^^^^^^^ required by this bound in `uncallable`
113+
114+
error[E0271]: expected `Empty<i32>` to be an iterator that yields `u32`, but it yields `i32`
115+
--> $DIR/duplicate_err.rs:75:16
116+
|
117+
LL | uncallable(iter::empty::<i32>());
118+
| ---------- ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `i32`
119+
| |
120+
| required by a bound introduced by this call
121+
|
122+
note: required by a bound in `uncallable`
123+
--> $DIR/duplicate_err.rs:67:44
124+
|
125+
LL | fn uncallable(_: impl Iterator<Item = i32, Item = u32>) {}
126+
| ^^^^^^^^^^ required by this bound in `uncallable`
127+
128+
error[E0271]: type mismatch resolving `<() as Trait>::ASSOC == 4`
129+
--> $DIR/duplicate_err.rs:76:22
130+
|
131+
LL | uncallable_const(());
132+
| ---------------- ^^ expected `4`, found `3`
133+
| |
134+
| required by a bound introduced by this call
135+
|
136+
= note: expected constant `4`
137+
found constant `3`
138+
note: required by a bound in `uncallable_const`
139+
--> $DIR/duplicate_err.rs:69:46
140+
|
141+
LL | fn uncallable_const(_: impl Trait<ASSOC = 3, ASSOC = 4>) {}
142+
| ^^^^^^^^^ required by this bound in `uncallable_const`
143+
144+
error[E0271]: type mismatch resolving `<u32 as Trait>::ASSOC == 3`
145+
--> $DIR/duplicate_err.rs:77:22
146+
|
147+
LL | uncallable_const(4u32);
148+
| ---------------- ^^^^ expected `3`, found `4`
149+
| |
150+
| required by a bound introduced by this call
151+
|
152+
= note: expected constant `3`
153+
found constant `4`
154+
note: required by a bound in `uncallable_const`
155+
--> $DIR/duplicate_err.rs:69:35
156+
|
157+
LL | fn uncallable_const(_: impl Trait<ASSOC = 3, ASSOC = 4>) {}
158+
| ^^^^^^^^^ required by this bound in `uncallable_const`
159+
160+
error[E0271]: type mismatch resolving `<() as Trait>::ASSOC == 4`
161+
--> $DIR/duplicate_err.rs:78:20
162+
|
163+
LL | uncallable_rtn(());
164+
| -------------- ^^ expected `4`, found `3`
165+
| |
166+
| required by a bound introduced by this call
167+
|
168+
= note: expected constant `4`
169+
found constant `3`
170+
note: required by a bound in `uncallable_rtn`
171+
--> $DIR/duplicate_err.rs:71:75
172+
|
173+
LL | fn uncallable_rtn(_: impl Trait<foo(..): Trait<ASSOC = 3>, foo(..): Trait<ASSOC = 4>>) {}
174+
| ^^^^^^^^^ required by this bound in `uncallable_rtn`
175+
176+
error[E0271]: type mismatch resolving `<u32 as Trait>::ASSOC == 3`
177+
--> $DIR/duplicate_err.rs:79:20
178+
|
179+
LL | uncallable_rtn(17u32);
180+
| -------------- ^^^^^ expected `3`, found `4`
181+
| |
182+
| required by a bound introduced by this call
183+
|
184+
= note: expected constant `3`
185+
found constant `4`
186+
note: required by a bound in `uncallable_rtn`
187+
--> $DIR/duplicate_err.rs:71:48
188+
|
189+
LL | fn uncallable_rtn(_: impl Trait<foo(..): Trait<ASSOC = 3>, foo(..): Trait<ASSOC = 4>>) {}
190+
| ^^^^^^^^^ required by this bound in `uncallable_rtn`
191+
192+
error: aborting due to 17 previous errors
101193

102-
Some errors have detailed explanations: E0277, E0282.
103-
For more information about an error, try `rustc --explain E0277`.
194+
Some errors have detailed explanations: E0271, E0277, E0282.
195+
For more information about an error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)