-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// check-pass | ||
|
||
trait Mirror { | ||
type Other; | ||
} | ||
|
||
#[derive(Debug)] | ||
struct Even(usize); | ||
struct Odd; | ||
|
||
impl Mirror for Even { | ||
type Other = Odd; | ||
} | ||
|
||
impl Mirror for Odd { | ||
type Other = Even; | ||
} | ||
|
||
trait Dyn<T: Mirror>: AsRef<<T as Mirror>::Other> {} | ||
|
||
impl Dyn<Odd> for Even {} | ||
|
||
impl AsRef<Even> for Even { | ||
fn as_ref(&self) -> &Even { | ||
self | ||
} | ||
} | ||
|
||
fn code<T: Mirror>(d: &dyn Dyn<T>) -> &T::Other { | ||
d.as_ref() | ||
} | ||
|
||
fn main() { | ||
println!("{:?}", code(&Even(22))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fn t7p<A, B, C>(f: impl Fn(B) -> C, g: impl Fn(A) -> B) -> impl Fn(A) -> C { | ||
move |a: A| -> C { f(g(a)) } | ||
} | ||
|
||
fn t8n<A, B, C>(f: impl Fn(A) -> B, g: impl Fn(A) -> C) -> impl Fn(A) -> (B, C) | ||
where | ||
A: Copy, | ||
{ | ||
move |a: A| -> (B, C) { | ||
let b = a; | ||
let fa = f(a); | ||
let ga = g(b); | ||
(fa, ga) | ||
} | ||
} | ||
|
||
fn main() { | ||
let f = |(_, _)| {}; | ||
let g = |(a, _)| a; | ||
let t7 = |env| |a| |b| t7p(f, g)(((env, a), b)); | ||
let t8 = t8n(t7, t7p(f, g)); | ||
//~^ ERROR: expected a `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0277]: expected a `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)>` | ||
--> $DIR/issue-59494.rs:21:22 | ||
| | ||
LL | fn t8n<A, B, C>(f: impl Fn(A) -> B, g: impl Fn(A) -> C) -> impl Fn(A) -> (B, C) | ||
| ---------- required by this bound in `t8n` | ||
... | ||
LL | let t8 = t8n(t7, t7p(f, g)); | ||
| ^^^^^^^^^ expected an `Fn<(_,)>` closure, found `impl Fn<(((_, _), _),)>` | ||
| | ||
= help: the trait `Fn<(_,)>` is not implemented for `impl Fn<(((_, _), _),)>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// check-pass | ||
|
||
pub trait Trait1 { | ||
type C; | ||
} | ||
|
||
struct T1; | ||
impl Trait1 for T1 { | ||
type C = usize; | ||
} | ||
pub trait Callback<T: Trait1>: FnMut(<T as Trait1>::C) {} | ||
impl<T: Trait1, F: FnMut(<T as Trait1>::C)> Callback<T> for F {} | ||
|
||
pub struct State<T: Trait1> { | ||
callback: Option<Box<dyn Callback<T>>>, | ||
} | ||
impl<T: Trait1> State<T> { | ||
fn new() -> Self { | ||
Self { callback: None } | ||
} | ||
fn test_cb(&mut self, d: <T as Trait1>::C) { | ||
(self.callback.as_mut().unwrap())(d) | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut s = State::<T1>::new(); | ||
s.test_cb(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// check-pass | ||
|
||
fn any<T>() -> T { | ||
loop {} | ||
} | ||
|
||
trait Foo { | ||
type V; | ||
} | ||
|
||
trait Callback<T: Foo>: Fn(&T, &T::V) {} | ||
impl<T: Foo, F: Fn(&T, &T::V)> Callback<T> for F {} | ||
|
||
struct Bar<T: Foo> { | ||
callback: Box<dyn Callback<T>>, | ||
} | ||
|
||
impl<T: Foo> Bar<T> { | ||
fn event(&self) { | ||
(self.callback)(any(), any()); | ||
} | ||
} | ||
|
||
struct A; | ||
struct B; | ||
impl Foo for A { | ||
type V = B; | ||
} | ||
|
||
fn main() { | ||
let foo = Bar::<A> { callback: Box::new(|_: &A, _: &B| ()) }; | ||
foo.event(); | ||
} |