Change:
It seems that should provide a better error message or hint when one tries to use the operator on an in a function returning a or vice-versa. Currently this is the error you get: However, it would be better to suggest the use of or , or , instead of referencing something dependent on the feature (). <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --This issue has been assigned to via . <!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
This error is emitted here: We could look at whether the is , and if so, provide a more targeted error, including a structured suggestion for .
Can I claim this issue?
claim

Discussion:
)), Some( "the question mark operation (`?`) implicitly performs a  <del> conversion on the error value using the `From` trait" </del> <ins> conversion on the error value using the `From` trait" </ins> .to_owned(), ), )

)) ); <ins> let should_convert_option_to_result = format!("{}", trait_ref.print_only_trait_path()) .starts_with("std::convert::From<std::option::NoneError"); let should_convert_result_to_option = format!("{}", trait_ref) .starts_with("<std::option::NoneError as std::convert::From<"); if is_try && is_from && should_convert_option_to_result { err.span_suggestion_verbose( span.shrink_to_lo(), "consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else`", ".ok_or_else(|| /* error value */)".to_string(), Applicability::HasPlaceholders, ); } else if is_try && is_from && should_convert_result_to_option { err.span_suggestion_verbose( span.shrink_to_lo(), "consider converting the `Result<T, _>` into an `Option<T>` using `Result::ok`", ".ok()".to_string(), Applicability::MachineApplicable, ); } </ins> let explanation = if obligation.cause.code == ObligationCauseCode::MainFunctionType { "consider using `()`, or a `Result`".to_owned()

<ins> fn main(){ } fn test_result() -> Result<(),()> { let a:Option<()> = Some(()); a?;//~ ERROR `?` couldn't convert the error Ok(()) } fn test_option() -> Option<i32>{ let a:Result<i32, i32> = Ok(5); a?;//~ ERROR `?` couldn't convert the error Some(5) } </ins>

<ins> error[E0277]: `?` couldn't convert the error to `()` --> $DIR/option-to-result.rs:5:6 | LL |     a?; |      ^ the trait `std::convert::From<std::option::NoneError>` is not implemented for `()` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait = note: required by `std::convert::From::from` help: consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else` | LL |     a.ok_or_else(|| /* error value */)?; |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: `?` couldn't convert the error to `std::option::NoneError` --> $DIR/option-to-result.rs:11:6 | LL |     a?; |      ^ the trait `std::convert::From<i32>` is not implemented for `std::option::NoneError` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait = note: required by `std::convert::From::from` help: consider converting the `Result<T, _>` into an `Option<T>` using `Result::ok` | LL |     a.ok()?; |      ^^^^^ error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. </ins>

| = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait = note: required by `std::convert::From::from` <ins> help: consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else` | LL |     x.ok_or_else(|| /* error value */)?; |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ </ins> error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`) --> $DIR/try-on-option.rs:13:5