Skip to content

surprising error observing a fallible using closure - #283

Open
mightyiam wants to merge 1 commit into
rxRust:masterfrom
molybdenumsoftware:throw_err_subscribe
Open

surprising error observing a fallible using closure#283
mightyiam wants to merge 1 commit into
rxRust:masterfrom
molybdenumsoftware:throw_err_subscribe

Conversation

@mightyiam

Copy link
Copy Markdown
Contributor

Hey, we do expect this to fail because closures
can only observe Infallible observables. But the
specific type error that we get seems unrelated
to that. We couldn't even find where it is coming
from.

Help?

@shivaraj-bh

Hey, we do expect this to fail because closures
can only observe `Infallible` observables. But the
specific type error that we get seems unrelated
to that. We couldn't even find where it is coming
from.

Help?
@mightyiam
mightyiam force-pushed the throw_err_subscribe branch from 2ec701e to 1e312e5 Compare August 22, 2026 08:50
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 1.76%. Comparing base (0e66079) to head (1e312e5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #283       +/-   ##
==========================================
- Coverage   82.47%   1.76%   -80.72%     
==========================================
  Files          84      83        -1     
  Lines       11887   11471      -416     
==========================================
- Hits         9804     202     -9602     
- Misses       2083   11269     +9186     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@M-Adoo

M-Adoo commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Sorry for the very late reply, and thanks for reporting this.

The failure itself is expected, but the RcDerefMut part of the diagnostic was indeed unrelated to anything the caller should implement.

subscribe(|...| ...) wraps the callback in FnMutObserver, which implements Observer<_, Infallible>. throw_err("some err"), however, requires an Observer<(), &str>.

While proving that bound, rustc picked our generic forwarding implementation for RcDerefMut<Target = Option<O>> as a diagnostic candidate. That is where the surprising RcDerefMut requirement came from.

#285 fixes this without removing or narrowing the forwarding implementation:

  • The forwarding implementation is excluded from trait recommendations.
  • on_error now correctly exposes Err = Infallible, since it consumes the terminal error instead of forwarding it.
  • The subscribe documentation clarifies that next-only subscriptions are for infallible observables.

The updated diagnostic now points directly to the real mismatch:

error[E0277]: the trait bound `FnMutObserver<_>: Observer<(), &str>` is not satisfied
...
help: the trait `Observer<(), &str>` is not implemented for `FnMutObserver<_>`
      but trait `Observer<(), Infallible>` is implemented for it
...
  = help: for that trait implementation, expected `Infallible`, found `&str`

For a fallible source, the intended next-only usage is:

Shared::throw_err("some err")
  .on_error(|err| eprintln!("{err}"))
  .subscribe(|_| unreachable!());

This now reports the actual &str versus Infallible mismatch and no longer mentions RcDerefMut.

@mightyiam

Copy link
Copy Markdown
Contributor Author

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants