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

nightly-only types are confusing in error[E0277]: ? couldn't convert the error to ... #121521

Open
ericseppanen opened this issue Feb 23, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ericseppanen
Copy link
Contributor

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. 👋

@ericseppanen ericseppanen added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 23, 2024
@jieyouxu jieyouxu added D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels Feb 23, 2024
@ericseppanen
Copy link
Contributor Author

I should also note that the "terminal" representation of this error isn't that bad, but in rust-analyzer (in vscode anyway) it's a lot more confusing, because it mashes all the text together, making it harder to identify the useful part.

weiznich added a commit to weiznich/rust that referenced this issue Jul 20, 2024
This commit starts using `#[diagnostic::do_not_recommend]` in the
standard library to improve some error messages. In this case we just
hide a certain nightly only impl as suggested in rust-lang#121521
weiznich added a commit to weiznich/rust that referenced this issue Jul 22, 2024
This commit starts using `#[diagnostic::do_not_recommend]` in the
standard library to improve some error messages. In this case we just
hide a certain nightly only impl as suggested in rust-lang#121521
tgross35 added a commit to tgross35/rust that referenced this issue Jul 22, 2024
Start using `#[diagnostic::do_not_recommend]` in the standard library

This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in rust-lang#121521

The result in not perfect yet, but at least the `Yeet` suggestion is not shown anymore. I would consider that as a minor improvement.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 22, 2024
Rollup merge of rust-lang#128008 - weiznich:fix/121521, r=lcnr

Start using `#[diagnostic::do_not_recommend]` in the standard library

This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in rust-lang#121521

The result in not perfect yet, but at least the `Yeet` suggestion is not shown anymore. I would consider that as a minor improvement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants