2
hinst
2y

â›” Rust error: expected Config, found ().
💡 Actual error: process is undeclared.

The actual error has no relation to the error reported by the Rust code checker. So bad

Comments
  • 6
    unwrap_or_else of Result<T, E> takes a closure of FnOnce(E) -> T, i.e. you must return a T, which in this case is Config.

    Your closure ends with process::exit(); (semicolon!) which means the closure evaluates to the unit type (), which is wrong

    The compiler can't even get to the phase of checking whether process is in scope because your types are messed up

    As a quick fix try removing the semicolon after process::exit(). Since it returns !, the never type (aka. the function cannot return), it should(?) then type check
  • 2
    Blame yourself before you blame the compiler 🙃
  • 0
    Could it be that the undeclared process caused rust to not understand?

    But yrs it should have noticed the inner error also in that case, unless it has with the order of parsing to do.

    It could be that it could not figure out if process actually was an error due to thinking there was a mismatch in the outer code.

    But I have not worked with rust, I only know it has generally better errors than most.

    Especially compared to c or c++ ;)

    At least back when I used C.
  • 1
    Also it seems to work... so yeah
  • 0
    @12bitfloat sir in my case the error is eliminated entirely if I uncomment `use std::process;` so the error is very specific and unrelated to Config
  • 1
    @hinst Yes but that's not specific to Config nor your situation. This code (https://play.rust-lang.org//... ) is effectively identical to yours and it prints both errors

    I don't know if your rust-analyzer install is busted but it sure as heck isn't a problem with Rust
  • 0
    Is that GoLang ?
Add Comment