-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak E0277 when predicate comes indirectly from
?
When a `?` operation requires an `Into` conversion with additional bounds (like having a concrete error but wanting to convert to a trait object), we handle it speficically and provide the same kind of information we give other `?` related errors. ``` error[E0277]: `?` couldn't convert the error: `E: std::error::Error` is not satisfied --> $DIR/bad-question-mark-on-trait-object.rs:5:13 | LL | fn foo() -> Result<(), Box<dyn std::error::Error>> { | -------------------------------------- required `E: std::error::Error` because of this LL | Ok(bar()?) | ^ the trait `std::error::Error` is not implemented for `E` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait = note: required for `Box<dyn std::error::Error>` to implement `From<E>` ``` Avoid talking about `FromResidual` when other more relevant information is being given, particularly from `rust_on_unimplemented`.
- Loading branch information
Showing
11 changed files
with
103 additions
and
65 deletions.
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
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
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,26 @@ | ||
struct E; | ||
struct X; | ||
|
||
fn foo() -> Result<(), Box<dyn std::error::Error>> { //~ NOTE required `E: std::error::Error` because of this | ||
Ok(bar()?) | ||
//~^ ERROR `?` couldn't convert the error: `E: std::error::Error` is not satisfied | ||
//~| NOTE the trait `std::error::Error` is not implemented for `E` | ||
//~| NOTE the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait | ||
//~| NOTE required for `Box<dyn std::error::Error>` to implement `From<E>` | ||
//~| NOTE in this expansion | ||
//~| NOTE in this expansion | ||
//~| NOTE in this expansion | ||
} | ||
fn bat() -> Result<(), X> { //~ NOTE expected `X` because of this | ||
Ok(bar()?) | ||
//~^ ERROR `?` couldn't convert the error to `X` | ||
//~| NOTE the trait `From<E>` is not implemented for `X` | ||
//~| NOTE this can't be annotated with `?` because it has type `Result<_, E>` | ||
//~| NOTE the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait | ||
//~| NOTE in this expansion | ||
//~| NOTE in this expansion | ||
} | ||
fn bar() -> Result<(), E> { | ||
Err(E) | ||
} | ||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
tests/ui/try-trait/bad-question-mark-on-trait-object.stderr
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,26 @@ | ||
error[E0277]: `?` couldn't convert the error: `E: std::error::Error` is not satisfied | ||
--> $DIR/bad-question-mark-on-trait-object.rs:5:13 | ||
| | ||
LL | fn foo() -> Result<(), Box<dyn std::error::Error>> { | ||
| -------------------------------------- required `E: std::error::Error` because of this | ||
LL | Ok(bar()?) | ||
| ^ the trait `std::error::Error` is not implemented for `E` | ||
| | ||
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait | ||
= note: required for `Box<dyn std::error::Error>` to implement `From<E>` | ||
|
||
error[E0277]: `?` couldn't convert the error to `X` | ||
--> $DIR/bad-question-mark-on-trait-object.rs:15:13 | ||
| | ||
LL | fn bat() -> Result<(), X> { | ||
| ------------- expected `X` because of this | ||
LL | Ok(bar()?) | ||
| -----^ the trait `From<E>` is not implemented for `X` | ||
| | | ||
| this can't be annotated with `?` because it has type `Result<_, E>` | ||
| | ||
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait | ||
|
||
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
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
Oops, something went wrong.