Skip to content

Commit 62aff3b

Browse files
committed
tweak wording
1 parent df81147 commit 62aff3b

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
735735
.must_apply_modulo_regions()
736736
{
737737
err.multipart_suggestion(
738-
"you can rely on the implicit conversion that `?` does to transform the error type",
738+
"use `?` to coerce and return an appropriate `Err`, and wrap the resulting value \
739+
in `Ok` so the expression remains of type `Result`",
739740
vec![
740741
(expr.span.shrink_to_lo(), "Ok(".to_string()),
741742
(expr.span.shrink_to_hi(), "?)".to_string()),

tests/ui/type/type-check/coerce-result-return-value-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | true => x,
99
|
1010
= note: expected enum `Result<_, B>`
1111
found enum `Result<_, A>`
12-
help: you can rely on the implicit conversion that `?` does to transform the error type
12+
help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result`
1313
|
1414
LL | true => Ok(x?),
1515
| +++ ++
@@ -25,7 +25,7 @@ LL | true => return x,
2525
|
2626
= note: expected enum `Result<_, B>`
2727
found enum `Result<_, A>`
28-
help: you can rely on the implicit conversion that `?` does to transform the error type
28+
help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result`
2929
|
3030
LL | true => return Ok(x?),
3131
| +++ ++

tests/ui/type/type-check/coerce-result-return-value.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | x
88
|
99
= note: expected enum `Result<_, B>`
1010
found enum `Result<_, A>`
11-
help: you can rely on the implicit conversion that `?` does to transform the error type
11+
help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result`
1212
|
1313
LL | Ok(x?)
1414
| +++ ++
@@ -23,7 +23,7 @@ LL | return x;
2323
|
2424
= note: expected enum `Result<_, B>`
2525
found enum `Result<_, A>`
26-
help: you can rely on the implicit conversion that `?` does to transform the error type
26+
help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result`
2727
|
2828
LL | return Ok(x?);
2929
| +++ ++
@@ -39,7 +39,7 @@ LL | x
3939
|
4040
= note: expected enum `Result<_, B>`
4141
found enum `Result<_, A>`
42-
help: you can rely on the implicit conversion that `?` does to transform the error type
42+
help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result`
4343
|
4444
LL | Ok(x?)
4545
| +++ ++
@@ -55,7 +55,7 @@ LL | x
5555
|
5656
= note: expected enum `Result<_, B>`
5757
found enum `Result<_, A>`
58-
help: you can rely on the implicit conversion that `?` does to transform the error type
58+
help: use `?` to coerce and return an appropriate `Err`, and wrap the resulting value in `Ok` so the expression remains of type `Result`
5959
|
6060
LL | Ok(x?)
6161
| +++ ++

0 commit comments

Comments
 (0)