add tests and bless existing ones
This commit is contained in:
parent
ff448cfcee
commit
e0c98e2a33
26
src/test/ui/associated-types/issue-59324.rs
Normal file
26
src/test/ui/associated-types/issue-59324.rs
Normal file
@ -0,0 +1,26 @@
|
||||
trait NotFoo {}
|
||||
|
||||
pub trait Foo: NotFoo {
|
||||
type OnlyFoo;
|
||||
}
|
||||
|
||||
pub trait Service {
|
||||
type AssocType;
|
||||
}
|
||||
|
||||
pub trait ThriftService<Bug: NotFoo>:
|
||||
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
|
||||
//~| ERROR the trait bound `Bug: Foo` is not satisfied
|
||||
Service<AssocType = <Bug as Foo>::OnlyFoo>
|
||||
{
|
||||
fn get_service(
|
||||
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
|
||||
//~| ERROR the trait bound `Bug: Foo` is not satisfied
|
||||
&self,
|
||||
) -> Self::AssocType;
|
||||
}
|
||||
|
||||
fn with_factory<H>(factory: dyn ThriftService<()>) {}
|
||||
//~^ ERROR the trait bound `(): Foo` is not satisfied
|
||||
|
||||
fn main() {}
|
69
src/test/ui/associated-types/issue-59324.stderr
Normal file
69
src/test/ui/associated-types/issue-59324.stderr
Normal file
@ -0,0 +1,69 @@
|
||||
error[E0277]: the trait bound `Bug: Foo` is not satisfied
|
||||
--> $DIR/issue-59324.rs:11:1
|
||||
|
|
||||
LL | / pub trait ThriftService<Bug: NotFoo>:
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
|
||||
... |
|
||||
LL | | ) -> Self::AssocType;
|
||||
LL | | }
|
||||
| |_^ the trait `Foo` is not implemented for `Bug`
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
|
||||
| +++++
|
||||
|
||||
error[E0277]: the trait bound `Bug: Foo` is not satisfied
|
||||
--> $DIR/issue-59324.rs:11:1
|
||||
|
|
||||
LL | / pub trait ThriftService<Bug: NotFoo>:
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
|
||||
... |
|
||||
LL | | ) -> Self::AssocType;
|
||||
LL | | }
|
||||
| |_^ the trait `Foo` is not implemented for `Bug`
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
|
||||
| +++++
|
||||
|
||||
error[E0277]: the trait bound `Bug: Foo` is not satisfied
|
||||
--> $DIR/issue-59324.rs:16:5
|
||||
|
|
||||
LL | / fn get_service(
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | &self,
|
||||
LL | | ) -> Self::AssocType;
|
||||
| |_________________________^ the trait `Foo` is not implemented for `Bug`
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
|
||||
| +++++
|
||||
|
||||
error[E0277]: the trait bound `Bug: Foo` is not satisfied
|
||||
--> $DIR/issue-59324.rs:16:8
|
||||
|
|
||||
LL | fn get_service(
|
||||
| ^^^^^^^^^^^ the trait `Foo` is not implemented for `Bug`
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | pub trait ThriftService<Bug: NotFoo + Foo>:
|
||||
| +++++
|
||||
|
||||
error[E0277]: the trait bound `(): Foo` is not satisfied
|
||||
--> $DIR/issue-59324.rs:23:29
|
||||
|
|
||||
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
62
src/test/ui/associated-types/issue-67684.rs
Normal file
62
src/test/ui/associated-types/issue-67684.rs
Normal file
@ -0,0 +1,62 @@
|
||||
// check-pass
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
trait ParseError {
|
||||
type StreamError;
|
||||
}
|
||||
|
||||
impl<T> ParseError for T {
|
||||
type StreamError = ();
|
||||
}
|
||||
|
||||
trait Stream {
|
||||
type Item;
|
||||
type Error: ParseError;
|
||||
}
|
||||
|
||||
trait Parser
|
||||
where
|
||||
<Self as Parser>::PartialState: Default,
|
||||
{
|
||||
type PartialState;
|
||||
fn parse_mode(_: &Self, _: Self::PartialState) {
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Stream for () {
|
||||
type Item = ();
|
||||
type Error = ();
|
||||
}
|
||||
|
||||
impl Parser for () {
|
||||
type PartialState = ();
|
||||
}
|
||||
|
||||
struct AndThen<A, B>(core::marker::PhantomData<(A, B)>);
|
||||
|
||||
impl<A, B> Parser for AndThen<A, B>
|
||||
where
|
||||
A: Stream,
|
||||
B: Into<<A::Error as ParseError>::StreamError>,
|
||||
{
|
||||
type PartialState = ();
|
||||
}
|
||||
|
||||
fn expr<A>() -> impl Parser
|
||||
where
|
||||
A: Stream<Error = <A as Stream>::Item>,
|
||||
{
|
||||
AndThen::<A, ()>(core::marker::PhantomData)
|
||||
}
|
||||
|
||||
fn parse_mode_impl<A>()
|
||||
where
|
||||
<A as Stream>::Error: ParseError,
|
||||
A: Stream<Error = <A as Stream>::Item>,
|
||||
{
|
||||
Parser::parse_mode(&expr::<A>(), Default::default())
|
||||
}
|
||||
|
||||
fn main() {}
|
21
src/test/ui/associated-types/issue-69398.rs
Normal file
21
src/test/ui/associated-types/issue-69398.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// check-pass
|
||||
|
||||
pub trait Foo {
|
||||
type Bar;
|
||||
}
|
||||
|
||||
pub trait Broken {
|
||||
type Assoc;
|
||||
fn broken(&self) where Self::Assoc: Foo;
|
||||
}
|
||||
|
||||
impl<T> Broken for T {
|
||||
type Assoc = ();
|
||||
fn broken(&self) where Self::Assoc: Foo {
|
||||
let _x: <Self::Assoc as Foo>::Bar;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _m: &dyn Broken<Assoc=()> = &();
|
||||
}
|
16
src/test/ui/associated-types/issue-71113.rs
Normal file
16
src/test/ui/associated-types/issue-71113.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// check-pass
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
enum _Recursive<'a>
|
||||
where
|
||||
Self: ToOwned<Owned=Box<Self>>
|
||||
{
|
||||
Variant(MyCow<'a, _Recursive<'a>>),
|
||||
}
|
||||
|
||||
pub struct Wrapper<T>(T);
|
||||
|
||||
pub struct MyCow<'a, T: ToOwned<Owned=Box<T>> + 'a>(Wrapper<Cow<'a, T>>);
|
||||
|
||||
fn main() {}
|
121
src/test/ui/associated-types/issue-82079.rs
Normal file
121
src/test/ui/associated-types/issue-82079.rs
Normal file
@ -0,0 +1,121 @@
|
||||
// check-pass
|
||||
|
||||
mod convenience_operators {
|
||||
use crate::{Op, Relation};
|
||||
use std::ops::AddAssign;
|
||||
use std::ops::Mul;
|
||||
|
||||
impl<C: Op> Relation<C> {
|
||||
pub fn map<F: Fn(C::D) -> D2 + 'static, D2: 'static>(
|
||||
self,
|
||||
f: F,
|
||||
) -> Relation<impl Op<D = D2, R = C::R>> {
|
||||
self.map_dr(move |x, r| (f(x), r))
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: 'static, V: 'static, C: Op<D = (K, V)>> Relation<C> {
|
||||
pub fn semijoin<C2: Op<D = K, R = R2>, R2, R3: AddAssign<R3>>(
|
||||
self,
|
||||
other: Relation<C2>,
|
||||
) -> Relation<impl Op<D = C::D, R = R3>>
|
||||
where
|
||||
C::R: Mul<R2, Output = R3>,
|
||||
{
|
||||
self.join(other.map(|x| (x, ()))).map(|(k, x, ())| (k, x))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod core {
|
||||
mod operator {
|
||||
mod join {
|
||||
use super::Op;
|
||||
use crate::core::Relation;
|
||||
use std::ops::{AddAssign, Mul};
|
||||
struct Join<LC, RC> {
|
||||
_left: LC,
|
||||
_right: RC,
|
||||
}
|
||||
impl<
|
||||
LC: Op<D = (K, LD), R = LR>,
|
||||
RC: Op<D = (K, RD), R = RR>,
|
||||
K: 'static,
|
||||
LD: 'static,
|
||||
LR: AddAssign<LR> + Mul<RR, Output = OR>,
|
||||
RD: 'static,
|
||||
RR: AddAssign<RR>,
|
||||
OR: AddAssign<OR>,
|
||||
> Op for Join<LC, RC>
|
||||
{
|
||||
type D = (K, LD, RD);
|
||||
type R = OR;
|
||||
}
|
||||
impl<K: 'static, D: 'static, C: Op<D = (K, D)>> Relation<C> {
|
||||
pub fn join<C2: Op<D = (K, D2)>, D2: 'static, OR: AddAssign<OR>>(
|
||||
self,
|
||||
other: Relation<C2>,
|
||||
) -> Relation<impl Op<D = (K, D, D2), R = OR>>
|
||||
where
|
||||
C::R: Mul<C2::R, Output = OR>,
|
||||
{
|
||||
Relation {
|
||||
inner: Join {
|
||||
_left: self.inner,
|
||||
_right: other.inner,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mod map {
|
||||
use super::Op;
|
||||
use crate::core::Relation;
|
||||
use std::ops::AddAssign;
|
||||
struct Map<C, MF> {
|
||||
_inner: C,
|
||||
_op: MF,
|
||||
}
|
||||
impl<
|
||||
D1,
|
||||
R1,
|
||||
D2: 'static,
|
||||
R2: AddAssign<R2>,
|
||||
C: Op<D = D1, R = R1>,
|
||||
MF: Fn(D1, R1) -> (D2, R2),
|
||||
> Op for Map<C, MF>
|
||||
{
|
||||
type D = D2;
|
||||
type R = R2;
|
||||
}
|
||||
impl<C: Op> Relation<C> {
|
||||
pub fn map_dr<F: Fn(C::D, C::R) -> (D2, R2), D2: 'static, R2: AddAssign<R2>>(
|
||||
self,
|
||||
f: F,
|
||||
) -> Relation<impl Op<D = D2, R = R2>> {
|
||||
Relation {
|
||||
inner: Map {
|
||||
_inner: self.inner,
|
||||
_op: f,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
use std::ops::AddAssign;
|
||||
pub trait Op {
|
||||
type D: 'static;
|
||||
type R: AddAssign<Self::R>;
|
||||
}
|
||||
}
|
||||
pub use self::operator::Op;
|
||||
#[derive(Clone)]
|
||||
pub struct Relation<C> {
|
||||
inner: C,
|
||||
}
|
||||
}
|
||||
|
||||
use self::core::Op;
|
||||
pub use self::core::Relation;
|
||||
|
||||
fn main() {}
|
32
src/test/ui/associated-types/issue-88856.rs
Normal file
32
src/test/ui/associated-types/issue-88856.rs
Normal file
@ -0,0 +1,32 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
pub trait Trait{
|
||||
type R;
|
||||
fn func(self)->Self::R;
|
||||
}
|
||||
|
||||
pub struct TraitImpl<const N:usize>(pub i32);
|
||||
|
||||
impl<const N:usize> Trait for TraitImpl<N>
|
||||
where [();N/2]:,
|
||||
{
|
||||
type R = Self;
|
||||
fn func(self)->Self::R {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn sample<P,Convert>(p:P,f:Convert) -> i32
|
||||
where
|
||||
P:Trait,Convert:Fn(P::R)->i32
|
||||
{
|
||||
f(p.func())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let t = TraitImpl::<10>(4);
|
||||
sample(t,|x|x.0);
|
||||
}
|
13
src/test/ui/associated-types/issue-91234.rs
Normal file
13
src/test/ui/associated-types/issue-91234.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// check-pass
|
||||
|
||||
struct Struct;
|
||||
|
||||
trait Trait {
|
||||
type Type;
|
||||
}
|
||||
|
||||
enum Enum<'a> where &'a Struct: Trait {
|
||||
Variant(<&'a Struct as Trait>::Type)
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user