Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e0c98e2

Browse files
committed
add tests and bless existing ones
1 parent ff448cf commit e0c98e2

File tree

8 files changed

+360
-0
lines changed

8 files changed

+360
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
trait NotFoo {}
2+
3+
pub trait Foo: NotFoo {
4+
type OnlyFoo;
5+
}
6+
7+
pub trait Service {
8+
type AssocType;
9+
}
10+
11+
pub trait ThriftService<Bug: NotFoo>:
12+
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
13+
//~| ERROR the trait bound `Bug: Foo` is not satisfied
14+
Service<AssocType = <Bug as Foo>::OnlyFoo>
15+
{
16+
fn get_service(
17+
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
18+
//~| ERROR the trait bound `Bug: Foo` is not satisfied
19+
&self,
20+
) -> Self::AssocType;
21+
}
22+
23+
fn with_factory<H>(factory: dyn ThriftService<()>) {}
24+
//~^ ERROR the trait bound `(): Foo` is not satisfied
25+
26+
fn main() {}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
error[E0277]: the trait bound `Bug: Foo` is not satisfied
2+
--> $DIR/issue-59324.rs:11:1
3+
|
4+
LL | / pub trait ThriftService<Bug: NotFoo>:
5+
LL | |
6+
LL | |
7+
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
8+
... |
9+
LL | | ) -> Self::AssocType;
10+
LL | | }
11+
| |_^ the trait `Foo` is not implemented for `Bug`
12+
|
13+
help: consider further restricting this bound
14+
|
15+
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
16+
| +++++
17+
18+
error[E0277]: the trait bound `Bug: Foo` is not satisfied
19+
--> $DIR/issue-59324.rs:11:1
20+
|
21+
LL | / pub trait ThriftService<Bug: NotFoo>:
22+
LL | |
23+
LL | |
24+
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
25+
... |
26+
LL | | ) -> Self::AssocType;
27+
LL | | }
28+
| |_^ the trait `Foo` is not implemented for `Bug`
29+
|
30+
help: consider further restricting this bound
31+
|
32+
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
33+
| +++++
34+
35+
error[E0277]: the trait bound `Bug: Foo` is not satisfied
36+
--> $DIR/issue-59324.rs:16:5
37+
|
38+
LL | / fn get_service(
39+
LL | |
40+
LL | |
41+
LL | | &self,
42+
LL | | ) -> Self::AssocType;
43+
| |_________________________^ the trait `Foo` is not implemented for `Bug`
44+
|
45+
help: consider further restricting this bound
46+
|
47+
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
48+
| +++++
49+
50+
error[E0277]: the trait bound `Bug: Foo` is not satisfied
51+
--> $DIR/issue-59324.rs:16:8
52+
|
53+
LL | fn get_service(
54+
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `Bug`
55+
|
56+
help: consider further restricting this bound
57+
|
58+
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
59+
| +++++
60+
61+
error[E0277]: the trait bound `(): Foo` is not satisfied
62+
--> $DIR/issue-59324.rs:23:29
63+
|
64+
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
65+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()`
66+
67+
error: aborting due to 5 previous errors
68+
69+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// check-pass
2+
3+
#![allow(dead_code)]
4+
5+
trait ParseError {
6+
type StreamError;
7+
}
8+
9+
impl<T> ParseError for T {
10+
type StreamError = ();
11+
}
12+
13+
trait Stream {
14+
type Item;
15+
type Error: ParseError;
16+
}
17+
18+
trait Parser
19+
where
20+
<Self as Parser>::PartialState: Default,
21+
{
22+
type PartialState;
23+
fn parse_mode(_: &Self, _: Self::PartialState) {
24+
loop {}
25+
}
26+
}
27+
28+
impl Stream for () {
29+
type Item = ();
30+
type Error = ();
31+
}
32+
33+
impl Parser for () {
34+
type PartialState = ();
35+
}
36+
37+
struct AndThen<A, B>(core::marker::PhantomData<(A, B)>);
38+
39+
impl<A, B> Parser for AndThen<A, B>
40+
where
41+
A: Stream,
42+
B: Into<<A::Error as ParseError>::StreamError>,
43+
{
44+
type PartialState = ();
45+
}
46+
47+
fn expr<A>() -> impl Parser
48+
where
49+
A: Stream<Error = <A as Stream>::Item>,
50+
{
51+
AndThen::<A, ()>(core::marker::PhantomData)
52+
}
53+
54+
fn parse_mode_impl<A>()
55+
where
56+
<A as Stream>::Error: ParseError,
57+
A: Stream<Error = <A as Stream>::Item>,
58+
{
59+
Parser::parse_mode(&expr::<A>(), Default::default())
60+
}
61+
62+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-pass
2+
3+
pub trait Foo {
4+
type Bar;
5+
}
6+
7+
pub trait Broken {
8+
type Assoc;
9+
fn broken(&self) where Self::Assoc: Foo;
10+
}
11+
12+
impl<T> Broken for T {
13+
type Assoc = ();
14+
fn broken(&self) where Self::Assoc: Foo {
15+
let _x: <Self::Assoc as Foo>::Bar;
16+
}
17+
}
18+
19+
fn main() {
20+
let _m: &dyn Broken<Assoc=()> = &();
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
use std::borrow::Cow;
4+
5+
enum _Recursive<'a>
6+
where
7+
Self: ToOwned<Owned=Box<Self>>
8+
{
9+
Variant(MyCow<'a, _Recursive<'a>>),
10+
}
11+
12+
pub struct Wrapper<T>(T);
13+
14+
pub struct MyCow<'a, T: ToOwned<Owned=Box<T>> + 'a>(Wrapper<Cow<'a, T>>);
15+
16+
fn main() {}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// check-pass
2+
3+
mod convenience_operators {
4+
use crate::{Op, Relation};
5+
use std::ops::AddAssign;
6+
use std::ops::Mul;
7+
8+
impl<C: Op> Relation<C> {
9+
pub fn map<F: Fn(C::D) -> D2 + 'static, D2: 'static>(
10+
self,
11+
f: F,
12+
) -> Relation<impl Op<D = D2, R = C::R>> {
13+
self.map_dr(move |x, r| (f(x), r))
14+
}
15+
}
16+
17+
impl<K: 'static, V: 'static, C: Op<D = (K, V)>> Relation<C> {
18+
pub fn semijoin<C2: Op<D = K, R = R2>, R2, R3: AddAssign<R3>>(
19+
self,
20+
other: Relation<C2>,
21+
) -> Relation<impl Op<D = C::D, R = R3>>
22+
where
23+
C::R: Mul<R2, Output = R3>,
24+
{
25+
self.join(other.map(|x| (x, ()))).map(|(k, x, ())| (k, x))
26+
}
27+
}
28+
}
29+
30+
mod core {
31+
mod operator {
32+
mod join {
33+
use super::Op;
34+
use crate::core::Relation;
35+
use std::ops::{AddAssign, Mul};
36+
struct Join<LC, RC> {
37+
_left: LC,
38+
_right: RC,
39+
}
40+
impl<
41+
LC: Op<D = (K, LD), R = LR>,
42+
RC: Op<D = (K, RD), R = RR>,
43+
K: 'static,
44+
LD: 'static,
45+
LR: AddAssign<LR> + Mul<RR, Output = OR>,
46+
RD: 'static,
47+
RR: AddAssign<RR>,
48+
OR: AddAssign<OR>,
49+
> Op for Join<LC, RC>
50+
{
51+
type D = (K, LD, RD);
52+
type R = OR;
53+
}
54+
impl<K: 'static, D: 'static, C: Op<D = (K, D)>> Relation<C> {
55+
pub fn join<C2: Op<D = (K, D2)>, D2: 'static, OR: AddAssign<OR>>(
56+
self,
57+
other: Relation<C2>,
58+
) -> Relation<impl Op<D = (K, D, D2), R = OR>>
59+
where
60+
C::R: Mul<C2::R, Output = OR>,
61+
{
62+
Relation {
63+
inner: Join {
64+
_left: self.inner,
65+
_right: other.inner,
66+
},
67+
}
68+
}
69+
}
70+
}
71+
mod map {
72+
use super::Op;
73+
use crate::core::Relation;
74+
use std::ops::AddAssign;
75+
struct Map<C, MF> {
76+
_inner: C,
77+
_op: MF,
78+
}
79+
impl<
80+
D1,
81+
R1,
82+
D2: 'static,
83+
R2: AddAssign<R2>,
84+
C: Op<D = D1, R = R1>,
85+
MF: Fn(D1, R1) -> (D2, R2),
86+
> Op for Map<C, MF>
87+
{
88+
type D = D2;
89+
type R = R2;
90+
}
91+
impl<C: Op> Relation<C> {
92+
pub fn map_dr<F: Fn(C::D, C::R) -> (D2, R2), D2: 'static, R2: AddAssign<R2>>(
93+
self,
94+
f: F,
95+
) -> Relation<impl Op<D = D2, R = R2>> {
96+
Relation {
97+
inner: Map {
98+
_inner: self.inner,
99+
_op: f,
100+
},
101+
}
102+
}
103+
}
104+
}
105+
use std::ops::AddAssign;
106+
pub trait Op {
107+
type D: 'static;
108+
type R: AddAssign<Self::R>;
109+
}
110+
}
111+
pub use self::operator::Op;
112+
#[derive(Clone)]
113+
pub struct Relation<C> {
114+
inner: C,
115+
}
116+
}
117+
118+
use self::core::Op;
119+
pub use self::core::Relation;
120+
121+
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// check-pass
2+
3+
#![feature(generic_const_exprs)]
4+
#![allow(incomplete_features)]
5+
6+
pub trait Trait{
7+
type R;
8+
fn func(self)->Self::R;
9+
}
10+
11+
pub struct TraitImpl<const N:usize>(pub i32);
12+
13+
impl<const N:usize> Trait for TraitImpl<N>
14+
where [();N/2]:,
15+
{
16+
type R = Self;
17+
fn func(self)->Self::R {
18+
self
19+
}
20+
}
21+
22+
fn sample<P,Convert>(p:P,f:Convert) -> i32
23+
where
24+
P:Trait,Convert:Fn(P::R)->i32
25+
{
26+
f(p.func())
27+
}
28+
29+
fn main() {
30+
let t = TraitImpl::<10>(4);
31+
sample(t,|x|x.0);
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
3+
struct Struct;
4+
5+
trait Trait {
6+
type Type;
7+
}
8+
9+
enum Enum<'a> where &'a Struct: Trait {
10+
Variant(<&'a Struct as Trait>::Type)
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)