Skip to content

Indecipherable error #78385

Closed
Closed
@sowelipililimute

Description

@sowelipililimute

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions