Skip to content

Commit a549bbd

Browse files
Add regression test for #54182
1 parent a323ff2 commit a549bbd

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// run-pass
2+
3+
#![feature(associated_type_defaults)]
4+
5+
macro_rules! overload {
6+
($a:expr, $b:expr) => {
7+
overload::overload2($a, $b)
8+
};
9+
($a:expr, $b:expr, $c:expr) => {
10+
overload::overload3($a, $b, $c)
11+
}
12+
}
13+
14+
fn main() {
15+
let r = overload!(42, true);
16+
println!("-> {:?}", r);
17+
18+
let r = overload!("Hello world", 13.0);
19+
println!("-> {:?}", r);
20+
21+
let r = overload!(42, true, 42.5);
22+
println!("-> {:?}", r);
23+
24+
let r = overload!("Hello world", 13.0, 42);
25+
println!("-> {:?}", r);
26+
}
27+
28+
mod overload {
29+
pub trait Overload {
30+
// type R;
31+
type R = ();
32+
fn overload(self) -> Self::R;
33+
}
34+
35+
// overloads for 2 args
36+
impl Overload for (i32, bool) {
37+
// type R = ();
38+
fn overload(self) /*-> Self::R*/ {
39+
let (a, b) = self; // destructure args
40+
println!("i32 and bool {:?}", (a, b));
41+
}
42+
}
43+
impl<'a> Overload for (&'a str, f32) {
44+
type R = f32;
45+
fn overload(self) -> Self::R {
46+
let (a, b) = self; // destructure args
47+
println!("&str and f32 {:?}", (a, b));
48+
b
49+
}
50+
}
51+
52+
// overloads for 3 args
53+
impl Overload for (i32, bool, f32) {
54+
// type R = ();
55+
fn overload(self) /*-> Self::R*/ {
56+
let (a, b, c) = self; // destructure args
57+
println!("i32 and bool and f32 {:?}", (a, b, c));
58+
}
59+
}
60+
impl<'a> Overload for (&'a str, f32, i32) {
61+
type R = i32;
62+
fn overload(self) -> Self::R {
63+
let (a, b, c) = self; // destructure args
64+
println!("&str and f32 and i32: {:?}", (a, b, c));
65+
c
66+
}
67+
}
68+
69+
// overloads for more args
70+
// ...
71+
72+
pub fn overload2<R, A, B>(a: A, b: B) -> R where (A, B): Overload<R = R> {
73+
(a, b).overload()
74+
}
75+
76+
pub fn overload3<R, A, B, C>(a: A, b: B, c: C) -> R where (A, B, C): Overload<R = R> {
77+
(a, b, c).overload()
78+
}
79+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-pass
2+
3+
#![feature(associated_type_defaults)]
4+
5+
trait Tr {
6+
type Assoc = ();
7+
}
8+
9+
impl Tr for () {}
10+
11+
fn f(thing: <() as Tr>::Assoc) {
12+
let c: () = thing;
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)