Open
Description
Code
struct BarError;
fn bar() -> Result<(), BarError> {
Ok(())
}
struct FooError;
fn foo() -> Result<(), FooError> {
bar()?;
Ok(())
}
fn main() {
foo();
}
Current output
error[E0277]: `?` couldn't convert the error to `FooError`
--> src/main.rs:11:10
|
10 | fn foo() -> Result<(), FooError> {
| -------------------- expected `FooError` because of this
11 | bar()?;
| -----^ the trait `From<BarError>` is not implemented for `FooError`
| |
| this can't be annotated with `?` because it has type `Result<_, BarError>`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following other types implement trait `FromResidual<R>`:
<Result<T, F> as FromResidual<Yeet<E>>>
<Result<T, F> as FromResidual<Result<Infallible, E>>>
= note: required for `Result<(), FooError>` to implement `FromResidual<Result<Infallible, BarError>>`
Desired output
I'm not sure.
Rationale and extra context
This is a very common error, and it's likely to be encountered by people new to Rust.
The note
and help
text mentions two different types that are nightly-only (Yeet
, FromResidual
). To someone who is learning the language or only using the stable compiler, this is both confusing and unhelpful.
I think the stable compiler should avoid mentioning internal or nightly-only types, and when possible, the advice given should be understandable and actionable by someone new to the language.
If the last two messages are only going to talk about nightly only types, and they're not actually helpful to someone using the stable compiler, maybe they should just be removed?
Other cases
No response
Rust Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Anything else?
I filed this bug after a conversation with @estebank on mastodon. 👋
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.