News for hackers. Stuff that matters.
Re:Rust Survey 2021 Results by dgellow on Wednesday February 16, 2022 @04:41AM (#30357990)
Isn't "?" just a sugar for something like the following? That's how I think about it in my mind at least.

  // with "?"
  let v = x?;

  // without "?"
  let v = match x {
    Ok(o) => Ok(o),
    Err(e) => return Err(e), // exit current scope due to the return
  }.unwrap();
That feels like something that could be done with a macro.
Re:Rust Survey 2021 Results by estebank on Wednesday February 16, 2022 @05:24AM (#30358280)
It's more like

  let v = match x {
    Ok(o) => o,
    Err(e) => return Err(e.into()),
  };
> That feels like something that could be done with a macro.

Indeed. It used to be a macro called try!.

Re:Rust Survey 2021 Results by dgellow on Wednesday February 16, 2022 @07:51AM (#30359354)
Ah, thanks for the correction, that's better yes
Re:Rust Survey 2021 Results by zozbot234 on Wednesday February 16, 2022 @05:06AM (#30358153)
Yes, that's control flow magic. It was prototyped with a macro, but failure handling comes up all the time in practical programming, and it's important to make it as ergonomic as possible.
Re:Rust Survey 2021 Results by dgellow on Wednesday February 16, 2022 @08:00AM (#30359426)
I see. I think reading your initial comment I took issue with the hyperbole "crazy control-flow (monadic) magic is happening here".

But yes it is a hidden control flow, and taking in account hidden control flows is inherently more complicated (or at least has a steeper learning curve).