Note inference failures using ? conversion
This commit is contained in:
parent
c97f11af7b
commit
0496fdee4f
10 changed files with 239 additions and 44 deletions
|
|
@ -13,7 +13,9 @@ error[E0282]: type annotations needed for `impl Future`
|
|||
LL | let fut = async {
|
||||
| --- consider giving `fut` the explicit type `impl Future`, with the type parameters specified
|
||||
LL | make_unit()?;
|
||||
| ^ cannot infer type
|
||||
| ^ cannot infer type of `?` error
|
||||
|
|
||||
= note: the `?` operation implicitly converts the error value into a type implementing `From<std::io::Error>`
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ error[E0282]: type annotations needed
|
|||
LL | let fut = async {
|
||||
| --- consider giving `fut` a type
|
||||
LL | make_unit()?;
|
||||
| ^ cannot infer type
|
||||
| ^ cannot infer type of `?` error
|
||||
|
|
||||
= note: the `?` operation implicitly converts the error value into a type implementing `From<std::io::Error>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
14
src/test/ui/inference/cannot-infer-closure-circular.rs
Normal file
14
src/test/ui/inference/cannot-infer-closure-circular.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
fn main() {
|
||||
// Below we call the closure with its own return as the argument, unifying
|
||||
// its inferred input and return types. We want to make sure that the generated
|
||||
// error handles this gracefully, and in particular doesn't generate an extra
|
||||
// note about the `?` operator in the closure body, which isn't relevant to
|
||||
// the inference.
|
||||
let x = |r| {
|
||||
//~^ ERROR type annotations needed
|
||||
let v = r?;
|
||||
Ok(v)
|
||||
};
|
||||
|
||||
let _ = x(x(Ok(())));
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
error[E0282]: type annotations needed for `std::result::Result<(), E>`
|
||||
--> $DIR/cannot-infer-closure-circular.rs:7:14
|
||||
|
|
||||
LL | let x = |r| {
|
||||
| ^ consider giving this closure parameter the explicit type `std::result::Result<(), E>`, with the type parameters specified
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
|
|
@ -2,8 +2,9 @@ error[E0282]: type annotations needed for the closure `fn((), ()) -> std::result
|
|||
--> $DIR/cannot-infer-closure.rs:3:15
|
||||
|
|
||||
LL | Err(a)?;
|
||||
| ^ cannot infer type
|
||||
| ^ cannot infer type of `?` error
|
||||
|
|
||||
= note: the `?` operation implicitly converts the error value into a type implementing `From<()>`
|
||||
help: give this closure an explicit return type without `_` placeholders
|
||||
|
|
||||
LL | let x = |a: (), b: ()| -> std::result::Result<(), _> {
|
||||
|
|
|
|||
22
src/test/ui/inference/cannot-infer-partial-try-return.rs
Normal file
22
src/test/ui/inference/cannot-infer-partial-try-return.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
struct QualifiedError<E>(E);
|
||||
|
||||
impl<E, T> From<E> for QualifiedError<T>
|
||||
where
|
||||
E: std::error::Error,
|
||||
T: From<E>,
|
||||
{
|
||||
fn from(e: E) -> QualifiedError<T> {
|
||||
QualifiedError(e.into())
|
||||
}
|
||||
}
|
||||
|
||||
fn infallible() -> Result<(), std::convert::Infallible> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = || -> Result<_, QualifiedError<_>> {
|
||||
infallible()?; //~ERROR type annotations needed
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
15
src/test/ui/inference/cannot-infer-partial-try-return.stderr
Normal file
15
src/test/ui/inference/cannot-infer-partial-try-return.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error[E0282]: type annotations needed for the closure `fn() -> std::result::Result<(), QualifiedError<_>>`
|
||||
--> $DIR/cannot-infer-partial-try-return.rs:19:9
|
||||
|
|
||||
LL | infallible()?;
|
||||
| ^^^^^^^^^^^^^ cannot infer type of `?` error
|
||||
|
|
||||
= note: the `?` operation implicitly converts the error value into `QualifiedError<_>` using its implementation of `From<Infallible>`
|
||||
help: give this closure an explicit return type without `_` placeholders
|
||||
|
|
||||
LL | let x = || -> std::result::Result<(), QualifiedError<_>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue