]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-93342.rs
Rollup merge of #94839 - TaKO8Ki:suggest-using-double-colon-for-struct-field-type...
[rust.git] / src / test / ui / generic-associated-types / issue-93342.rs
1 // check-pass
2
3 #![feature(generic_associated_types)]
4
5 use std::marker::PhantomData;
6
7 pub trait Scalar: 'static {
8     type RefType<'a>: ScalarRef<'a>;
9 }
10
11 pub trait ScalarRef<'a>: 'a {}
12
13 impl Scalar for i32 {
14     type RefType<'a> = i32;
15 }
16
17 impl Scalar for String {
18     type RefType<'a> = &'a str;
19 }
20
21 impl Scalar for bool {
22     type RefType<'a> = i32;
23 }
24
25 impl<'a> ScalarRef<'a> for bool {}
26
27 impl<'a> ScalarRef<'a> for i32 {}
28
29 impl<'a> ScalarRef<'a> for &'a str {}
30
31 fn str_contains(a: &str, b: &str) -> bool {
32     a.contains(b)
33 }
34
35 pub struct BinaryExpression<A: Scalar, B: Scalar, O: Scalar, F>
36 where
37     F: Fn(A::RefType<'_>, B::RefType<'_>) -> O,
38 {
39     f: F,
40     _phantom: PhantomData<(A, B, O)>,
41 }
42
43 impl<A: Scalar, B: Scalar, O: Scalar, F> BinaryExpression<A, B, O, F>
44 where
45     F: Fn(A::RefType<'_>, B::RefType<'_>) -> O,
46 {
47     pub fn new(f: F) -> Self {
48         Self {
49             f,
50             _phantom: PhantomData,
51         }
52     }
53 }
54
55 fn main() {
56     BinaryExpression::<String, String, bool, _>::new(str_contains);
57 }