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