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