diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 97490194e2558..3f185dfae0241 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -735,7 +735,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .must_apply_modulo_regions() { err.multipart_suggestion( - "you can rely on the implicit conversion that `?` does to transform the error type", + "use `?` to coerce and return an appropriate `Err`, and wrap the resulting value \ + in `Ok` so the expression remains of type `Result`", vec![ (expr.span.shrink_to_lo(), "Ok(".to_string()), (expr.span.shrink_to_hi(), "?)".to_string()), diff --git a/tests/ui/type/type-check/coerce-result-return-value-2.stderr b/tests/ui/type/type-check/coerce-result-return-value-2.stderr index 64a8c779fce76..5992162341e6e 100644 --- a/tests/ui/type/type-check/coerce-result-return-value-2.stderr +++ b/tests/ui/type/type-check/coerce-result-return-value-2.stderr @@ -9,7 +9,7 @@ LL | true => x, | = note: expected enum `Result<_, B>` found enum `Result<_, A>` -help: you can rely on the implicit conversion that `?` does to transform the error type +help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result` | LL | true => Ok(x?), | +++ ++ @@ -25,7 +25,7 @@ LL | true => return x, | = note: expected enum `Result<_, B>` found enum `Result<_, A>` -help: you can rely on the implicit conversion that `?` does to transform the error type +help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result` | LL | true => return Ok(x?), | +++ ++ diff --git a/tests/ui/type/type-check/coerce-result-return-value.stderr b/tests/ui/type/type-check/coerce-result-return-value.stderr index 18993b3cef1b9..550153520782c 100644 --- a/tests/ui/type/type-check/coerce-result-return-value.stderr +++ b/tests/ui/type/type-check/coerce-result-return-value.stderr @@ -8,7 +8,7 @@ LL | x | = note: expected enum `Result<_, B>` found enum `Result<_, A>` -help: you can rely on the implicit conversion that `?` does to transform the error type +help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result` | LL | Ok(x?) | +++ ++ @@ -23,7 +23,7 @@ LL | return x; | = note: expected enum `Result<_, B>` found enum `Result<_, A>` -help: you can rely on the implicit conversion that `?` does to transform the error type +help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result` | LL | return Ok(x?); | +++ ++ @@ -39,7 +39,7 @@ LL | x | = note: expected enum `Result<_, B>` found enum `Result<_, A>` -help: you can rely on the implicit conversion that `?` does to transform the error type +help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result` | LL | Ok(x?) | +++ ++ @@ -55,7 +55,7 @@ LL | x | = note: expected enum `Result<_, B>` found enum `Result<_, A>` -help: you can rely on the implicit conversion that `?` does to transform the error type +help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result` | LL | Ok(x?) | +++ ++