-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest removing .unwrap()
or .expect()
if followed by a failed ?
operator
#127485
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
☔ The latest upstream changes (presumably #127493) made this pull request unmergeable. Please resolve the merge conflicts. |
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
Show resolved
Hide resolved
@rustbot ready |
fn baz3() -> Option<usize> { | ||
Ok(44).unwrap()? | ||
//~^ ERROR the `?` operator can only be applied to values that implement `Try` | ||
//~| HELP the trait `Try` is not implemented for `{integer}` | ||
//~| HELP remove the `.unwrap()` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In baz3
the suggestion shouldn't fire because removing the .unwrap
does not help. You probably want to check that the return type of the function is compatible with the non-unwrap
ped reciever
fn baz4() { | ||
Ok(44).unwrap()? | ||
//~^ ERROR the `?` operator can only be applied to values that implement `Try` | ||
//~| HELP the trait `Try` is not implemented for `{integer}` | ||
//~| HELP remove the `.unwrap()` | ||
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) | ||
//~| HELP the trait `FromResidual<_>` is not implemented for `()` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. It is more likely that the ?
was inserted on error and not .unwrap()
☔ The latest upstream changes (presumably #128041) made this pull request unmergeable. Please resolve the merge conflicts. |
@trevyn |
Closes #127345