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

Detect when ? is being called on a type *after* .unwrap or .expect was called on a Result or Option #127345

Open
estebank opened this issue Jul 4, 2024 · 0 comments · May be fixed by #127485
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Jul 4, 2024

The following code

fn foo() -> Option<usize> {
    let x = Some(42).unwrap()?;
    x
}

currently emits

error[E0277]: the `?` operator can only be applied to values that implement `Try`
 --> src/lib.rs:2:13
  |
2 |     let x = Some(42).unwrap()?;
  |             ^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `{integer}`
  |
  = help: the trait `Try` is not implemented for `{integer}`

but it should suggest removing the .unwrap().

Inspired by https://x.com/jonasfovea/status/1808961128812183774

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Jul 4, 2024
@chenyukang chenyukang assigned chenyukang and unassigned chenyukang Jul 5, 2024
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants