Open
Description
This example:
pub struct Request<'a, 'b: 'a> {
a: &'a (),
b: &'b (),
}
pub trait Handler: Send + Sync + 'static {
fn handle(&self, &mut Request) -> Result<(),()>;
}
impl<F> Handler for F where F: Send + Sync + 'static + Fn(&mut Request) -> Result<(),()> {
fn handle(&self, _: &mut Request) -> Result<(),()> {
unimplemented!()
}
}
fn make_handler(h: &'static Handler) -> Box<Handler> {
Box::new(move |req| h.handle(req))
}
errors with
error[E0271]: type mismatch resolving `for<'r, 'r, 'r> <[closure@<anon>:14:14: 14:38 h:_] as std::ops::FnOnce<(&'r mut Request<'r, 'r>,)>>::Output == std::result::Result<(), ()>`
--> <anon>:14:5
|
14 | Box::new(move |req| h.handle(req))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected bound lifetime parameter , found concrete lifetime
|
= note: concrete lifetime that was found is lifetime '_#9r
= note: required because of the requirements on the impl of `Handler` for `[closure@<anon>:14:14: 14:38 h:_]`
= note: required for the cast to the object type `Handler`
Annotating the closure parameter |req: &mut Response|
allow the example to compile.
Interesting, annotating with |req: &&mut Response|
produces a similarly-structured error, so I believe we're inferring &&mut
here (maybe related to autoderef?).
Metadata
Metadata
Assignees
Labels
Area: Closures (`|…| { … }`)Area: Messages for errors, warnings, and lintsArea: Type inferenceArea: Type systemCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.