Skip to content

Commit c8e0f4d

Browse files
authored
Rollup merge of rust-lang#78295 - Alexendoo:ice-regression-tests, r=nagisa
Add some regression tests Closes rust-lang#56229 Closes rust-lang#59494 Closes rust-lang#70746 Closes rust-lang#73229
2 parents 463b6cc + 75bbd80 commit c8e0f4d

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

src/test/ui/issues/issue-56229.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// check-pass
2+
3+
trait Mirror {
4+
type Other;
5+
}
6+
7+
#[derive(Debug)]
8+
struct Even(usize);
9+
struct Odd;
10+
11+
impl Mirror for Even {
12+
type Other = Odd;
13+
}
14+
15+
impl Mirror for Odd {
16+
type Other = Even;
17+
}
18+
19+
trait Dyn<T: Mirror>: AsRef<<T as Mirror>::Other> {}
20+
21+
impl Dyn<Odd> for Even {}
22+
23+
impl AsRef<Even> for Even {
24+
fn as_ref(&self) -> &Even {
25+
self
26+
}
27+
}
28+
29+
fn code<T: Mirror>(d: &dyn Dyn<T>) -> &T::Other {
30+
d.as_ref()
31+
}
32+
33+
fn main() {
34+
println!("{:?}", code(&Even(22)));
35+
}

src/test/ui/issues/issue-59494.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fn t7p<A, B, C>(f: impl Fn(B) -> C, g: impl Fn(A) -> B) -> impl Fn(A) -> C {
2+
move |a: A| -> C { f(g(a)) }
3+
}
4+
5+
fn t8n<A, B, C>(f: impl Fn(A) -> B, g: impl Fn(A) -> C) -> impl Fn(A) -> (B, C)
6+
where
7+
A: Copy,
8+
{
9+
move |a: A| -> (B, C) {
10+
let b = a;
11+
let fa = f(a);
12+
let ga = g(b);
13+
(fa, ga)
14+
}
15+
}
16+
17+
fn main() {
18+
let f = |(_, _)| {};
19+
let g = |(a, _)| a;
20+
let t7 = |env| |a| |b| t7p(f, g)(((env, a), b));
21+
let t8 = t8n(t7, t7p(f, g));
22+
//~^ ERROR: expected a `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)>
23+
}

src/test/ui/issues/issue-59494.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: expected a `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)>`
2+
--> $DIR/issue-59494.rs:21:22
3+
|
4+
LL | fn t8n<A, B, C>(f: impl Fn(A) -> B, g: impl Fn(A) -> C) -> impl Fn(A) -> (B, C)
5+
| ---------- required by this bound in `t8n`
6+
...
7+
LL | let t8 = t8n(t7, t7p(f, g));
8+
| ^^^^^^^^^ expected an `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)>`
9+
|
10+
= help: the trait `Fn<(_,)>` is not implemented for `impl Fn<(((_, _), _),)>`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/issues/issue-70746.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// check-pass
2+
3+
pub trait Trait1 {
4+
type C;
5+
}
6+
7+
struct T1;
8+
impl Trait1 for T1 {
9+
type C = usize;
10+
}
11+
pub trait Callback<T: Trait1>: FnMut(<T as Trait1>::C) {}
12+
impl<T: Trait1, F: FnMut(<T as Trait1>::C)> Callback<T> for F {}
13+
14+
pub struct State<T: Trait1> {
15+
callback: Option<Box<dyn Callback<T>>>,
16+
}
17+
impl<T: Trait1> State<T> {
18+
fn new() -> Self {
19+
Self { callback: None }
20+
}
21+
fn test_cb(&mut self, d: <T as Trait1>::C) {
22+
(self.callback.as_mut().unwrap())(d)
23+
}
24+
}
25+
26+
fn main() {
27+
let mut s = State::<T1>::new();
28+
s.test_cb(1);
29+
}

src/test/ui/issues/issue-73229.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// check-pass
2+
3+
fn any<T>() -> T {
4+
loop {}
5+
}
6+
7+
trait Foo {
8+
type V;
9+
}
10+
11+
trait Callback<T: Foo>: Fn(&T, &T::V) {}
12+
impl<T: Foo, F: Fn(&T, &T::V)> Callback<T> for F {}
13+
14+
struct Bar<T: Foo> {
15+
callback: Box<dyn Callback<T>>,
16+
}
17+
18+
impl<T: Foo> Bar<T> {
19+
fn event(&self) {
20+
(self.callback)(any(), any());
21+
}
22+
}
23+
24+
struct A;
25+
struct B;
26+
impl Foo for A {
27+
type V = B;
28+
}
29+
30+
fn main() {
31+
let foo = Bar::<A> { callback: Box::new(|_: &A, _: &B| ()) };
32+
foo.event();
33+
}

0 commit comments

Comments
 (0)