Skip to content
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

Unexpected lifetime: one type is more general than the other. #8

Closed
cheako opened this issue Nov 12, 2021 · 3 comments
Closed

Unexpected lifetime: one type is more general than the other. #8

cheako opened this issue Nov 12, 2021 · 3 comments

Comments

@cheako
Copy link

cheako commented Nov 12, 2021

I was trying to have parse() return slices from the parser like you normally would. Some clarity in the docs as to if references with lifetimes are possible above the call to parse(). I switched to returning owned values, so I'm confused as to where this lifetime is coming from.

https://gitlab.torproject.org/cheako/arti/-/blob/1b1c61b48a8f30e6911a954fa358b657462b6e14/crates/tor-socksproto/src/handshake.rs#L35-68

error[E0308]: mismatched types
  --> crates/tor-socksproto/src/handshake.rs:38:11
   |
38 |         i.parse(alt((FirstAction::s4, FirstAction::s5)))
   |           ^^^^^ one type is more general than the other
   |
  ::: /home/cheako/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.0/src/branch/mod.rs:73:6
   |
73 | ) -> impl FnMut(I) -> IResult<I, O, E> {
   |      ---------------------------------
   |      |
   |      the expected opaque type
   |      the found opaque type
   |
   = note: expected associated type `<impl FnMut<(&[u8],)> as FnOnce<(&[u8],)>>::Output`
              found associated type `<impl FnMut<(&[u8],)> as FnOnce<(&'a [u8],)>>::Output`

error[E0308]: mismatched types
  --> crates/tor-socksproto/src/handshake.rs:90:23
   |
90 |                     i.parse(SecondAction::s5_uname)
   |                       ^^^^^ one type is more general than the other
   |
   = note: expected associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], SecondAction), nom::Err<nom::error::Error<&'r [u8]>>> {SecondAction::s5_uname} as FnOnce<(&[u8],)>>::Output`
              found associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], SecondAction), nom::Err<nom::error::Error<&'r [u8]>>> {SecondAction::s5_uname} as FnOnce<(&'a [u8],)>>::Output`

error[E0308]: mismatched types
   --> crates/tor-socksproto/src/handshake.rs:137:18
    |
137 |                 .parse(ThirdAction::s4)
    |                  ^^^^^ one type is more general than the other
    |
    = note: expected associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], SocksRequest), nom::Err<nom::error::Error<&'r [u8]>>> {ThirdAction::s4} as FnOnce<(&[u8],)>>::Output`
               found associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], SocksRequest), nom::Err<nom::error::Error<&'r [u8]>>> {ThirdAction::s4} as FnOnce<(&'a [u8],)>>::Output`

error[E0308]: mismatched types
   --> crates/tor-socksproto/src/handshake.rs:142:22
    |
142 |                     .parse(ThirdAction::s5)
    |                      ^^^^^ one type is more general than the other
    |
    = note: expected associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], (impls::SocksCmd, SocksAddr, u16)), nom::Err<nom::error::Error<&'r [u8]>>> {ThirdAction::s5} as FnOnce<(&[u8],)>>::Output`
               found associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], (impls::SocksCmd, SocksAddr, u16)), nom::Err<nom::error::Error<&'r [u8]>>> {ThirdAction::s5} as FnOnce<(&'a [u8],)>>::Output`

error[E0308]: mismatched types
   --> crates/tor-socksproto/src/handshake.rs:156:22
    |
156 |                     .parse(ThirdAction::s5)
    |                      ^^^^^ one type is more general than the other
    |
    = note: expected associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], (impls::SocksCmd, SocksAddr, u16)), nom::Err<nom::error::Error<&'r [u8]>>> {ThirdAction::s5} as FnOnce<(&[u8],)>>::Output`
               found associated type `<for<'r> fn(&'r [u8]) -> std::result::Result<(&'r [u8], (impls::SocksCmd, SocksAddr, u16)), nom::Err<nom::error::Error<&'r [u8]>>> {ThirdAction::s5} as FnOnce<(&'a [u8],)>>::Output`

For more information about this error, try `rustc --explain E0308`.
@cheako
Copy link
Author

cheako commented Nov 15, 2021

Here is a more minimal example: Edit: https://paste.debian.net/1219657/ I forgot to include the error.

@cheako
Copy link
Author

cheako commented Nov 16, 2021

Does Err need to be an owned value? It does make a differance.

@cheako
Copy link
Author

cheako commented Nov 16, 2021

Duplicate of #3

@cheako cheako closed this as completed Nov 16, 2021
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

1 participant