Skip to content

Indecipherable error #78385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sowelipililimute opened this issue Oct 26, 2020 · 1 comment
Closed

Indecipherable error #78385

sowelipililimute opened this issue Oct 26, 2020 · 1 comment

Comments

@sowelipililimute
Copy link

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.

(Playground)

@jonas-schievink
Copy link
Contributor

Duplicate of #77365

@jonas-schievink jonas-schievink marked this as a duplicate of #77365 Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants