Open
Description
Attempting to implement FnOnce
for a reference to a struct or a trait object:
#![feature(fn_traits)]
#![feature(unboxed_closures)]
struct S;
fn repro_ref(thing: &S) {
thing();
}
impl<'a> FnOnce<()> for &'a S {
type Output = ();
extern "rust-call" fn call_once(self, _arg: ()) -> () {}
}
fn main() {}
Produces the error:
error[E0618]: expected function, found `&S`
--> src/main.rs:7:5
|
7 | thing();
| ^^^^^^^
|
note: defined here
--> src/main.rs:6:14
|
6 | fn repro_ref(thing: &S) {
| ^^^^^
Interestingly, both of these alternatives work:
fn ok_ref_ref_arg(thing: &&S) {
thing();
}
fn ok_ref_ref(thing: &S) {
(&thing)();
}
cc #29625.
Originally from this Stack Overflow question.