You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#137245 - estebank:from-residual-note-2, r=oli-obk
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:7: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`
| |
| this has type `Result<_, E>`
|
note: `E` needs to implement `std::error::Error`
--> $DIR/bad-question-mark-on-trait-object.rs:1:1
|
LL | struct 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`.
Fixrust-lang#137238.
-----
CC rust-lang#137232, which was a smaller step related to this.
Copy file name to clipboardExpand all lines: tests/ui/async-await/try-on-option-in-async.stderr
-6
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,6 @@ LL | async {
6
6
LL | let x: Option<u32> = None;
7
7
LL | x?;
8
8
| ^ cannot use the `?` operator in an async block that returns `{integer}`
9
-
|
10
-
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `{integer}`
11
9
12
10
error[E0277]: the `?` operator can only be used in an async closure that returns `Result` or `Option` (or another type that implements `FromResidual`)
13
11
--> $DIR/try-on-option-in-async.rs:16:10
@@ -20,8 +18,6 @@ LL | | x?;
20
18
LL | | 22_u32
21
19
LL | | };
22
20
| |_____- this function should return `Result` or `Option` to accept `?`
23
-
|
24
-
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
25
21
26
22
error[E0277]: the `?` operator can only be used in an async function that returns `Result` or `Option` (or another type that implements `FromResidual`)
27
23
--> $DIR/try-on-option-in-async.rs:25:6
@@ -34,8 +30,6 @@ LL | | x?;
34
30
LL | | 22
35
31
LL | | }
36
32
| |_- this function should return `Result` or `Option` to accept `?`
37
-
|
38
-
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
0 commit comments