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.
GuillerLT and schneiderfelipe
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4