forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#71141 - Duddino:master, r=estebank
Provide better compiler output when using `?` on `Option` in fn returning `Result` and vice-versa Fixes rust-lang#71089
- Loading branch information
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters