Closed
Description
Minimal(ish) reproducible example:
use std::io::{Read, Seek};
type Error = String;
type ParserResult<Output> = Result<Output, Error>;
type Parser<'a, Output> = Box<dyn Fn(&mut dyn ReadSeeker) -> ParserResult<Output>>;
trait ReadSeeker: Read + Seek {}
impl<T: Read + Seek> ReadSeeker for T {}
fn between<Val, Discard>(wrap: Parser<'static, Val>, with: Parser<'static, Discard>) -> Parser<'static, Val> {
Box::from(
|input| -> ParserResult<Val> {
if let Err(err) = with(input) {
return Err(err);
}
let result = wrap(input);
if let Err(err) = result {
return Err(err);
}
if let Err(err) = with(input) {
return Err(err);
}
Ok(result.unwrap())
}
)
}
results in the error
error[E0308]: mismatched types
-->
|
61 | / Box::from(
62 | | |input| -> ParserResult<Val> {
63 | | if let Err(err) = with(input) {
64 | | return Err(err);
... |
74 | | }
75 | | )
| |_____^ one type is more general than the other
|
= note: expected type `std::ops::FnOnce<(&mut dyn ReadSeeker,)>`
found type `std::ops::FnOnce<(&mut dyn ReadSeeker,)>`
which doesn't do anything to explain to the user what's going on here, since the outputted types are identical.
Metadata
Metadata
Assignees
Labels
No labels